use of org.jumpmind.symmetric.io.data.DbImport in project symmetric-ds by JumpMind.
the class DbExportImportTest method importUniqueKeywordTable.
@Test
public void importUniqueKeywordTable() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
DbImport dbImport = new DbImport(engine.getDatabasePlatform());
dbImport.setFormat(DbImport.Format.XML);
dbImport.setDropIfExists(true);
dbImport.setAlterCaseToMatchDatabaseDefaultCase(true);
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
Database testTables = platform.readDatabaseFromXml("/test-dbimport-unique.xml", true);
Table table = testTables.findTable("test_db_import_unique", false);
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
Assert.assertEquals(table.getColumnWithName("string_required_value").isUnique(), true);
DbImport importCsv = new DbImport(engine.getDatabasePlatform());
importCsv.setFormat(DbImport.Format.SQL);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-good.sql"));
Assert.assertEquals(5, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
try {
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.fail("Expected a sql exception");
} catch (SqlException ex) {
}
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
importCsv.setCommitRate(1);
importCsv.setForceImport(true);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-unique-bad-line-2.sql"));
Assert.assertEquals(4, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
}
use of org.jumpmind.symmetric.io.data.DbImport in project symmetric-ds by JumpMind.
the class DbExportImportTest method exportUniqueKeywordSqliteTable.
@Test
public void exportUniqueKeywordSqliteTable() throws Exception {
String dbName = engine.getDatabasePlatform().getName();
if (dbName.equals(DatabaseNamesConstants.SQLITE)) {
ISymmetricEngine engine = getSymmetricEngine();
DbImport dbImport = new DbImport(engine.getDatabasePlatform());
dbImport.setFormat(DbImport.Format.XML);
dbImport.setDropIfExists(true);
dbImport.setAlterCaseToMatchDatabaseDefaultCase(true);
dbImport.importTables(getClass().getResourceAsStream("/test-dbimport-unique.xml"));
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
Database testTables = platform.readDatabaseFromXml("/test-dbimport-unique.xml", true);
Table table = testTables.findTable("test_db_import_unique", false);
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
Assert.assertEquals(table.getColumnWithName("string_required_value").isUnique(), true);
final int RECORD_COUNT = 100;
DbFill fill = new DbFill(platform);
fill.setRecordCount(RECORD_COUNT);
fill.fillTables(table.getName());
Assert.assertEquals(RECORD_COUNT, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
DbExport export = new DbExport(platform);
export.setFormat(Format.XML);
export.setNoCreateInfo(false);
export.setNoData(true);
String xmlOutput = export.exportTables(new String[] { table.getName() });
dbImport.importTables(xmlOutput);
table = testTables.findTable("test_db_import_unique", false);
Assert.assertEquals(0, platform.getSqlTemplate().queryForInt("select count(*) from " + table.getName()));
Assert.assertEquals(table.getColumnWithName("string_required_value").isUnique(), true);
}
}
use of org.jumpmind.symmetric.io.data.DbImport in project symmetric-ds by JumpMind.
the class DbExportImportTest method importSymXmlData.
@Test
public void importSymXmlData() throws Exception {
final String FILE = "/test-dbimport-1-sym_xml-1.xml";
ISymmetricEngine engine = getSymmetricEngine();
recreateImportTable();
assertCountDbImportTableRecords(0);
DbImport importCsv = new DbImport(engine.getDatabasePlatform());
importCsv.setFormat(DbImport.Format.SYM_XML);
importCsv.importTables(getClass().getResourceAsStream(FILE));
assertCountDbImportTableRecords(2);
try {
importCsv.importTables(getClass().getResourceAsStream(FILE));
Assert.fail("Expected a sql exception");
} catch (ConflictException ex) {
}
assertCountDbImportTableRecords(2);
recreateImportTable();
importCsv.setReplaceRows(true);
importCsv.importTables(getClass().getResourceAsStream(FILE));
assertCountDbImportTableRecords(2);
}
use of org.jumpmind.symmetric.io.data.DbImport in project symmetric-ds by JumpMind.
the class DbExportImportTest method importSqlData.
@Test
public void importSqlData() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
recreateImportTable();
assertCountDbImportTableRecords(0);
DbImport importCsv = new DbImport(engine.getDatabasePlatform());
importCsv.setFormat(DbImport.Format.SQL);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-1-good.sql"));
assertCountDbImportTableRecords(5);
recreateImportTable();
assertCountDbImportTableRecords(0);
try {
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-1-bad-line-2.sql"));
Assert.fail("Expected a sql exception");
} catch (SqlException ex) {
}
assertCountDbImportTableRecords(0);
importCsv.setCommitRate(1);
importCsv.setForceImport(true);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-1-bad-line-2.sql"));
assertCountDbImportTableRecords(4);
}
use of org.jumpmind.symmetric.io.data.DbImport in project symmetric-ds by JumpMind.
the class DbExportImportTest method exportThenImportCsv.
@Test
public void exportThenImportCsv() throws Exception {
ISymmetricEngine engine = getSymmetricEngine();
IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
Database testTables = platform.readDatabaseFromXml("/test-dbimport.xml", true);
Table table = testTables.findTable("test_db_import_1", false);
recreateImportTable();
final int RECORD_COUNT = 100;
DbFill fill = new DbFill(platform);
fill.setRecordCount(RECORD_COUNT);
fill.fillTables(table.getName());
DbExport export = new DbExport(platform);
export.setFormat(Format.CSV);
export.setNoCreateInfo(true);
export.setNoData(false);
String csvOutput = export.exportTables(new String[] { table.getName() });
logger.info(csvOutput);
ISqlTemplate sqlTemplate = platform.getSqlTemplate();
List<Row> rowsBeforeImport = sqlTemplate.query(SELECT_FROM_TEST_DB_IMPORT_1_ORDER_BY_ID);
recreateImportTable();
DbImport importCsv = new DbImport(platform);
importCsv.setFormat(DbImport.Format.CSV);
importCsv.importTables(csvOutput, table.getName());
Assert.assertEquals(RECORD_COUNT, sqlTemplate.queryForInt("select count(*) from " + table.getName()));
compareRows(table, rowsBeforeImport, sqlTemplate.query(SELECT_FROM_TEST_DB_IMPORT_1_ORDER_BY_ID));
// TODO test error
// TODO test replace
// TODO test ignore
// TODO test force
}
Aggregations