Building ASTA Servers


 

ASTA was designed to allow any Delphi database component to be used on ASTA servers and be threaded by ASTA internally to support ASTA's 3 threading models (singlesession, persistentsession and pooled).

 

ASTA Servers need to be able to handle:

1. Selects

2. Parameterized Queries

3. MetaData Requests

4. Fetch Blob Requests

5. Transactions

6. Stored Procedures

 

To support the above 6 items, ASTA Servers need to know which components to use for which operation. To that end the ThreadedDBSupplyQuery is called.

 

ThreadedDBSupplyQuery passes in an enumerated type of TThreadDBAction which can be ttSelect, ttExec, ttStoredProc, ttTransactionStart, etc.

 

So in your case you are using TAstaProviders on the server to generate SQL on the server from remote AstaClientDataSets.

 

When you are using an AstaClientDataSet with NO SQL and you want to be able to make it editable and post changes on the server using a provider, you set the SQLGenerateLocation property of the AstaClientDataSet to gsServer. This sets EditMode to Cached and allows you to then call ApplyUpdates(usmServerTransaction) to post any inserts, updates and deletes on the server.

 

When you call ApplyUpdates, the AstaClientDataSet sends two datasets to the server. The OriginalValues (nothing for inserts) and CurrentValues(nothing for deletes).

 

The TAstaProvider then looks to (or creates if none exists) a TAstaSQLGenerator to get any SQLDialect settings (for instace MS SQL Server needs booleans to be posted as integers).

 

1. ASTA calls ThreadedDBSupplyQuery and says "What component do I need to start a transaction?" (ttTransactionStart is passed)

2. In your case your ThreadedDBSupplyQuery will return a TDatabase.

3. ASTA then calls the OnTransactionBegin event of the TAstaServerSocket and passes it the TDatabase it just got from #2, and the transaction is started.

4. We need to execute a bunch of parameterzied queries for the SQL to be generated so ASTA calls the ThreadedDBSupplyQuery with ttExec and your BDE server returns a TQuery.

5. ASTA generates SQL (and with a provider you get a chance to modfiy the values of the two datasets passed from the client or to generate your own SQL in events) for each row of the AstaClientDataset and calls the AstaServerSocket.OnExecSQLParamList using the TQuery that it has.

6. This repeats for all the rows (and refetches can be gathered up for things like auto increment fields that can be streamed back on inserts).

7. At the end of the transaction ASTA calls the OnTransactionEnd passing the TDatabase again, and either commits or rolls back the transaction according to what has happened on the executes.

 



ASTA Overview