Connecting Data Access Components


IBO's native Data Access components connect together in much the same way as the standard Data Access components do. The traditional model has a database, dataset and a datasource. This remains true with IBO. However, with a SQL database such as InterBase there is also the additional factor of transactions to integrate.

So far this whole transaction level has been hidden within the TDatabase component by the BDE. It uses a connection and a transaction wrapped together in a single interface. But, InterBase is not limited to having a single transaction per connection.

Because InterBase is able to have multiple simultaneous transactions per connection, IBO has been designed to implement transactions in a separate component. This way, it is possible to have one connection component and multiple transaction components that all reference it at the same time.

Another significant feature of InterBase is that it supports a single transaction spanning multiple databases. So, it also becomes necessary to design IBO to handle the case where a transaction references multiple connections concurrently. IBO makes it very easy to take advantage of this very advanced and powerful feature of InterBase. Use the IB_Connection1 and IB_Connection2 properties of the TIB_Transaction component to specify additional connections to include in the multi-database transaction. If more than three are needed use the AddConnection() method to add any others.

So, a dataset doesn't just reference a database with IBO. It must also reference a transaction as well. This is what determines the context data on the server is read and written in. A statement and dataset in IBO has both a database and a transaction reference property. They are IB_Connection
and IB_Transaction.

In order to make things more flexible the following behaviors have been implemented in the statements and datasets:

Default Connection
If a connection reference is not provided on a statement or a dataset then it will check with the default session and see if there is a default connection present. If so then it will automatically align to that connection. This is typically the first connection component created in the application. If there is only a single connection for the whole application is is generally unnecessary to pay any attention to the connection reference since IBO will automatically align things up for you.

Default Transaction
If a transaction reference is not provided on a statement or a dataset then an internal transaction is generated automatically. It is given an isolation that allows it to see the committed state of the database at all times and will auto-commit any changes that are posted. In this way, if you design an application without using the transaction layer it will still function just fine. Datasets behave as if there wasn't the concept of transactions in this mode.

Normal Mode
A statement or query normally assigns it's IB_Connection
and IB_Transaction properties to the proper corresponding component. For the IB_Connection property this can connect to a TIB_Connection, TIB_Database, TIBODatabase component or any subclasses of these. The IB_Transaction property connects to the TIB_Transaction component or any of its sub-classes.

The TIB_TransactionSingle, TIB_TransactionDouble and TIB_TransactionMultiple components are obsolete and just included for backwards compatibility.

BDE Emulation
The TIBODatabase component has be designed to do what the BDE driven TDatabase component does. It combines the connection with an internal transaction and makes all statements and datasets which attach to it share the same transaction. So, when you use this component don't bother trying to set the IB_Transaction reference of a dataset because it will remain fixed to the central transaction internal to the TIBODatabase component. It will show the property setting of <database> in the object inspector to indicate that it is set for you automatically.

A significant amount of control is surrendered when the TIBODatabase component is used. It is ideally used in the process of converting an existing BDE application to IBO. Once converted to IBO this component may eventually be replaced with a TIB_Connection component when transactions are being fully and properly implemented in the application.

Note:
The TIB_Database and TIBODatabase components work very nicely when cached updates are your principal mode of operation. Use the latter if you are using the TDataset based components.