Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0003145: Allow $(schemaName) variable in channel expression
  • Loading branch information
erilong committed Jun 8, 2017
1 parent d3b8f43 commit cece499
Showing 1 changed file with 25 additions and 4 deletions.
Expand Up @@ -266,6 +266,15 @@ protected String getSourceTablePrefix(Table table) {
return prefix;
}

protected String getSourceTableSchema(Table table) {
String prefix = (isNotBlank(table.getSchema()) ? table.getSchema() : "");
if (isBlank(prefix)) {
prefix = (isNotBlank(symmetricDialect.getPlatform().getDefaultSchema()) ?
symmetricDialect.getPlatform().getDefaultSchema() : "");
}
return prefix;
}

protected String getSourceTablePrefix(TriggerHistory triggerHistory) {
String prefix = (isNotBlank(triggerHistory.getSourceSchemaName()) ? SymmetricUtils.quote(
symmetricDialect, triggerHistory.getSourceSchemaName()) + symmetricDialect.getPlatform().getDatabaseInfo().getSchemaSeparator() : "");
Expand All @@ -283,6 +292,15 @@ protected String getSourceTablePrefix(TriggerHistory triggerHistory) {
return prefix;
}

protected String getSourceTableSchema(TriggerHistory triggerHistory) {
String prefix = (isNotBlank(triggerHistory.getSourceSchemaName()) ? triggerHistory.getSourceSchemaName() : "");
if (isBlank(prefix)) {
prefix = (isNotBlank(symmetricDialect.getPlatform().getDefaultSchema()) ?
symmetricDialect.getPlatform().getDefaultSchema() : "");
}
return prefix;
}

protected String replaceDefaultSchemaAndCatalog(String sql) {
String defaultCatalog = symmetricDialect.getPlatform().getDefaultCatalog();
String defaultSchema = symmetricDialect.getPlatform().getDefaultSchema();
Expand Down Expand Up @@ -432,8 +450,8 @@ protected String replaceTemplateVariables(DataEventType dml, Trigger trigger,
ddl = FormatUtils.replace("txIdExpression",
symmetricDialect.preProcessTriggerSqlClause(triggerExpression), ddl);

ddl = FormatUtils.replace("channelExpression", symmetricDialect.preProcessTriggerSqlClause(getChannelExpression(trigger)),
ddl);
ddl = FormatUtils.replace("channelExpression", symmetricDialect.preProcessTriggerSqlClause(
getChannelExpression(trigger, history, originalTable)), ddl);

ddl = FormatUtils.replace("externalSelect", (trigger.getExternalSelect() == null ? "null"
: "(" + symmetricDialect.preProcessTriggerSqlClause(trigger.getExternalSelect())
Expand Down Expand Up @@ -583,10 +601,13 @@ protected String toClobExpression(Table table) {
}
}

protected String getChannelExpression(Trigger trigger) {
protected String getChannelExpression(Trigger trigger, TriggerHistory history, Table originalTable) {
if (trigger.getChannelId().equals(Constants.CHANNEL_DYNAMIC)) {
if (StringUtils.isNotBlank(trigger.getChannelExpression())) {
return trigger.getChannelExpression();
String expr = trigger.getChannelExpression();
expr = FormatUtils.replace("schemaName", history == null ? getSourceTableSchema(originalTable)
: getSourceTableSchema(history), expr);
return expr;
} else {
throw new IllegalStateException("When the channel is set to '" + Constants.CHANNEL_DYNAMIC + "', a channel expression must be provided.");
}
Expand Down

0 comments on commit cece499

Please sign in to comment.