From 6b8e77900d0446b04d36ce8ff9875226677b36c1 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 22 Feb 2009 19:43:55 +0000 Subject: [PATCH] started on transactions git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@276 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- doc/prog_woc.html | 122 ++++++++++++++++++++++++++++++++++++++++++++- src/wbase/WTransaction.h | 3 + woc/qtout.cpp | 83 ++++++++++++++++++++++++++++++- woc/qtout.h | 6 ++ woc/woc.pro | 7 +++ 5 files changed, 216 insertions(+), 5 deletions(-) diff --git a/doc/prog_woc.html b/doc/prog_woc.html index 4400156..336a220 100644 --- a/doc/prog_woc.html +++ b/doc/prog_woc.html @@ -141,11 +141,127 @@ The Value tags for enum types function similar to enums in C++. If a value attri

Communication Abstraction Layer

-The Communication Abstraction Layer is the servers upper bound towards the client. It hides the complexities of serializing data onto the network transport protocol by providing communication classes that do this automatically. The configuration of this layer is split into two major components: communication classes and transactions. While the communication classes describe what data can be transported over the connection, the transactions describe what operations can be performed. +The Communication Abstraction Layer is the servers upper bound towards the client. It hides the complexities of serializing data onto the network transport protocol by providing communication classes that do this automatically. The configuration of this layer is split into two major components: communication classes and transactions. While the communication classes describe what data can be transported over the connection, the transactions describe what operations can be performed.

-

Business Logic: Mapping - the Trivial Case

+

Communication Classes

+ +An example class can be seen here: + +
+<Class name="Ticket">
+  <Enum name="TicketState" refColumn="ticket:status"/>
+  <Property name="ticketid" type="astring" id="yes"/>
+  <Property name="eventid" type="int"/>
+  <Property name="price" type="int"/>
+  <Property name="status" type="TicketState"/>
+  <Property name="orderid" type="int"/>
+  
+  <ToXml name="inOrder">ticketid eventid price status</ToXml>
+  <ToXml name="Full">ticketid eventid price status orderid</ToXml>
+  
+  <Mapping table="ticket">
+    <Map column="ticketid"/>
+    <Map column="price"/>
+    <Map column="eventid"/>
+    <Map column="status"/>
+    <Map column="orderid" property="orderid"/>
+  </Mapping>
+</Class>
+
+ +The "name" attribute of the Class tag gives the communication class a name by which it can be referenced. The language converters will prefix it with "WO" to make it unique and postfix it with "Abstract" if the class is declared abstract - in this case the user must derive the non-abstract class to make it usable.

+ +Class attributes: + + + + +
AttributeDescription
namethe name of the class
abstract(optional) marks the class abstract

+ +The Enum tag defines a local enumeration. In most cases they will simply reference an enumeration that has already been defined in a database table with a refColumn attribute (syntax: table:column), but it may also locally define its values by using the same Value tags used for database enums.

+ +The Property tag defines a property of the class that can be read and written to: + + + + + + +
AttributeDescription
namethe name of the property
abstract(optional) marks the property abstract - this automatically makes the class abstract and the user has to overwrite the getter and setter methods
id(optional, default=no) marks the property to identify the instance in a cache
type(mandatory) defines the type of the property, see below

+ +Property types: + + + + + +the name of an enum defined in the same class is possible, local storage is as integer, transport is as string equalling the symbolic name of the value in an attribute + + +
TypeDescription
intan integer - it is at least a 32bit signed type; it is transported as attribute
astringa string that can be safely stored in a XML attribute
stringa string that is transported as element and can reach any length
EnumName
ClassNamethe name of a defined class makes the property an instance of that class; they are transported as sub-elements of this class
List:*prefixing the type with "List:" makes the property a list of that type - any of the above types can be made into lists; on transport list values are always serialized as elements

+ +The Mapping tag can be used to provide a shortcut cast between a database table type and the communication class type. This is provided for the trivial case in which no transformations between the database query result and the transport data is necessary. If the property attribute is ommitted a property with the same name as the listed column is looked for.

+ +The ToXml tag provides valid serializations. Each serialization must have a name - the language converters prefix them with "toString" and "toXml" to build a method names. The text of the tag simply lists all properties that should be contained in the serialization separated by spaces. Properties that are communication classes (or lists thereof) must also list the proper serialization function of that communication class, eg. Order serialized thus: + +

+<ToXml name="Full">orderid customerid seller amountpaid state amountdue tickets/inOrder vouchers/inOrder</ToXml>
+
+ +Above the property "tickets" is a list of Ticket and "inOrder" is a serialization defined above for Ticket. + + +

Transactions

+ +
+<Transaction name="GetTicket">
+  <Input>
+    <Var name="ticketid" type="astring"/>
+    <Call lang="php" method="getTicketFunction"/>
+  </Input>
+  <Output>
+    <Var name="ticket" type="Ticket/Full"/>
+  </Output>
+</Transaction>
+
+ +Each transaction must have a name that identifies it. This name is used in the wire protocol to correctly identify the currently requested transaction. + +Transaction attributes: + + + + +
AttributeDescription
namethe name of the transaction
mode(optional, default=checked) can be used to require less restrictive privileges, see below for values

+ +Transaction modes: + + + + + +
ModeDescription
checkedthe default mode: the session must be authenticated and the user must have the privilege to execute this query
auththe session must be authenticated, but no special privilege is required; this can for example be used for the logout function or a function query information about the session itself
openno session is necessary for this to work; usually this is only done for login

+ +Input defines the input parameters (Var tag) of the transaction (ie. what is sent to the server) and what function is called (Call tag) once the transaction has been checked and authenticated.

+ +Output defines the data (Var tag) sent back to the client.

+ +Var attributes: + + + + +
AttributeDescription
namethe name of the variable
typetype of the attribute; all types allowed for class properties (except enums) are allowed here

+ +Call attributes: + + + + +
AttributeDescription
langthe language binding this refers to (currently only "php")
methodthe function to call - it must take exactly one argument: the transaction object

+ +Transactions are represented as classes. On the client side they are used to execute the query and to represent the result. On the server side they internally verify the input and authenticate the transaction and are then used to take and encode the output or possible error conditions. -In some cases the Business Logic is a trivial case of translating a database object into a communication object. For these cases a simple mapping can be formulated....

Server Abstraction Layer

diff --git a/src/wbase/WTransaction.h b/src/wbase/WTransaction.h index 2f0b656..15e5a39 100644 --- a/src/wbase/WTransaction.h +++ b/src/wbase/WTransaction.h @@ -20,6 +20,9 @@ class WTransaction:public QObject { + protected: + WTransaction(){} + WTransaction(const WTransaction&){} }; #endif diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 914f350..86401b2 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -390,21 +390,100 @@ void WocQtClientOut::newTransaction(const WocTransaction&trn) emit errorFound(); return; } + //basics + QStringList in=trn.inputNames(); + QStringList out=trn.outputNames(); //lead in hdr.write(QByteArray(HDRSTART).replace("%",cn.toAscii())); src.write(QByteArray(SRCSTART).replace("%",cn.toAscii())); QString hcd; QString scd; - hcd="#include \"WTransaction.h\"\n\n"; - hcd+="class "+cn+":public WTransaction\n{\n public:\n"; + hcd="#include \"WTransaction.h\"\n"; + for(int i=0;i\n"; + } + for(int i=0;i\n"; + } + hcd+="\nclass "+cn+":public WTransaction\n{\n"; hdr.write(hcd.toAscii()); + //create properties + QString inlist,clist; + hcd=" private:\n"; + for(int i=0;i