Skip to content

Commit

Permalink
0002519 DB2 dialect to provide source node id as part of change data
Browse files Browse the repository at this point in the history
capture
  • Loading branch information
Hicks, Josh committed Mar 8, 2016
1 parent b5b2c00 commit 93bedbc
Showing 1 changed file with 26 additions and 3 deletions.
Expand Up @@ -34,6 +34,11 @@
*/
public class Db2SymmetricDialect extends AbstractSymmetricDialect implements ISymmetricDialect {

// DB2 Variables
public static final String VAR_SOURCE_NODE_ID = "_source_node_id";
public static final String VAR_TRIGGER_DISABLED = "_trigger_disabled";


public Db2SymmetricDialect(IParameterService parameterService, IDatabasePlatform platform) {
super(parameterService, platform);
this.triggerTemplate = new Db2TriggerTemplate(this);
Expand Down Expand Up @@ -77,7 +82,21 @@ protected String getSystemSchemaName() {
}

@Override
public void createRequiredDatabaseObjects() {
public void createRequiredDatabaseObjects() {
try {
String sql = "select " + getSourceNodeExpression() + " from " + parameterService.getTablePrefix() + "_node_identity";
platform.getSqlTemplate().query(sql);
}
catch (Exception e) {
platform.getSqlTemplate().update("create variable " + getSourceNodeExpression() + " varchar(50)");
}
try {
String sql = "select " + parameterService.getTablePrefix() + VAR_TRIGGER_DISABLED + " from " + parameterService.getTablePrefix() + "_node_identity";
platform.getSqlTemplate().query(sql);
}
catch (Exception e) {
platform.getSqlTemplate().update("create variable " + parameterService.getTablePrefix() + VAR_TRIGGER_DISABLED + " varchar(50)");
}
}

@Override
Expand All @@ -103,10 +122,14 @@ public void enableSyncTriggers(ISqlTransaction transaction) {
}

public void disableSyncTriggers(ISqlTransaction transaction, String nodeId) {
transaction.prepareAndExecute("set " + parameterService.getTablePrefix() + VAR_TRIGGER_DISABLED + " = 1");
if (nodeId != null) {
transaction.prepareAndExecute("set " + getSourceNodeExpression() + " = '" + nodeId + "'");
}
}

public String getSyncTriggersExpression() {
return "1=1";
return parameterService.getTablePrefix() + VAR_TRIGGER_DISABLED + " is null";
}

@Override
Expand Down Expand Up @@ -135,6 +158,6 @@ protected String getDbSpecificDataHasChangedCondition(Trigger trigger) {

@Override
public String getSourceNodeExpression() {
return "null";
return parameterService.getTablePrefix() + VAR_SOURCE_NODE_ID;
}
}

0 comments on commit 93bedbc

Please sign in to comment.