Search in sources :

Example 1 with ISymmetricDialect

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

the class AbstractTriggerRouterServiceTest method test11BinaryColumnTypesForOracle.

@Test
public void test11BinaryColumnTypesForOracle() {
    ISymmetricDialect dialect = getDbDialect();
    if (DatabaseNamesConstants.ORACLE.equals(dialect.getName())) {
        getSqlTemplate().update(CREATE_ORACLE_BINARY_TYPE);
        TriggerRouter trouter = new TriggerRouter();
        Trigger trigger = trouter.getTrigger();
        trigger.setSourceTableName("test_oracle_binary_types");
        trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
        Router router = trouter.getRouter();
        router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        getTriggerRouterService().saveTriggerRouter(trouter);
        ITriggerRouterService triggerService = getTriggerRouterService();
        triggerService.syncTriggers();
        Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
        getSqlTemplate().update(INSERT_ORACLE_BINARY_TYPE_1);
        String csvString = getNextDataRow();
        Assert.assertEquals(EXPECTED_INSERT_ORALCE_BINARY_TYPE_1, csvString);
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 2 with ISymmetricDialect

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

the class AbstractTriggerRouterServiceTest method test10DisableTriggers.

@Test
public void test10DisableTriggers() throws Exception {
    ISymmetricDialect dbDialect = getDbDialect();
    ISqlTemplate jdbcTemplate = getSqlTemplate();
    ISqlTransaction transaction = jdbcTemplate.startSqlTransaction();
    try {
        dbDialect.disableSyncTriggers(transaction, null);
        int count = insert(INSERT1_VALUES, transaction, dbDialect);
        dbDialect.enableSyncTriggers(transaction);
        transaction.commit();
        assertTrue(count == 1);
        String csvString = getNextDataRow();
        // DB2 captures decimal differently
        csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
        // Informix captures decimal differently
        csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
        // ASA captures decimal differently
        csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
        boolean match = csvString.endsWith(EXPECTED_INSERT2_CSV_ENDSWITH);
        assertTrue(match, "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT2_CSV_ENDSWITH);
    } finally {
        transaction.close();
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Test(org.junit.Test)

Example 3 with ISymmetricDialect

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

the class AbstractTriggerRouterServiceTest method test12BinaryColumnTypesForPostgres.

@Test
public void test12BinaryColumnTypesForPostgres() {
    ISymmetricDialect dialect = getDbDialect();
    if (DatabaseNamesConstants.POSTGRESQL.equals(dialect.getName())) {
        getSqlTemplate().update(DROP_POSTGRES_BINARY_TYPE);
        getSqlTemplate().update(CREATE_POSTGRES_BINARY_TYPE);
        TriggerRouter trouter = new TriggerRouter();
        Trigger trigger = trouter.getTrigger();
        trigger.setSourceTableName("test_postgres_binary_types");
        trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
        Router router = trouter.getRouter();
        router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
        getTriggerRouterService().saveTriggerRouter(trouter);
        ITriggerRouterService triggerService = getTriggerRouterService();
        triggerService.syncTriggers();
        Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
        // new SerialBlob("test 1 2 3".getBytes())
        ISqlTransaction transaction = getSqlTemplate().startSqlTransaction();
        try {
            getSqlTemplate().update(INSERT_POSTGRES_BINARY_TYPE_1, "test 1 2 3".getBytes());
            transaction.commit();
        } finally {
            transaction.close();
        }
        String csvString = getNextDataRow();
        Assert.assertEquals(EXPECTED_INSERT_POSTGRES_BINARY_TYPE_1, csvString);
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Example 4 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect 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 5 with ISymmetricDialect

use of org.jumpmind.symmetric.db.ISymmetricDialect 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)

Aggregations

ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)13 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)5 Test (org.junit.Test)4 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)3 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)3 Router (org.jumpmind.symmetric.model.Router)3 Trigger (org.jumpmind.symmetric.model.Trigger)3 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)3 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)3 IParameterService (org.jumpmind.symmetric.service.IParameterService)3 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)3 Node (org.jumpmind.symmetric.model.Node)2 Before (org.junit.Before)2 ArrayList (java.util.ArrayList)1 Database (org.jumpmind.db.model.Database)1 AbstractJdbcDatabasePlatform (org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)1 IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)1 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)1 SqlScript (org.jumpmind.db.sql.SqlScript)1