Search in sources :

Example 31 with Trigger

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;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger)

Example 32 with Trigger

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);
        }
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory)

Example 33 with Trigger

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;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList)

Example 34 with 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;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList)

Example 35 with Trigger

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;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) HashSet(java.util.HashSet)

Aggregations

Trigger (org.jumpmind.symmetric.model.Trigger)42 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)20 ArrayList (java.util.ArrayList)17 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)14 Router (org.jumpmind.symmetric.model.Router)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)11 Test (org.junit.Test)11 Date (java.util.Date)5 Table (org.jumpmind.db.model.Table)5 CsvData (org.jumpmind.symmetric.io.data.CsvData)5 Data (org.jumpmind.symmetric.model.Data)5 Node (org.jumpmind.symmetric.model.Node)5 HashSet (java.util.HashSet)4 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 INodeService (org.jumpmind.symmetric.service.INodeService)3 List (java.util.List)2