use of org.jumpmind.db.sql.mapper.StringMapper 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;
}
use of org.jumpmind.db.sql.mapper.StringMapper in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test06InitialLoadSql.
@Test
public void test06InitialLoadSql() throws Exception {
ITriggerRouterService triggerRouterService = getTriggerRouterService();
IParameterService parameterService = getParameterService();
parameterService.saveParameter(ParameterConstants.INITIAL_LOAD_CONCAT_CSV_IN_SQL_ENABLED, true, "unittest");
TriggerRouter triggerRouter = triggerRouterService.getTriggerRouterForTableForCurrentNode(true, null, null, TEST_TRIGGERS_TABLE, true).iterator().next();
Table table = getDbDialect().getPlatform().getTableFromCache(triggerRouter.getTrigger().getSourceTableName(), true);
Trigger trigger = triggerRouter.getTrigger();
String sql = getDbDialect().createInitialLoadSqlFor(new Node("1", null, "1.0"), triggerRouter, table, triggerRouterService.getNewestTriggerHistoryForTrigger(trigger.getTriggerId(), trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), trigger.getSourceTableName()), getConfigurationService().getChannel(triggerRouter.getTrigger().getChannelId()), null);
List<String> csvStrings = getSqlTemplate().query(sql, new StringMapper());
assertTrue(csvStrings.size() > 0);
String csvString = csvStrings.get(0);
// DB2 captures decimal differently
csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
// Informix captures decimal differently
csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
// ASA captures decimal differently
csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
assertTrue(csvString.endsWith(EXPECTED_INSERT1_CSV_ENDSWITH), "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT1_CSV_ENDSWITH);
}
Aggregations