RAD Studio supports multi-table resolution with BDP.NET. Specifically, the DataSync and DataHub components are designed to provide and resolve a .NET DataSet from multiple heterogeneous data sources. In addition, these components support the display of live data at designtime, and provide and resolve master-detail data by generating optimal SQL for resolving to BDP data sources.
The DataHub acts as a conduit between a DataSet and a DataSync. The DataPort property for a DataHub can be set to any IDataProvider implementation. DataSync implements IDataProvider and has a Providers collection that can contain any .NET data provider that implements IDbDataAdapter. The GetData method for DataSync iterates through all the DataProviders in the collection and returns a DataSet. SaveData resolves DataSet changes back to the database through the DataProvider collection. While resolving changes through a BdpDataAdapter the resolver generates optimal SQL. For non-BDP data providers, their respective CommandBuilder is used.
Building a database application that resolves multiple tables consists of the following steps:
- Create a simple database project from the Data Explorer with multiple BdpDataAdapter objects to connect to multiple providers
- Add and configure a DataSync component to connect the providers
- Add and configure a DataHub component to connect the DataSync to a DataSet
To create a database project from the Data Explorer
- Choose FileNewWindows Forms Application for either Delphi for .NET. The Windows Forms designer appears.
- Choose ViewData Explorer to access the Data Explorer.
- Expand the Data Explorer Tree to expose the providers and database tables you want to use. You must have a live connection to exprovider nodes. If you do not have a live connection, you may need to modify the connection string.
- Drag and drop tables from one or more providers onto your form. For each table you drag onto your form, a BdpConnection and a BdpDataAdapter appear in the component tray. If you add multiple tables from the same provider, you can delete all but one BdpConnection for that provider.
- Configure each BdpDataAdapter component. There is no need to set the Active or DataSet properties, as the DataSet will be populated by the DataHub component.
- Add a DataSet component to your form from the Data Components category of the Tool Palette.
- Add and configure a DataGrid component to your form from the Data Controls category of the Tool Palette. Set the DataSource property for the DataGrid to the name of the added DataSet component (for example, dataSet1).
To add and configure a DataSync component
- Drag a DataSync component onto your form from the Borland Data Provider category of the Tool Palette.
- In the Component Tray, select the DataSync component.
- In the Object Inspector, select the Providers property, and click the ellipsis button to open the DataProvider Collection Editor.
- In the the DataProvider Collection Editor, add a DataProvider for each table you want to provide and resolve. You should have a DataProvider for each BdpDataAdapter in your project.
- For each DataProvider, select the DataProvider in the Members pane, and set the DataAdapter property to the appropriate BdpDataAdapter.
- When you have finished configuring your DataProviders, click OK to close the DataProvider Collection Editor.
- In the Object Inspector, set the CommitBehavior property to specify how failures are handled during resolving. There are three options for resolving logic:
- Atomic—transactions are attempted for each provider. If a transaction fails, no further transactions are attempted, and all preceding transactions are rolled back. If there are no failed transactions, all transactions are committed.
- Individual—a transaction is attempted for a provider, and if it succeeds, it is committed. The next transaction is attempted, and if it succeeds, it is committed, and so on. If a transaction fails for a provider, that transaction is rolled back, and no further transactions are attempted.
- ForceIndividual—a transaction is attempted for a provider, and if it succeeds, it is committed. The next transaction is attempted, and if it succeeds, it is committed, and so on. If a transaction fails for a provider, that transaction is rolled back, and the next transaction is attempted.
To add and configure a DataHub component
- Drag a DataHub component onto your form from the Borland Data Provider category of the Tool Palette.
- In the Component Tray, select the DataHub component.
- In the Object Inspector, set the DataPort property to the added DataSync component (for example, DataSync1).
- Set the DataSet property to the added DataSet (for example, dataSet1)
- Choose RunRun. The application compiles and displays a Windows Form with a DataGrid.