Skip to content

Commit

Permalink
Make fully qualified table name methods consistent. Also strip out sp…
Browse files Browse the repository at this point in the history
…ecial characters from trigger_ids when generating trigger names.
  • Loading branch information
chenson42 committed Sep 10, 2010
1 parent e792b5a commit 77511f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
Expand Up @@ -124,7 +124,7 @@ public String createInitalLoadSql(Node node, IDbDialect dialect, TriggerRouter t
}

public String createPurgeSql(Node node, IDbDialect dialect, TriggerRouter triggerRouter) {
return String.format("delete from %s", triggerRouter.getQualifiedTargetTableName());
return String.format("delete from %s", triggerRouter.qualifiedTargetTableName());
}

public String createCsvDataSql(IDbDialect dialect, Trigger trig, Table metaData, String whereClause) {
Expand Down
Expand Up @@ -100,7 +100,7 @@ public Trigger(String tableName) {
this.sourceTableName = tableName;
}

public String displayTableName() {
public String qualifiedSourceTableName() {
String schemaPlusTableName = (getSourceSchemaName() != null ? getSourceSchemaName()
+ "." : "")
+ getSourceTableName();
Expand Down
Expand Up @@ -172,8 +172,12 @@ public String getTargetTable() {
return null;
}
}

public String qualifiedSourceTableName() {
return trigger.qualifiedSourceTableName();
}

public String getQualifiedTargetTableName() {
public String qualifiedTargetTableName() {
String catalog = getTargetCatalog(null);
String schema = getTargetSchema(null);
String tableName = getTargetTable();
Expand Down
Expand Up @@ -237,11 +237,19 @@ public String reloadNode(String nodeId) {
}

public void insertReloadEvents(Node targetNode) {

// outgoing data events are pointless because we are reloading all data
outgoingBatchService.markAllAsSentForNode(targetNode);

if (parameterService.is(ParameterConstants.DATA_RELOAD_IS_BATCH_INSERT_TRANSACTIONAL)) {
newTransactionTemplate.execute(new TransactionalInsertReloadEventsDelegate(targetNode));
} else {
new TransactionalInsertReloadEventsDelegate(targetNode).doInTransaction(null);
}

// remove all incoming events from the node are starting a reload for.
purgeService.purgeAllIncomingEventsForNode(targetNode.getNodeId());

}

class TransactionalInsertReloadEventsDelegate implements TransactionCallback<Object> {
Expand All @@ -262,10 +270,6 @@ public Object doInTransaction(TransactionStatus status) {
}
}

// outgoing data events are pointless because we are reloading all
// data
outgoingBatchService.markAllAsSentForNode(targetNode);

// insert node security so the client doing the initial load knows
// that an initial load is currently happening
insertNodeSecurityUpdate(targetNode, true);
Expand All @@ -280,7 +284,7 @@ public Object doInTransaction(TransactionStatus status) {
Table table = dbDialect.getTable(trigger.getSourceCatalogName(), trigger
.getSourceSchemaName(), trigger.getSourceTableName(), false);
if (table == null) {
log.warn("TriggerTableMissing",trigger.displayTableName());
log.warn("TriggerTableMissing",trigger.qualifiedSourceTableName());
iterator.remove();
}
}
Expand Down Expand Up @@ -316,9 +320,6 @@ public Object doInTransaction(TransactionStatus status) {
insertNodeSecurityUpdate(targetNode,
parameterService.is(ParameterConstants.INITIAL_LOAD_USE_RELOAD_CHANNEL));

// remove all incoming events from the node are starting a reload for.
purgeService.purgeAllIncomingEventsForNode(targetNode.getNodeId());

return null;
}
}
Expand Down
Expand Up @@ -693,7 +693,7 @@ protected void updateOrCreateDatabaseTriggers(StringBuilder sqlBuffer, boolean g
}

} else {
log.error("TriggerTableMissing", trigger.displayTableName());
log.error("TriggerTableMissing", trigger.qualifiedSourceTableName());

if (this.triggerCreationListeners != null) {
for (ITriggerCreationListener l : this.triggerCreationListeners) {
Expand All @@ -702,7 +702,7 @@ protected void updateOrCreateDatabaseTriggers(StringBuilder sqlBuffer, boolean g
}
}
} catch (Exception ex) {
log.error("TriggerSynchronizingFailed", ex, trigger.displayTableName());
log.error("TriggerSynchronizingFailed", ex, trigger.qualifiedSourceTableName());
if (this.triggerCreationListeners != null) {
for (ITriggerCreationListener l : this.triggerCreationListeners) {
l.triggerFailed(trigger, ex);
Expand Down Expand Up @@ -796,12 +796,11 @@ protected String getTriggerName(DataEventType dml, int maxTriggerNameLength, Tri
break;
}

if (triggerName == null) {
if (StringUtils.isBlank(triggerName)) {
String triggerPrefix1 = tablePrefix + "_";
String triggerSuffix1 = "on_" + dml.getCode().toLowerCase() + "_for_"
+ trigger.getTriggerId();
String triggerSuffix2 = "_"
+ parameterService.getNodeGroupId().replaceAll(
String triggerSuffix1 = "on_" + dml.getCode().toLowerCase() + "_for_";
String triggerSuffix2 = (trigger.getTriggerId() + "_"
+ parameterService.getNodeGroupId()).replaceAll(
"[^a-zA-Z0-9]|[a|e|i|o|u|A|E|I|O|U]", "");
triggerName = triggerPrefix1 + triggerSuffix1 + triggerSuffix2;
// use the node group id as part of the trigger if we can because it
Expand Down

0 comments on commit 77511f2

Please sign in to comment.