use of org.jumpmind.db.sql.InvalidSqlException in project symmetric-ds by JumpMind.
the class SubSelectDataRouter method routeToNodes.
public Set<String> routeToNodes(SimpleRouterContext routingContext, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
String sql = FormatUtils.replaceToken(SQL, "prefixName", symmetricDialect.getTablePrefix(), true);
String subSelect = dataMetaData.getRouter().getRouterExpression();
Set<String> nodeIds = null;
if (!StringUtils.isBlank(subSelect) && !initialLoadSelectUsed) {
try {
Map<String, Object> sqlParams = getDataObjectMap(dataMetaData, symmetricDialect, true);
sqlParams.put("NODE_GROUP_ID", dataMetaData.getRouter().getNodeGroupLink().getTargetNodeGroupId());
sqlParams.put("EXTERNAL_DATA", dataMetaData.getData().getExternalData());
ISqlTemplate template = symmetricDialect.getPlatform().getSqlTemplate();
List<String> ids = template.query(String.format("%s%s", sql, subSelect), new StringMapper(), sqlParams);
if (ids != null) {
nodeIds = new HashSet<String>(ids);
}
} catch (InvalidSqlException ex) {
log.error("The subselect expression was invalid for the {} subselect router for the '{}' event for table '{}'", new Object[] { dataMetaData.getRouter().getRouterId(), dataMetaData.getData().getDataEventType().name(), dataMetaData.getData().getTableName() });
throw ex;
}
} else if (initialLoadSelectUsed) {
nodeIds = toNodeIds(nodes, null);
} else {
throw new InvalidSqlException("The subselect expression is missing for the %s router", dataMetaData.getRouter().getRouterId());
}
return nodeIds;
}
Aggregations