Search in sources :

Example 1 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method insert.

protected void insert(final String tableName, final int count, boolean transactional, final String node2disable, final String routingVarcharFieldValue, final boolean rollback) {
    ISymmetricDialect dialect = getDbDialect();
    IDatabasePlatform platform = dialect.getPlatform();
    String columnName = platform.alterCaseToMatchDatabaseDefaultCase("ROUTING_VARCHAR");
    ISqlTransaction transaction = null;
    try {
        transaction = platform.getSqlTemplate().startSqlTransaction();
        if (node2disable != null) {
            dialect.disableSyncTriggers(transaction, node2disable);
        }
        transaction.prepare(String.format("insert into %s (%s) values(?)", tableName, columnName));
        for (int i = 0; i < count; i++) {
            transaction.addRow(i, new Object[] { routingVarcharFieldValue }, new int[] { Types.VARCHAR });
            if (!transactional) {
                transaction.commit();
            }
        }
        if (node2disable != null) {
            dialect.enableSyncTriggers(transaction);
        }
        if (rollback) {
            transaction.rollback();
        } else {
            transaction.flush();
            transaction.commit();
        }
    } finally {
        if (transaction != null) {
            transaction.close();
        }
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction)

Example 2 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class RouterServiceTest method setup.

@Before
public void setup() {
    ISymmetricEngine engine = mock(ISymmetricEngine.class);
    IParameterService parameterService = mock(IParameterService.class);
    ISymmetricDialect symmetricDialect = mock(ISymmetricDialect.class);
    IDatabasePlatform databasePlatform = mock(IDatabasePlatform.class);
    IExtensionService extensionService = mock(IExtensionService.class);
    when(databasePlatform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    when(symmetricDialect.getPlatform()).thenReturn(databasePlatform);
    when(engine.getDatabasePlatform()).thenReturn(databasePlatform);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    routerService = new RouterService(engine);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) IParameterService(org.jumpmind.symmetric.service.IParameterService) Before(org.junit.Before)

Example 3 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method setUp.

@Before
public void setUp() throws Exception {
    sqlTemplate = mock(ISqlTemplate.class);
    sqlTransaction = mock(ISqlTransaction.class);
    when(sqlTemplate.startSqlTransaction()).thenReturn(sqlTransaction);
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    when(symmetricDialect.supportsTransactionViews()).thenReturn(false);
    when(symmetricDialect.getDatabaseTime()).thenReturn(0L);
    parameterService = mock(ParameterService.class);
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.getLong(ParameterConstants.ROUTING_STALE_DATA_ID_GAP_TIME)).thenReturn(60000000L);
    when(parameterService.getInt(ParameterConstants.DATA_ID_INCREMENT_BY)).thenReturn(1);
    when(parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)).thenReturn(50000000L);
    when(parameterService.getLong(ParameterConstants.DBDIALECT_ORACLE_TRANSACTION_VIEW_CLOCK_SYNC_THRESHOLD_MS)).thenReturn(60000L);
    when(parameterService.getLong(ParameterConstants.ROUTING_STALE_GAP_BUSY_EXPIRE_TIME)).thenReturn(60000L);
    when(parameterService.is(ParameterConstants.ROUTING_DETECT_INVALID_GAPS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAP_CHANGES)).thenReturn(1000);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    contextService = mock(ContextService.class);
    dataService = mock(DataService.class);
    statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    detector = newGapDetector();
    detector.setFullGapAnalysis(false);
}
Also used : RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) IContextService(org.jumpmind.symmetric.service.IContextService) ContextService(org.jumpmind.symmetric.service.impl.ContextService) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) IParameterService(org.jumpmind.symmetric.service.IParameterService) ParameterService(org.jumpmind.symmetric.service.impl.ParameterService) INodeService(org.jumpmind.symmetric.service.INodeService) NodeService(org.jumpmind.symmetric.service.impl.NodeService) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) DataService(org.jumpmind.symmetric.service.impl.DataService) IDataService(org.jumpmind.symmetric.service.IDataService) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) StatisticManager(org.jumpmind.symmetric.statistic.StatisticManager) AbstractSymmetricDialect(org.jumpmind.symmetric.db.AbstractSymmetricDialect) Before(org.junit.Before)

Example 4 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AuditTableDataRouter method toAuditTable.

protected Table toAuditTable(Table table) {
    IDatabasePlatform platform = engine.getDatabasePlatform();
    Table auditTable = table.copy();
    auditTable.setName(String.format("%s_%s", auditTable.getName(), platform.alterCaseToMatchDatabaseDefaultCase("AUDIT")));
    Column[] columns = auditTable.getColumns();
    auditTable.removeAllColumns();
    auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0));
    auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0));
    auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0));
    for (Column column : columns) {
        column.setRequired(false);
        column.setPrimaryKey(false);
        column.setAutoIncrement(false);
        auditTable.addColumn(column);
    }
    auditTable.removeAllForeignKeys();
    auditTable.removeAllIndices();
    platform.alterCaseToMatchDatabaseDefaultCase(auditTable);
    return auditTable;
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column)

Example 5 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform 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()));
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) SqlException(org.jumpmind.db.sql.SqlException) DbImport(org.jumpmind.symmetric.io.data.DbImport) 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