use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method containsExactMatchForSourceTableName.
private boolean containsExactMatchForSourceTableName(Table table, List<Trigger> triggers, boolean ignoreCase) {
for (Trigger trigger : triggers) {
String sourceCatalogName = trigger.getSourceCatalogName() != null ? trigger.getSourceCatalogName() : platform.getDefaultCatalog();
String sourceSchemaName = trigger.getSourceSchemaName() != null ? trigger.getSourceSchemaName() : platform.getDefaultSchema();
if (trigger.getSourceTableName().equals(table.getName()) && (sourceCatalogName == null || sourceCatalogName.equals(table.getCatalog())) && (sourceSchemaName == null || sourceSchemaName.equals(table.getSchema()))) {
return true;
} else if (ignoreCase && trigger.getSourceTableName().equalsIgnoreCase(table.getName()) && (sourceCatalogName == null || sourceCatalogName.equalsIgnoreCase(table.getCatalog())) && (sourceSchemaName == null || sourceSchemaName.equalsIgnoreCase(table.getSchema()))) {
return true;
}
}
return false;
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method syncTrigger.
public void syncTrigger(Trigger trigger, ITriggerCreationListener listener, boolean force, boolean verifyInDatabase) {
StringBuilder sqlBuffer = new StringBuilder();
clearCache();
List<Trigger> triggersForCurrentNode = null;
if (verifyInDatabase) {
triggersForCurrentNode = getTriggersForCurrentNode();
} else {
triggersForCurrentNode = new ArrayList<Trigger>();
triggersForCurrentNode.add(trigger);
}
try {
if (listener != null) {
extensionService.addExtensionPoint(listener);
}
List<TriggerHistory> allHistories = getActiveTriggerHistories();
if (triggersForCurrentNode.contains(trigger)) {
if (!trigger.isSourceTableNameWildCarded()) {
for (TriggerHistory triggerHistory : getActiveTriggerHistories(trigger)) {
if (!triggerHistory.getFullyQualifiedSourceTableName().equals(trigger.getFullyQualifiedSourceTableName())) {
dropTriggers(triggerHistory, sqlBuffer);
}
}
}
updateOrCreateDatabaseTrigger(trigger, triggersForCurrentNode, sqlBuffer, force, verifyInDatabase, allHistories, false);
} else {
for (TriggerHistory triggerHistory : getActiveTriggerHistories(trigger)) {
dropTriggers(triggerHistory, sqlBuffer);
}
}
} finally {
if (listener != null) {
extensionService.removeExtensionPoint(listener);
}
}
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method getTriggerById.
public Trigger getTriggerById(String triggerId, boolean refreshCache) {
Trigger trigger = null;
final long triggerCacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_TRIGGER_ROUTER_IN_MS);
Map<String, Trigger> cache = this.triggersCache;
if (cache == null || !cache.containsKey(triggerId) || refreshCache || (System.currentTimeMillis() - this.triggersCacheTime) > triggerCacheTimeoutInMs) {
synchronized (cacheLock) {
this.triggersCacheTime = System.currentTimeMillis();
List<Trigger> triggers = new ArrayList<Trigger>(getTriggers());
triggers.addAll(buildTriggersForSymmetricTables(Version.version()));
cache = new HashMap<String, Trigger>(triggers.size());
for (Trigger t : triggers) {
cache.put(t.getTriggerId(), t);
}
this.triggersCache = cache;
}
}
trigger = cache.get(triggerId);
if (trigger == null && !refreshCache) {
trigger = getTriggerById(triggerId, true);
}
return trigger;
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method buildTriggersForSymmetricTables.
protected List<Trigger> buildTriggersForSymmetricTables(String version, String... tablesToExclude) {
List<Trigger> triggers = new ArrayList<Trigger>();
List<String> tables = new ArrayList<String>(TableConstants.getConfigTables(symmetricDialect.getTablePrefix()));
if (extraConfigTables != null) {
for (String extraTable : extraConfigTables) {
tables.add(extraTable);
}
}
List<Trigger> definedTriggers = getTriggers();
for (Trigger trigger : definedTriggers) {
if (tables.remove(trigger.getSourceTableName())) {
logOnce(String.format("Not generating virtual triggers for %s because there is a user defined trigger already defined", trigger.getSourceTableName()));
}
}
if (tablesToExclude != null) {
for (String tableToExclude : tablesToExclude) {
String tablename = TableConstants.getTableName(tablePrefix, tableToExclude);
if (!tables.remove(tablename)) {
if (!tables.remove(tablename.toUpperCase())) {
tables.remove(tablename.toLowerCase());
}
}
}
}
for (String tableName : tables) {
Trigger trigger = buildTriggerForSymmetricTable(tableName);
triggers.add(trigger);
}
return triggers;
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method findMatchingTriggers.
public Collection<Trigger> findMatchingTriggers(List<Trigger> triggers, String catalog, String schema, String table) {
Set<Trigger> matches = new HashSet<Trigger>();
for (Trigger trigger : triggers) {
boolean catalogMatches = trigger.isSourceCatalogNameWildCarded() || (catalog == null && trigger.getSourceCatalogName() == null) || (StringUtils.isBlank(trigger.getSourceCatalogName()) && StringUtils.isNotBlank(catalog) && catalog.equals(platform.getDefaultCatalog())) || (StringUtils.isNotBlank(catalog) && catalog.equals(trigger.getSourceCatalogName()));
boolean schemaMatches = trigger.isSourceSchemaNameWildCarded() || (schema == null && trigger.getSourceSchemaName() == null) || (StringUtils.isBlank(trigger.getSourceSchemaName()) && StringUtils.isNotBlank(schema) && schema.equals(platform.getDefaultSchema())) || (StringUtils.isNotBlank(schema) && schema.equals(trigger.getSourceSchemaName()));
boolean tableMatches = trigger.isSourceTableNameWildCarded() || table.equalsIgnoreCase(trigger.getSourceTableName());
if (catalogMatches && schemaMatches && tableMatches) {
matches.add(trigger);
}
}
return matches;
}
Aggregations