Search in sources :

Example 46 with TriggerHistory

use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.

the class TriggerRouterService method fillTriggerRoutersByHistIdAndSortHist.

public Map<Integer, List<TriggerRouter>> fillTriggerRoutersByHistIdAndSortHist(String sourceNodeGroupId, String targetNodeGroupId, List<TriggerHistory> triggerHistories) {
    final Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = fillTriggerRoutersByHistId(sourceNodeGroupId, targetNodeGroupId, triggerHistories);
    final List<Table> sortedTables = getSortedTablesFor(triggerHistories);
    Comparator<TriggerHistory> comparator = new Comparator<TriggerHistory>() {

        public int compare(TriggerHistory o1, TriggerHistory o2) {
            List<TriggerRouter> triggerRoutersForTriggerHist1 = triggerRoutersByHistoryId.get(o1.getTriggerHistoryId());
            int intialLoadOrder1 = 0;
            for (TriggerRouter triggerRouter1 : triggerRoutersForTriggerHist1) {
                if (triggerRouter1.getInitialLoadOrder() > intialLoadOrder1) {
                    intialLoadOrder1 = triggerRouter1.getInitialLoadOrder();
                }
            }
            List<TriggerRouter> triggerRoutersForTriggerHist2 = triggerRoutersByHistoryId.get(o2.getTriggerHistoryId());
            int intialLoadOrder2 = 0;
            for (TriggerRouter triggerRouter2 : triggerRoutersForTriggerHist2) {
                if (triggerRouter2.getInitialLoadOrder() > intialLoadOrder2) {
                    intialLoadOrder2 = triggerRouter2.getInitialLoadOrder();
                }
            }
            if (intialLoadOrder1 < intialLoadOrder2) {
                return -1;
            } else if (intialLoadOrder1 > intialLoadOrder2) {
                return 1;
            }
            Table table1 = platform.getTableFromCache(o1.getSourceCatalogName(), o1.getSourceSchemaName(), o1.getSourceTableName(), false);
            Table table2 = platform.getTableFromCache(o2.getSourceCatalogName(), o2.getSourceSchemaName(), o2.getSourceTableName(), false);
            return new Integer(sortedTables.indexOf(table1)).compareTo(new Integer(sortedTables.indexOf(table2)));
        }

        ;
    };
    Collections.sort(triggerHistories, comparator);
    return triggerRoutersByHistoryId;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Example 47 with TriggerHistory

use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.

the class ColumnMatchDataRouterTest method testExpressionNotEqualsNodeId.

@Test
public void testExpressionNotEqualsNodeId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("NODE_ID != :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(2, result.size());
    assertEquals(true, result.contains("200"));
    assertEquals(true, result.contains("300"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 48 with TriggerHistory

use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.

the class ConfigurationChangedDataRouterTest method buildDataMetaData.

protected DataMetaData buildDataMetaData(String tableName, String nodeId) {
    Data data = new Data();
    data.setTableName(tableName);
    data.setDataEventType(DataEventType.UPDATE);
    data.setTriggerHistory(new TriggerHistory(tableName, "NODE_ID", "NODE_ID"));
    data.setPkData(nodeId);
    data.setRowData(nodeId);
    return new DataMetaData(data, new Table(tableName), null, null);
}
Also used : Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) DataMetaData(org.jumpmind.symmetric.model.DataMetaData)

Example 49 with TriggerHistory

use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.

the class ColumnMatchDataRouterTest method testExpressionEqualsNodeId.

@Test
public void testExpressionEqualsNodeId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("NODE_ID = :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(1, result.size());
    assertEquals(true, result.contains("100"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 50 with TriggerHistory

use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.

the class NonDmlEventsTest method test.

@Override
protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer) throws Exception {
    loadConfigAndRegisterNode("client", "root");
    // pull to clear out any heartbeat events
    pull("client");
    List<TriggerHistory> histories = rootServer.getTriggerRouterService().findTriggerHistories(null, null, testTable.getName());
    assertNotNull(histories);
    assertEquals(1, histories.size());
    String serverQuote = rootServer.getDatabasePlatform().getDatabaseInfo().getDelimiterToken();
    String clientQuote = clientServer.getDatabasePlatform().getDatabaseInfo().getDelimiterToken();
    for (int i = 0; i < 100; i++) {
        rootServer.getSqlTemplate().update(String.format("insert into %sCamelCase%s values (?,?)", serverQuote, serverQuote), i, "this is a test");
    }
    String serverCountSql = String.format("select count(*) from %sCamelCase%s", serverQuote, serverQuote);
    String clientCountSql = String.format("select count(*) from %sCamelCase%s", clientQuote, clientQuote);
    assertEquals(100, rootServer.getDatabasePlatform().getSqlTemplate().queryForInt(serverCountSql));
    assertEquals(0, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(clientCountSql));
    // we installed a dead trigger, so no data should have been captured
    assertFalse(pull("client"));
    rootServer.getDataService().reloadTable("client", null, null, testTable.getName());
    assertTrue(pull("client"));
    assertEquals(100, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(clientCountSql));
    rootServer.getDataService().sendSQL("client", null, null, testTable.getName(), String.format("insert into %sCamelCase%s values (101,'direct insert')", clientQuote, clientQuote));
    rootServer.getDataService().sendSQL("client", null, null, testTable.getName(), String.format("insert into %sCamelCase%s values (102,'direct insert')", clientQuote, clientQuote));
    assertTrue(pull("client"));
    assertEquals(102, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(clientCountSql));
    rootServer.getDataService().sendSQL("client", null, null, testTable.getName(), String.format("delete from %sCamelCase%s", clientQuote, clientQuote));
    assertTrue(pull("client"));
    assertEquals(0, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(clientCountSql));
    rootServer.getDataService().reloadTable("client", null, null, testTable.getName(), String.format("%sId%s < 50", serverQuote, serverQuote));
    assertTrue(pull("client"));
    assertEquals(50, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(clientCountSql));
    Table serverTable = rootServer.getDatabasePlatform().readTableFromDatabase(null, null, "A");
    Table clientTable = clientServer.getDatabasePlatform().readTableFromDatabase(null, null, "A");
    // test a wildcard table
    for (int i = 0; i < 10; i++) {
        rootServer.getSqlTemplate().update(String.format("insert into %s values (?)", serverTable.getName()), i);
    }
    assertFalse(pull("client"));
    String msg = rootServer.getDataService().reloadTable("client", null, null, "A");
    assertTrue("Should have pulled data for the reload event for table A.  The reload table method returned the following text: " + msg, pull("client"));
    assertEquals(10, clientServer.getDatabasePlatform().getSqlTemplate().queryForInt(String.format("select count(*) from %s", clientTable.getName())));
    testRoutingOfReloadEvents(rootServer, clientServer);
}
Also used : Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory)

Aggregations

TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)50 Table (org.jumpmind.db.model.Table)19 Data (org.jumpmind.symmetric.model.Data)19 Node (org.jumpmind.symmetric.model.Node)17 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)14 Trigger (org.jumpmind.symmetric.model.Trigger)14 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)13 HashSet (java.util.HashSet)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Router (org.jumpmind.symmetric.model.Router)10 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)9 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)8 List (java.util.List)6 CsvData (org.jumpmind.symmetric.io.data.CsvData)6 SymmetricException (org.jumpmind.symmetric.SymmetricException)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 Date (java.util.Date)4 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)4 HashMap (java.util.HashMap)3