Search in sources :

Example 6 with IDatabasePlatform

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);
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) DbImport(org.jumpmind.symmetric.io.data.DbImport) DbFill(org.jumpmind.symmetric.io.data.DbFill) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Example 7 with IDatabasePlatform

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
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) Row(org.jumpmind.db.sql.Row) DbImport(org.jumpmind.symmetric.io.data.DbImport) DbFill(org.jumpmind.symmetric.io.data.DbFill) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Example 8 with IDatabasePlatform

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
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Example 9 with IDatabasePlatform

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;
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) DmlStatement(org.jumpmind.db.sql.DmlStatement) SqlException(org.jumpmind.db.sql.SqlException) ConflictException(org.jumpmind.symmetric.io.data.writer.ConflictException)

Example 10 with IDatabasePlatform

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));
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) DbImport(org.jumpmind.symmetric.io.data.DbImport) Row(org.jumpmind.db.sql.Row) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Aggregations

IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)27 Table (org.jumpmind.db.model.Table)13 Database (org.jumpmind.db.model.Database)9 Test (org.junit.Test)9 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)8 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)7 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)6 DbExport (org.jumpmind.symmetric.io.data.DbExport)6 DbImport (org.jumpmind.symmetric.io.data.DbImport)6 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)5 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)5 Column (org.jumpmind.db.model.Column)4 Before (org.junit.Before)4 File (java.io.File)3 DmlStatement (org.jumpmind.db.sql.DmlStatement)3 Row (org.jumpmind.db.sql.Row)3 SqlException (org.jumpmind.db.sql.SqlException)3