| Database Subsetting Tool |
Home Quick Tour Tutorial Data Browser FAQ API Documentation Forum Download
API
- 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) log4J Classes net.sf.jailer.api.Subsetter generates a subset of a relational database that respects foreign key constraints. net.sf.jailer.api.Importer imports subset data. Example The example is included in the jailer-engine-version.jar. It extracts some data from the "demo-scott-1.4" database and imports it into another database "demo-scott-subset-1.4". Packages The data model "Demo-Scott" and the extraction model "Demo-Scott.jm" are both embedded into the package and thus accessible as class resources. Source
      public class APIExample {

      	// JDBC connection pool size
      	private static final int POOL_SIZE = 10;

      	// The subsetter
      	private static Subsetter subsetter =
      		new Subsetter(
      			new BasicDataSource(
      					"org.h2.Driver", "jdbc:h2:" + new File("demo-scott-1.4").getAbsolutePath(), "sa", "",
      					POOL_SIZE,
      					new File("lib/h2-1.4.199.jar")),
      			null,
      			APIExample.class.getResource("Demo-Scott"),
      			APIExample.class.getResource("Demo-Scott.jm"),
      			ScriptFormat.SQL);

      	// The importer
      	private static Importer importer =
      		new Importer(
      			new BasicDataSource(
      				"org.h2.Driver", "jdbc:h2:" + new File("demo-scott-subset-1.4").getAbsolutePath(), "sa", "",
      				10,
      				new File("lib/h2-1.4.199.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();
      	}

      }