Skip to content

Commit

Permalink
Issue #939 - Move substitution to database writer on the target
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilmer committed Dec 5, 2012
1 parent 8319b10 commit ec649a6
Showing 1 changed file with 6 additions and 26 deletions.
Expand Up @@ -205,39 +205,17 @@ public String createInitialLoadSqlFor(Node node, TriggerRouter trigger, Table ta

public String createPurgeSqlFor(Node node, TriggerRouter triggerRouter, TriggerHistory triggerHistory) {

String sql=null;

String sql=null;
if (StringUtils.isEmpty(triggerRouter.getInitialLoadDeleteStmt())) {
sql = String.format(
sql = String.format(
parameterService.getString(ParameterConstants.INITIAL_LOAD_DELETE_FIRST_SQL),
formatTableName(triggerRouter.qualifiedTargetTableName(triggerHistory)));
triggerRouter.qualifiedTargetTableName(triggerHistory));
} else {
sql = triggerRouter.getInitialLoadDeleteStmt();
sql = FormatUtils.replace("groupId", node.getNodeGroupId(), sql);
sql = FormatUtils.replace("externalId", node.getExternalId(), sql);
sql = FormatUtils.replace("nodeId", node.getNodeId(), sql);
sql = FormatUtils.replace("schemaName", triggerRouter.getTargetSchema(platform.getDefaultSchema()),sql);
sql = FormatUtils.replace("catalogName", triggerRouter.getTargetCatalog(platform.getDefaultCatalog()),sql);
sql = FormatUtils.replace("tableName",
formatTableName(triggerRouter.qualifiedTargetTableName(triggerHistory)),
sql);
}
return sql;
}

private String formatTableName(String tableName) {
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform
.getDatabaseInfo().getDelimiterToken() : "";
Table table = platform.getTableFromCache(tableName, false);
if (table != null) {
return String.format("%s%s%s", quote, table.getName(), quote);
} else {
throw new RuntimeException(String.format("Could not find %s to trunate",
tableName));
}
}


public String createCsvDataSql(Trigger trigger, TriggerHistory triggerHistory, Channel channel,
String whereClause) {
return triggerTemplate.createCsvDataSql(
Expand Down Expand Up @@ -708,14 +686,16 @@ public int getRouterDataPeekAheadCount() {
}

public void truncateTable(String tableName) {
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform
.getDatabaseInfo().getDelimiterToken() : "";
boolean success = false;
int tryCount = 5;
while (!success && tryCount > 0) {
try {
Table table = platform.getTableFromCache(tableName, false);
if (table != null) {
platform.getSqlTemplate().update(
String.format("truncate table %s", formatTableName(table.getName())));
String.format("truncate table %s%s%s", quote, table.getName(), quote));
success = true;
} else {
throw new RuntimeException(String.format("Could not find %s to trunate",
Expand Down

0 comments on commit ec649a6

Please sign in to comment.