use of org.jumpmind.db.platform.IDatabasePlatform 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.db.platform.IDatabasePlatform 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
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method exportThenImportXml.
@Test
public void exportThenImportXml() 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();
DbExport export = new DbExport(platform);
export.setFormat(Format.XML);
export.setNoCreateInfo(false);
export.setNoData(true);
export.setSchema(getSymmetricEngine().getSymmetricDialect().getPlatform().getDefaultSchema());
export.setCatalog(getSymmetricEngine().getSymmetricDialect().getPlatform().getDefaultCatalog());
export.exportTables(new String[] { table.getName() });
// System.out.println(output);
// TODO validate
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method createAndFillTimestampWithTimeZoneTable.
protected boolean createAndFillTimestampWithTimeZoneTable() {
ISymmetricEngine engine = getSymmetricEngine();
IDatabasePlatform platform = engine.getDatabasePlatform();
String dbName = platform.getName();
if (dbName.equals(DatabaseNamesConstants.ORACLE) || dbName.equals(DatabaseNamesConstants.POSTGRESQL)) {
ISqlTemplate template = engine.getSqlTemplate();
try {
template.update(String.format("drop table \"%s\"", TEST_TS_W_TZ));
} catch (Exception ex) {
}
String createSql = String.format("create table \"%s\" (\"id\" integer, \"tz\" timestamp with time zone, primary key (\"id\"))", TEST_TS_W_TZ);
template.update(createSql);
DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, platform.getTableFromCache(TEST_TS_W_TZ, true), null);
template.update(statement.getSql(), statement.getValueArray(new Object[] { 1, "1973-06-08 07:00:00.000 -04:00" }, new Object[] { 1 }));
return true;
} else {
return false;
}
}
use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.
the class DbExportImportTest method exportThenImportCsvWithBackslashes.
@Test
public void exportThenImportCsvWithBackslashes() 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();
DbImport importCsv = new DbImport(platform);
importCsv.setFormat(DbImport.Format.SQL);
importCsv.importTables(getClass().getResourceAsStream("/test-dbimport-1-backslashes.sql"));
assertCountDbImportTableRecords(1);
DbExport export = new DbExport(platform);
export.setFormat(Format.CSV);
export.setNoCreateInfo(true);
export.setNoData(false);
String csvOutput = export.exportTables(new String[] { table.getName() });
ISqlTemplate sqlTemplate = platform.getSqlTemplate();
List<Row> rowsBeforeImport = sqlTemplate.query(SELECT_FROM_TEST_DB_IMPORT_1_ORDER_BY_ID);
recreateImportTable();
importCsv.setFormat(DbImport.Format.CSV);
importCsv.importTables(csvOutput, table.getName());
compareRows(table, rowsBeforeImport, sqlTemplate.query(SELECT_FROM_TEST_DB_IMPORT_1_ORDER_BY_ID));
}
Aggregations