|
Application
Programming Interface
The API provides programmatic access to
the data export and import functionality.
Dependencies
- jailer-engine-version.jar (MVN-Repository, also included in jailer-version.zip)
- If you are not using a dependency management system, add the required jar-files in the lib/ directory to the class path manually.
Classes
Example
The example is included in the sources. It extracts some data
from the "demo-scott" database and imports it into another
database "demo-scott-subset".
- Source
public class APIExample {
// JDBC connection pool size
private static final int POOL_SIZE = 10;
// Folder containing models and databases
private static final File baseFolder = new File(".");
// The subsetter
private static Subsetter subsetter =
new Subsetter(
new BasicDataSource(
"org.h2.Driver", "jdbc:h2:" + new File(baseFolder, "demo-db/demo-scott").getAbsolutePath(), "sa", "",
POOL_SIZE,
new File(baseFolder, "lib/h2-2.2.224.jar")),
null,
new File(baseFolder, "datamodel/Demo-Scott"),
new File(baseFolder, "extractionmodel/Demo-Scott.jm"),
ScriptFormat.SQL);
// The importer
private static Importer importer =
new Importer(
new BasicDataSource(
"org.h2.Driver", "jdbc:h2:" + new File(baseFolder, "demo-db/demo-scott-subset").getAbsolutePath(), "sa", "",
POOL_SIZE,
new File(baseFolder, "lib/h2-2.2.224.jar")));
/**
* Exports data related with employee "SCOTT"
* and imports it into another database.
*/
public static void main(String[] args) throws SQLException, IOException {
File exportScriptFile = Configuration.getInstance().createTempFile();
subsetter.setUpsertOnly(true); // overwrite previous data
subsetter.execute("NAME='SCOTT'", exportScriptFile);
importer.execute(exportScriptFile);
exportScriptFile.delete();
}
}
|
|