|
Transactions in ASTA are optimized to keep network traffic to a
minimum. For this reason, ASTA clients do not start a transaction on
the client, execute some sql statements, and then end the transaction.
For that you would need many round trips to and from the server to
perform each step. You would also need an open connection to the server
and that would not fit in with the sharing of resources that allows
ASTA servers to scale.
A complete transaction is always sent to the server to be started
and ended entirely on the server side. ASTA was designed so that you
need only write SQL for select statements and any insert, update or
delete statements as well as anything necessary execute those
statements under transaction control, is handled by ASTA.
Here is a step by step walkthrough of how ASTA's Cached Edit Mode
uses transactions
- Write a Select Statement and set active to True
- Set EditMode to Cached using the EditMode property editor and set the UpdateTableName and PrimeKey Fields
- Connect to an ASTA Server which executes the Select and then allow your users to append, edit, and delete. They can even disconnect from the server and continue to append, edit and delete. The original values of the Dataset are pushed into the internal FoldValuesDataset so that you can call RevertRecord or CancelUpdates at any time to restore a row to it's pre-edited state.
- Call ApplyUpdates(usmServerTransactions)
- The AstaclientDataSet will now either generate SQL if you are using client side sql, or packup FoldValuesDataSet and a dataset consisting of rows affected by changes and transport them to the server. If you are using any blobs or memos then a TastaParamlist containing their data goes to the server also.
- A Database Session is obtained depending on which ASTA threading model.
- A thread is launched if the server is running threaded.
- A call is made to ThreadedDBSupplyQuery to obtain the component that can start a transaction
- A transaction is started
- SQL is generated on the server if using server side components and the TAstaProviders Before/After events are fired.
- Each line of SQL is passed to OnExecSQLParamList to be executed.
- If any SQL Fails or if all succeed another call is made to ThreadedDBSupplyQuery to get a Component to Commit or RollBack the transaction
- If there were problems, an exception is streamed back to the client, otherwise the client is notified of a success and the FoldValuesDataSet is emptied on the client.
- Any Fields tagged to be refetched are brought back.
Notice all the processing takes place on the server which shows how
the use of the middle tier can be leveraged for processing.
Multiple AstaClientDataSets can be sent in one transaction by
calling
procedure SendDataSetTransactions(TransactionName:String;
Const DataSets:Array of TDataSet);
If you want to send multiple SQL Statements to an ASTA server use
the TAstaClientDataSet call
Function SendSQLTransaction(TransactionName:String;List:TStrings):Boolean;
Where each item in the List has a separate SQL Statement.
|