package net.sf.jailer.api_example;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import net.sf.jailer.api.Importer;
import net.sf.jailer.api.Subsetter;
import net.sf.jailer.configuration.Configuration;
import net.sf.jailer.database.BasicDataSource;
import net.sf.jailer.subsetting.ScriptFormat;
/**
* Jailer API Example.
*
* Extracts some data from the "demo-scott" database
* and imports it into another database "demo-scott-subset".
*/
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:demo-scott",
"sa",
"",
POOL_SIZE,
new File(
"lib/h2-1.3.160.jar")),
null,
APIExample.
class.getResource(
"Demo-Scott"),
APIExample.
class.getResource(
"Demo-Scott.csv"),
ScriptFormat.SQL);
// The importer
private static Importer importer =
new Importer(
new BasicDataSource(
"org.h2.Driver",
"jdbc:h2:demo-scott-subset",
"sa",
"",
10,
new File(
"lib/h2-1.3.160.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();
}
}