Search in sources :

Example 46 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method fillTriggerRoutersByHistId.

public Map<Integer, List<TriggerRouter>> fillTriggerRoutersByHistId(String sourceNodeGroupId, String targetNodeGroupId, List<TriggerHistory> triggerHistories) {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>(getAllTriggerRoutersForReloadForCurrentNode(sourceNodeGroupId, targetNodeGroupId));
    Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = new HashMap<Integer, List<TriggerRouter>>(triggerHistories.size());
    for (TriggerHistory triggerHistory : triggerHistories) {
        List<TriggerRouter> triggerRoutersForTriggerHistory = new ArrayList<TriggerRouter>();
        triggerRoutersByHistoryId.put(triggerHistory.getTriggerHistoryId(), triggerRoutersForTriggerHistory);
        String triggerId = triggerHistory.getTriggerId();
        for (TriggerRouter triggerRouter : triggerRouters) {
            if (triggerRouter.getTrigger().getTriggerId().equals(triggerId)) {
                triggerRoutersForTriggerHistory.add(triggerRouter);
            }
        }
    }
    return triggerRoutersByHistoryId;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 47 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method findTriggerRouterById.

public TriggerRouter findTriggerRouterById(String triggerId, String routerId, boolean refreshCache) {
    List<TriggerRouter> configs = (List<TriggerRouter>) sqlTemplate.query(getTriggerRouterSql("selectTriggerRouterSql"), new TriggerRouterMapper(), triggerId, routerId);
    if (configs.size() > 0) {
        TriggerRouter triggerRouter = configs.get(0);
        triggerRouter.setRouter(getRouterById(triggerRouter.getRouter().getRouterId(), refreshCache));
        triggerRouter.setTrigger(getTriggerById(triggerRouter.getTrigger().getTriggerId(), refreshCache));
        return triggerRouter;
    } else {
        return null;
    }
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 48 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method getConfigurationTablesTriggerRoutersForCurrentNode.

/**
     * Create a list of {@link TriggerRouter} for the SymmetricDS tables that
     * should have triggers created for them on the current node.
     */
protected List<TriggerRouter> getConfigurationTablesTriggerRoutersForCurrentNode(String sourceNodeGroupId) {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    List<NodeGroupLink> links = configurationService.getNodeGroupLinksFor(sourceNodeGroupId, false);
    for (NodeGroupLink nodeGroupLink : links) {
        triggerRouters.addAll(buildTriggerRoutersForSymmetricTables(Version.version(), nodeGroupLink));
    }
    return triggerRouters;
}
Also used : ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink)

Example 49 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method getTriggerRouterForTableForCurrentNode.

public Set<TriggerRouter> getTriggerRouterForTableForCurrentNode(NodeGroupLink link, String catalogName, String schemaName, String tableName, boolean refreshCache) {
    TriggerRoutersCache cache = getTriggerRoutersCacheForCurrentNode(refreshCache);
    Collection<List<TriggerRouter>> triggerRouters = cache.triggerRoutersByTriggerId.values();
    HashSet<TriggerRouter> returnList = new HashSet<TriggerRouter>();
    for (List<TriggerRouter> list : triggerRouters) {
        for (TriggerRouter triggerRouter : list) {
            if (isMatch(link, triggerRouter) && isMatch(catalogName, schemaName, tableName, triggerRouter.getTrigger())) {
                returnList.add(triggerRouter);
            }
        }
    }
    return returnList;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 50 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method fillTriggerRoutersByHistIdAndSortHist.

public Map<Integer, List<TriggerRouter>> fillTriggerRoutersByHistIdAndSortHist(String sourceNodeGroupId, String targetNodeGroupId, List<TriggerHistory> triggerHistories) {
    final Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = fillTriggerRoutersByHistId(sourceNodeGroupId, targetNodeGroupId, triggerHistories);
    final List<Table> sortedTables = getSortedTablesFor(triggerHistories);
    Comparator<TriggerHistory> comparator = new Comparator<TriggerHistory>() {

        public int compare(TriggerHistory o1, TriggerHistory o2) {
            List<TriggerRouter> triggerRoutersForTriggerHist1 = triggerRoutersByHistoryId.get(o1.getTriggerHistoryId());
            int intialLoadOrder1 = 0;
            for (TriggerRouter triggerRouter1 : triggerRoutersForTriggerHist1) {
                if (triggerRouter1.getInitialLoadOrder() > intialLoadOrder1) {
                    intialLoadOrder1 = triggerRouter1.getInitialLoadOrder();
                }
            }
            List<TriggerRouter> triggerRoutersForTriggerHist2 = triggerRoutersByHistoryId.get(o2.getTriggerHistoryId());
            int intialLoadOrder2 = 0;
            for (TriggerRouter triggerRouter2 : triggerRoutersForTriggerHist2) {
                if (triggerRouter2.getInitialLoadOrder() > intialLoadOrder2) {
                    intialLoadOrder2 = triggerRouter2.getInitialLoadOrder();
                }
            }
            if (intialLoadOrder1 < intialLoadOrder2) {
                return -1;
            } else if (intialLoadOrder1 > intialLoadOrder2) {
                return 1;
            }
            Table table1 = platform.getTableFromCache(o1.getSourceCatalogName(), o1.getSourceSchemaName(), o1.getSourceTableName(), false);
            Table table2 = platform.getTableFromCache(o2.getSourceCatalogName(), o2.getSourceSchemaName(), o2.getSourceTableName(), false);
            return new Integer(sortedTables.indexOf(table1)).compareTo(new Integer(sortedTables.indexOf(table2)));
        }

        ;
    };
    Collections.sort(triggerHistories, comparator);
    return triggerRoutersByHistoryId;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Table(org.jumpmind.db.model.Table) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Aggregations

TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)64 ArrayList (java.util.ArrayList)22 Trigger (org.jumpmind.symmetric.model.Trigger)20 Router (org.jumpmind.symmetric.model.Router)18 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)12 Test (org.junit.Test)12 List (java.util.List)10 Node (org.jumpmind.symmetric.model.Node)8 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)7 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)7 Table (org.jumpmind.db.model.Table)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Data (org.jumpmind.symmetric.model.Data)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 ConfigurationChangedDataRouter (org.jumpmind.symmetric.route.ConfigurationChangedDataRouter)4 FileSyncDataRouter (org.jumpmind.symmetric.route.FileSyncDataRouter)4