Migrating Data with TInstantPump
TInstantPump is a component that helps migrate data between InstantObjects databases. It can help in these circumstances:
- You have a database in a broker and want to move the data to a database of another broker (for example to Firebird or to SQL Server). InstantObjects eases the creation of the new database schema, while
TInstantPumpmoves the data. In the general case you can migrate data using any combination of two connectors, provided the destination broker supports all the features you have used in the source database. For example, some brokers do not support external Parts and References, others do. - You have decided to convert the Parts and References blobs from binary to XML format (see XML Blob Streaming). Create a new empty database, set the source connector to use binary blobs and the destination connector to use XML blobs, then run the pump.
- You need to change the data type or the size of the Id fields (see Id Data Type and Size).
TInstantPump currently cannot migrate data between different models (for example from the classic blob-based storage of the collections to external storage).
The demo Demos\Pump shows how to use the component.
Using TInstantPump
You hook the pump to a source connector (used to retrieve the objects from the source database) and to a destination connector (used to write the objects to the destination database).
Properties
| Property | Description |
|---|---|
SourceConnector: TInstantConnector | The source database. Set the properties of the connector (UseTransactions, BlobStreamFormat, IdDataType, IdSize...) to match those of the database. |
DestConnector: TInstantConnector | The destination database. Set the properties of the connector the same way. |
Options: set of TInstantPumpOption | Tweaks the pump process. poEmptyDestBeforePump empties each destination table before writing the objects to it. The default is [poEmptyDestBeforePump]. |
Methods
procedure Pump(Model: TInstantModel = nil);Starts pumping. Passing an external model is not supported: pass nil, which means the component uses the global InstantModel. All the model units must therefore be part of the project: the pump works inside an InstantObjects project.
Events
| Event | Description |
|---|---|
BeforePump: TInstantSchemeEvent | Called before the pump, with the TInstantScheme built by the source connector: you can look at it (and possibly modify it; not tested). |
AfterPump: TInstantSchemeEvent | The same, called after the pump process has finished. |
Example
var
Pump: TInstantPump;
begin
Pump := TInstantPump.Create(nil);
try
Pump.SourceConnector := SQLConnector;
Pump.DestConnector := XMLConnector;
Pump.Options := [poEmptyDestBeforePump];
Pump.Pump;
finally
Pump.Free;
end;
end;Pumping without the model units (not tested)
In principle the pump can be used without compiling the model units into the application. These are the steps:
- create a package that holds the model units;
- create a pump application with no model, compiled with run-time packages;
- have the application load the model package dynamically with
H := LoadPackage('MyModel.bpl'), and callUnloadPackage(H)when finished; - before calling
Pump, load the model from an XML file or from an.mdrresource file:InstantModel.LoadFromFile('MyModel.xml')orInstantModel.LoadFromResFile('MyModel.mdr'); - call
Pump.
Originally written by Nando Dessena, 2005.
