ColumnMatchDataRouter extends AbstractDataRouter implements IDataRouter, IBuiltInExtensionPoint { public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) { Set<String> nodeIds = null; if (initialLoadSelectUsed && initialLoad) { nodeIds = toNodeIds(nodes, null); } else { List<Expression> expressions = getExpressions(dataMetaData.getRouter(), routingContext); Map<String, String> columnValues = getDataMap(dataMetaData, symmetricDialect); if (columnValues != null) { for (Expression e : expressions) { String column = e.tokens[0].trim(); String value = e.tokens[1]; String columnValue = columnValues.get(column); if (value.equalsIgnoreCase(TokenConstants.NODE_ID)) { for (Node node : nodes) { nodeIds = runExpression(e, columnValue, node.getNodeId(), nodes, nodeIds, node); } } else if (value.equalsIgnoreCase(TokenConstants.EXTERNAL_ID)) { for (Node node : nodes) { nodeIds = runExpression(e, columnValue, node.getExternalId(), nodes, nodeIds, node); } } else if (value.equalsIgnoreCase(TokenConstants.NODE_GROUP_ID)) { for (Node node : nodes) { nodeIds = runExpression(e, columnValue, node.getNodeGroupId(), nodes, nodeIds, node); } } else if (e.hasEquals && value.equalsIgnoreCase(TokenConstants.REDIRECT_NODE)) { Map<String, String> redirectMap = getRedirectMap(routingContext); String nodeId = redirectMap.get(columnValue); if (nodeId != null) { nodeIds = addNodeId(nodeId, nodeIds, nodes); } } else { String compareValue = value; if (value.equalsIgnoreCase(TokenConstants.EXTERNAL_DATA)) { compareValue = dataMetaData.getData().getExternalData(); } else if (value.startsWith(":")) { compareValue = columnValues.get(value.substring(1)); } else if (value.equals(NULL_VALUE)) { compareValue = null; } nodeIds = runExpression(e, columnValue, compareValue, nodes, nodeIds, null); } } } else { log.warn("There were no columns to match for the data_id of {}", dataMetaData .getData().getDataId()); } } if(nodeIds != null) { nodeIds.remove(null); } else { nodeIds = Collections.emptySet(); } return nodeIds; } ColumnMatchDataRouter();  ColumnMatchDataRouter(IConfigurationService configurationService, ISymmetricDialect symmetricDialect); Set<String> routeToNodes(SimpleRouterContext routingContext,
            DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter); List<Expression> parse(String routerExpression);  }
@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")); }
@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")); }
@Test public void testExpressionEqualsExternalId() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); SimpleRouterContext routingContext = new SimpleRouterContext(); HashSet<Node> nodes = new HashSet<Node>(); nodes.add(new Node("1000", "client")); nodes.add(new Node("100", "client")); nodes.add(new Node("10", "client")); TriggerHistory triggerHist = new TriggerHistory("mytable","ID","ID,STORE_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("STORE_ID = :EXTERNAL_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")); }
@Test public void testExpressionEqualsGroupId() { ColumnMatchDataRouter router = new ColumnMatchDataRouter(); SimpleRouterContext routingContext = new SimpleRouterContext(); HashSet<Node> nodes = new HashSet<Node>(); nodes.add(new Node("10", "server")); nodes.add(new Node("20", "server")); nodes.add(new Node("3", "client")); nodes.add(new Node("2", "client")); nodes.add(new Node("1", "client")); TriggerHistory triggerHist = new TriggerHistory("mytable","ID","ID,GROUP_ID,COLUMN2"); Data data = new Data(); data.setDataId(1); data.setDataEventType(DataEventType.INSERT); data.setRowData("1,client,Super Dooper"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("GROUP_ID = :NODE_GROUP_ID"); route.setRouterId("route1"); DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel); Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null); assertEquals(3, result.size()); assertEquals(true, result.contains("1")); assertEquals(true, result.contains("2")); assertEquals(true, result.contains("3")); }
@Test public void testExpressionEqualsNull() { 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")); 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,"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("COLUMN2 = NULL"); 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("100")); assertEquals(true, result.contains("200")); }
@Test public void testExpressionNotEqualsNull() { 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")); 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,"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("COLUMN2 != NULL"); route.setRouterId("route1"); DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel); Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null); assertEquals(0, result.size()); }
@Test public void testExpressionExternalData() { 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.setExternalData("100"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("EXTERNAL_DATA = :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")); }
@Test public void testExpressionContains() { 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")); nodes.add(new Node("1000", "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.setExternalData("1000,200"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("EXTERNAL_DATA contains :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("1000")); assertEquals(true, result.contains("200")); }
@Test public void testExpressionNotContains() { 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")); nodes.add(new Node("1000", "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.setExternalData("1000,200"); data.setTriggerHistory(triggerHist); Table table = new Table(); NodeChannel nodeChannel = new NodeChannel(); Router route = new Router(); route.setRouterExpression("EXTERNAL_DATA not contains :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("100")); assertEquals(true, result.contains("300")); }