Skip to content

Commit

Permalink
Force the creation of the triggers (associated with the -t option, wr…
Browse files Browse the repository at this point in the history
…iting the trigger DDL to a file).
  • Loading branch information
pmarzullo64 committed May 18, 2009
1 parent eec04a2 commit 6b1d36b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
Expand Up @@ -86,6 +86,8 @@ public class SymmetricLauncher {
private static final String OPTION_DDL_GEN = "generate-config-dll";

private static final String OPTION_TRIGGER_GEN = "generate-triggers";

private static final String OPTION_TRIGGER_GEN_ALWAYS = "generate-triggers-always";

private static final String OPTION_PURGE = "purge";

Expand Down Expand Up @@ -192,7 +194,8 @@ public static void main(String[] args) throws Exception {

if (line.hasOption(OPTION_TRIGGER_GEN)) {
String arg = line.getOptionValue(OPTION_TRIGGER_GEN);
syncTrigger(new SymmetricEngine(), arg);
boolean gen_always = line.hasOption(OPTION_TRIGGER_GEN_ALWAYS);
syncTrigger(new SymmetricEngine(), arg, gen_always);
return;
}

Expand Down Expand Up @@ -353,6 +356,7 @@ private static Options buildOptions() {
false,
"Don't test to see if the database connection is valid before starting the server. Note that if the connection is invalid, then the server will continually try to connect if this is set.");
options.addOption("t", OPTION_TRIGGER_GEN, true, "Run the sync triggers process and write the output the specified file. If triggers should not be applied automatically then set the auto.sync.triggers property to false");
options.addOption("o", OPTION_TRIGGER_GEN_ALWAYS, false, "Run the sync triggers process even if the triggers already exist.");
return options;
}

Expand Down Expand Up @@ -406,15 +410,15 @@ private static String reloadNode(SymmetricEngine engine, String argument) {
}


private static void syncTrigger(SymmetricEngine engine, String fileName) throws IOException {
private static void syncTrigger(SymmetricEngine engine, String fileName, boolean gen_always) throws IOException {
if (fileName != null) {
File file = new File(fileName);
if (file.getParentFile() != null) {
file.getParentFile().mkdirs();
}
IBootstrapService bootstrapService = AppUtils.find(Constants.BOOTSTRAP_SERVICE, engine);
StringBuilder sqlBuffer = new StringBuilder();
bootstrapService.syncTriggers(sqlBuffer);
bootstrapService.syncTriggers(sqlBuffer, gen_always);
FileUtils.writeStringToFile(file, sqlBuffer.toString(), null);
} else {
throw new IllegalStateException("Please provide a file name to write the trigger SQL to");
Expand Down
Expand Up @@ -45,7 +45,7 @@ public interface IBootstrapService {
/**
* Synchronize the triggers and write the DDL to the SQL buffer.
*/
public void syncTriggers(StringBuilder sql);
public void syncTriggers(StringBuilder sql, boolean gen_always);

@Deprecated
public void register();
Expand Down
Expand Up @@ -154,15 +154,15 @@ public void setupDatabase(boolean force) {
}

public void syncTriggers() {
syncTriggers(null);
syncTriggers(null, false);
}

synchronized public void syncTriggers(StringBuilder sqlBuffer) {
synchronized public void syncTriggers(StringBuilder sqlBuffer, boolean gen_always) {
if (clusterService.lock(LockActionConstants.SYNCTRIGGERS)) {
try {
logger.info("Synchronizing triggers");
removeInactiveTriggers(sqlBuffer);
updateOrCreateSymmetricTriggers(sqlBuffer);
updateOrCreateSymmetricTriggers(sqlBuffer, gen_always);
} finally {
clusterService.unlock(LockActionConstants.SYNCTRIGGERS);
logger.info("Done synchronizing triggers");
Expand Down Expand Up @@ -230,7 +230,7 @@ public Map<Integer, Trigger> getCachedTriggers(boolean refreshCache) {
return triggerCache;
}

private void updateOrCreateSymmetricTriggers(StringBuilder sqlBuffer) {
private void updateOrCreateSymmetricTriggers(StringBuilder sqlBuffer, boolean gen_always) {
Collection<Trigger> triggers = getCachedTriggers(true).values();

for (Trigger trigger : triggers) {
Expand Down Expand Up @@ -263,6 +263,9 @@ private void updateOrCreateSymmetricTriggers(StringBuilder sqlBuffer) {
|| trigger.getHashedValue() != latestHistoryBeforeRebuild.getTriggerRowHash()) {
reason = TriggerReBuildReason.TABLE_SYNC_CONFIGURATION_CHANGED;
forceRebuildOfTriggers = true;
} else if(gen_always) {
reason = TriggerReBuildReason.FORCED;
forceRebuildOfTriggers = true;
}

TriggerHistory newestHistory = rebuildTriggerIfNecessary(sqlBuffer, forceRebuildOfTriggers,
Expand Down
6 changes: 3 additions & 3 deletions symmetric/src/main/resources/dialects/db2-zseries.xml
Expand Up @@ -84,7 +84,7 @@
SELECT node_id, IDENTITY_VAL_LOCAL(), '$(channelName)',
$(txIdExpression) from $(prefixName)_node c
where (c.node_group_id = '$(targetGroupId)' and c.sync_enabled = 1) $(nodeSelectWhere);
END
END;
]]>
</value>
</entry>
Expand All @@ -109,7 +109,7 @@
SELECT node_id, IDENTITY_VAL_LOCAL(), '$(channelName)',
$(txIdExpression) from $(prefixName)_node c
where (c.node_group_id = '$(targetGroupId)' and c.sync_enabled = 1) $(nodeSelectWhere);
END
END;
]]>
</value>
</entry>
Expand All @@ -132,7 +132,7 @@
SELECT node_id, IDENTITY_VAL_LOCAL(), '$(channelName)',
$(txIdExpression) from $(prefixName)_node c
where (c.node_group_id = '$(targetGroupId)' and c.sync_enabled = 1) $(nodeSelectWhere);
END
END;
]]>
</value>
</entry>
Expand Down

0 comments on commit 6b1d36b

Please sign in to comment.