Multi Tier Server Programming with ASTA
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.
- To be able to use the same code from the server on multiple client applications
- For security to not allow clients to execute SQL
- For Performance
- To keep the client application thinner
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
- TAstaProviders
- TAstaBusinessObjectsManagers
- ServerDataSets
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.
If the DataSet used on the provider has an SQL property and uses a
parameterized Query, those parameters will be streamed to
ASTAClientDataSets. In order to support TDataSet Components that do not
use Tparams types for their parameters the AstaServerSocket has some
Provider Parameter helper events that need to be coded.
When a provider is used on an ASTA server, it is registered when the
ASTAServer starts up by the call RegisterDataModule.
Whether you use an AstaProvider or Server Method, AstaclientDataSet
that don't use SQL for their selects, are only updateable if they use a
provider. To make an AstaClientDataSet updateable.
Making an AstaClientDataSet Updateable Using a Provider
Server Side
- Set the PrimeKeyFields and UpdateTableName property of the TAstaProvider.
- 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.
ClientSide
- When you use TAstaProviders, EditMode can only be set to cached. there is no option of after Post as a transaction MUST be started when a provider is used on the server.
- Set the AstaclientDataSet.GenerateSQLLocation to gsServer. This puts the AstaclientDataSet in Cached Edit Mode. You may now append, update, delete the AstaClientDataSet using normal VCL commands and when you want to post the changes to the server call ApplyUpdates(usmServerTransaction);
- Instead of generating SQL on the client, the internal FoldValuesDataSet 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.
ServerDataSets
Any TDataSet descendent sitting on an ASTA server can be made
available to ASTA client applications. You may have as many DataModules
or Forms your ASTA server as you desire available to TAstaClientDataSet
at design time and at runtime. They can also be seen from the
TAstaClientDataSet SQLWorkbench by clicking on the ServerDataSet tab.
Since ASTA client applications are going to point directly to any of
the ServerDataSets that you make available, you can use the persistent
field properties to Set Edit Masks, Display Labels, Date or Float
formats. Additional information from the TFields of your ServerDataSet
is streamed back to the ASTA client application.
Server Datasets are read only so if you require a dataset to be
updateable use a TAstaProvider.
Business Objects
The TAstaBusinessObjectsManager allows ASTA developer to create
server side methods that can be executed by ASTA client applications.
"Methods" can be defined and named so that AstaClientDataSets and can
"point" to a specific server method and execute it when the
AstaClientDataSet is opened. You can define a method name and any types
of Parameters which consist of a ParamName, DataType and ParamType
(ptinput, ptinputoutput etc). Each method has a DataSet property if you
want to stream a result set back. Set the property UseNoDataSet to true
if you have not result set to come back to the client but only want to
trigger some action.
You can use any number or kinds of components on the server and
ServerMethods are great for doing complicated reports that require a
number of Queries to be executed or results sets to be combined. You
can even use TAstaDataSets (in memory Datasets) to define the fields
and types you want the AstaClientDataSet to receive and populate it on
the server. You can also hook a ServerMethod to a TAstaProvider and
optionally use the Provider Params rather than any Params that you have
to define. If you want a result set to be updateable you must use a
TAstaProvider.
Server side SQL Generation
AstaClientDatasets can generate their SQL for inserts,update and deletes on the client OR on the server. When the SQL is generated on the server, ASTA sends TastaDataSets that consist of the original dataset values and the current datsaet values.
|