Search in sources :

Example 1 with InvalidSqlException

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;
}
Also used : StringMapper(org.jumpmind.db.sql.mapper.StringMapper) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) InvalidSqlException(org.jumpmind.db.sql.InvalidSqlException)

Aggregations

ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)1 InvalidSqlException (org.jumpmind.db.sql.InvalidSqlException)1 StringMapper (org.jumpmind.db.sql.mapper.StringMapper)1