![]() | ![]() |
|||||||||||||||||||||||||||||||
|
A S T A P R O V I D E R S Chris Weston
March, 2001 Copyright 2001 by ASTA Technology Group. All rights reserved.
Asta Servers have been designed to support Asta Client applications with no changes. Everything that you can do with a normal 2-tier fat client database application, ASTA Servers can provide to ASTA client applications. There is much to be said in developing and deploying a generic ASTA server that can serve diverse client applications. Writing client side SQL select statements, calling stored procedures from ASTA clients, and using ASTA to generate SQL on update, insert, allow ASTA developers to quickly and easily deploy thin client 3 tier applications. However there may be times when you want to customize an ASTA server or to NOT use SQL in an ASTA client. There are a number of reasons that you would want to code the server rather than the client.
ASTA provides tools to allow you to easily create and maintain ASTA servers that will allow you to deploy ASTA client applications that require NO SQL. It is of course acceptable to use a mix of client side SQL and server side programming techniques. The following are the ASTA Server concepts that enable this to occur.
For this tutorial we will code a TAstaProvider on an ASTA Server then create a client that uses no sql to access the Customer.db table supplied with Delphi or C++ Builder. AstaProviders TAstaProviders provide a way for Asta developers to write SQL on the server rather than on from TAstaClientDataSets. An AstaProvider has a DataSet:TDataSet property where you use a server side TDataSet Descendent that will contain a result set that will be streamed back to remote clients. The Field properties like DisplayLabel and Display Width can optionally be streamed back to AstaClientDataSets so that the right mouse persistent Fields editor is used on the server rather than on the client. Building the Server Setting up an AstaProvider on the ASTAServer is really quite simple. In the server source project you will find a datamodule called AstaDataModule. This AstaServer is the standard AstaBDEServer with the addition of two components. A TQuery named Customer and a TAstaProvider named CustomerAstaProvider have been placed onto the datamodule. Properties for each component have been set as follows:
The TQuery is our physical connectivity to the database table. For this tutorial we have selected all of the records from the Customer table. If the Dataset used on the provider has an SQL property and uses a parameterized Query, those parameters will be streamed to ASTAClientDataSets. The TAstaProvider will be our middle man between the AstaClientDataSet on our client and the TQuery. The Dataset property is set to Customer. AstaClientDataSets that don’t use SQL for their selects, are only updateable if they use a provider. To make our AstaClientDataSet updateable the PrimeFields and UpdateTableName properties have been assigned as shown above. You can optionally code any of the Before/After events of the provider that present you the Original row of from the ClientDataSet and current row of the ClientDataSet or, optionally, the current values on the server. This allows you to change row values to add defaults or otherwise modify values coming from the client. You can optionally have ASTA generate NO SQL for any row. All ASTA server side components are inventoried when the AstaServerSocket When the ASTA Server starts up the AstaProvider is registered by the call RegisterDataModule. Next we compile and run the server and move on to building our client.
The client application contains a TAstaClientSocket, TAstaClientDataSet, TDataSource, TDBGrid and a TButton. Properties for each component have been set as follows:
The following code has been placed in the OnClick event of the TButton: procedure TForm1.Button1Click(Sender: TObject); We have set the AstaclientDataSet.GenerateSQLLocation to gsServer. This puts the AstaclientDataSet in Cached Edit Mode. The EditMode property is ONLY used for Client Side SQL (gsClient). We can now append, update, delete the AstaClientDataSet using normal VCL commands and when you want to post the changes to the server call ApplyUpdates(usmServerTransaction) which has been placed in the OnClick event of the TButton. Instead of generating SQL on the client, the internal OldValuesDataSet is sent to the server along with a data set of all current rows that are involved in update or appends. A Transaction is started on the server and all the provider events are fired as each row of the AstaClientDataSet now on the server is presented to the AstaProvider. If all the SQL generated is successful then a Commit is issued to the Database, otherwise the changes are rolled back. You may now compile and run your client. Remember, updates will not be applied until the ApplyUpdates procedure is called by clicking on the Update button.
|
||||||||||||||||||||||||||||||||
|
ASTA
in 60 Seconds | Products & Training |
Developer Details | Free
Internet Tools Copyright
© 2000, ASTA Technology
Group. | ||||||||||||||||||||||||||||||||