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;
}
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"));
}
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);
}
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"));
}
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);
}
Aggregations