Search in sources :

Example 16 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractIntegrationTest method checkForFailedTriggers.

protected void checkForFailedTriggers(boolean server, boolean client) {
    if (server) {
        ITriggerRouterService service = getServer().getTriggerRouterService();
        assertEquals(0, service.getFailedTriggers().size());
    }
    if (client) {
        ITriggerRouterService service = getClient().getTriggerRouterService();
        assertEquals(0, service.getFailedTriggers().size());
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService)

Example 17 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test06InitialLoadSql.

@Test
public void test06InitialLoadSql() throws Exception {
    ITriggerRouterService triggerRouterService = getTriggerRouterService();
    IParameterService parameterService = getParameterService();
    parameterService.saveParameter(ParameterConstants.INITIAL_LOAD_CONCAT_CSV_IN_SQL_ENABLED, true, "unittest");
    TriggerRouter triggerRouter = triggerRouterService.getTriggerRouterForTableForCurrentNode(true, null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
    Table table = getDbDialect().getPlatform().getTableFromCache(triggerRouter.getTrigger().getSourceTableName(), true);
    Trigger trigger = triggerRouter.getTrigger();
    String sql = getDbDialect().createInitialLoadSqlFor(new Node("1", null, "1.0"), triggerRouter, table, triggerRouterService.getNewestTriggerHistoryForTrigger(trigger.getTriggerId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()), getConfigurationService().getChannel(triggerRouter.getTrigger().getChannelId()), null);
    List<String> csvStrings = getSqlTemplate().query(sql, new StringMapper());
    assertTrue(csvStrings.size() > 0);
    String csvString = csvStrings.get(0);
    // 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\"");
    assertTrue(csvString.endsWith(EXPECTED_INSERT1_CSV_ENDSWITH), "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT1_CSV_ENDSWITH);
}
Also used : StringMapper(org.jumpmind.db.sql.mapper.StringMapper) Table(org.jumpmind.db.model.Table) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) Node(org.jumpmind.symmetric.model.Node) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) IParameterService(org.jumpmind.symmetric.service.IParameterService) Test(org.junit.Test)

Example 18 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test09ExcludedColumnsFunctionality.

@Test
public void test09ExcludedColumnsFunctionality() throws Exception {
    ITriggerRouterService service = getTriggerRouterService();
    ISqlTemplate jdbcTemplate = getSqlTemplate();
    assertEquals(1, jdbcTemplate.update("update sym_trigger set excluded_column_names='BOOLEAN_VALUE', last_update_time=? " + TEST_TRIGGER_WHERE_CLAUSE, new Object[] { new Date(System.currentTimeMillis() + 60000) }));
    service.syncTriggers();
    TriggerRouter triggerRouter = service.getTriggerRouterForTableForCurrentNode(true, null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
    assertEquals(jdbcTemplate.queryForInt("select count(*) from sym_trigger_hist where trigger_id='" + triggerRouter.getTrigger().getTriggerId() + "' and inactive_time is null"), 1, "We expected only one active record in the trigger_hist table for " + TEST_TRIGGERS_TABLE);
    assertEquals(1, insert(INSERT2_VALUES, jdbcTemplate, getDbDialect()));
    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);
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Date(java.util.Date) Test(org.junit.Test)

Example 19 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class AbstractTriggerRouterServiceTest method test13BinaryColumnTypesForDerby.

@Test
public void test13BinaryColumnTypesForDerby() {
    ISymmetricDialect dialect = getDbDialect();
    if (DatabaseNamesConstants.DERBY.equals(dialect.getName())) {
        try {
            getSqlTemplate().update("drop table test_derby_binary_types");
        } catch (Exception e) {
        }
        getSqlTemplate().update("create table test_derby_binary_types (id integer, data VARCHAR (100) FOR BIT DATA, data2 CHAR(12) FOR BIT DATA)");
        TriggerRouter trouter = new TriggerRouter();
        Trigger trigger = trouter.getTrigger();
        trigger.setSourceTableName("test_derby_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 into test_derby_binary_types values (?, ?, ?)", new Object[] { 23, "test 1 2 3".getBytes(), "test 1 2 3".getBytes() });
        String csvString = getNextDataRow();
        Assert.assertEquals("\"23\",\"dGVzdCAxIDIgMw==\",\"dGVzdCAxIDIgMyAg\"", 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 20 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class SymmetricAdmin method syncTrigger.

private void syncTrigger(CommandLine line, List<String> args) throws IOException {
    boolean genAlways = line.hasOption(OPTION_FORCE);
    String filename = line.getOptionValue(OPTION_OUT);
    String catalogName = line.getOptionValue(OPTION_CATALOG);
    String schemaName = line.getOptionValue(OPTION_SCHEMA);
    File file = null;
    if (filename != null) {
        file = new File(filename);
        if (file.getParentFile() != null) {
            file.getParentFile().mkdirs();
        }
    }
    ITriggerRouterService triggerService = getSymmetricEngine().getTriggerRouterService();
    StringBuilder sqlBuffer = new StringBuilder();
    if (args.size() == 0) {
        triggerService.syncTriggers(sqlBuffer, genAlways);
    } else {
        for (String tablename : args) {
            Table table = platform.getTableFromCache(catalogName, schemaName, tablename, true);
            if (table != null) {
                triggerService.syncTriggers(table, genAlways);
            } else {
                System.out.println("Unable to find table " + tablename);
            }
        }
    }
    if (file != null) {
        FileUtils.writeStringToFile(file, sqlBuffer.toString());
    }
}
Also used : Table(org.jumpmind.db.model.Table) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) File(java.io.File)

Aggregations

ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)27 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)12 Trigger (org.jumpmind.symmetric.model.Trigger)11 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)9 Node (org.jumpmind.symmetric.model.Node)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 Router (org.jumpmind.symmetric.model.Router)5 Table (org.jumpmind.db.model.Table)4 INodeService (org.jumpmind.symmetric.service.INodeService)4 File (java.io.File)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2