Search in sources :

Example 1 with Grouplet

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

the class AbstractSymmetricEngine method uninstall.

public synchronized void uninstall() {
    log.warn("Attempting an uninstall of all SymmetricDS database objects from the database");
    stop();
    log.info("Just cleaned {} files in the staging area during the uninstall.", getStagingManager().clean(0));
    try {
        Table table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_TRIGGER_ROUTER));
        if (table != null) {
            List<Grouplet> grouplets = groupletService.getGrouplets(true);
            for (Grouplet grouplet : grouplets) {
                groupletService.deleteGrouplet(grouplet);
            }
            List<TriggerRouter> triggerRouters = triggerRouterService.getTriggerRouters(false, true);
            for (TriggerRouter triggerRouter : triggerRouters) {
                triggerRouterService.deleteTriggerRouter(triggerRouter);
            }
            List<FileTriggerRouter> fileTriggerRouters = fileSyncService.getFileTriggerRouters();
            for (FileTriggerRouter fileTriggerRouter : fileTriggerRouters) {
                fileSyncService.deleteFileTriggerRouter(fileTriggerRouter);
            }
            List<Router> routers = triggerRouterService.getRouters(true);
            for (Router router : routers) {
                triggerRouterService.deleteRouter(router);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_CONFLICT));
        if (table != null) {
            // need to remove all conflicts before we can remove the node
            // group links
            List<ConflictNodeGroupLink> conflicts = dataLoaderService.getConflictSettingsNodeGroupLinks();
            for (ConflictNodeGroupLink conflict : conflicts) {
                dataLoaderService.delete(conflict);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_TRANSFORM_TABLE));
        if (table != null) {
            // need to remove all transforms before we can remove the node
            // group links
            List<TransformTableNodeGroupLink> transforms = transformService.getTransformTables(false);
            for (TransformTableNodeGroupLink transformTable : transforms) {
                transformService.deleteTransformTable(transformTable.getTransformId());
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_ROUTER));
        if (table != null) {
            List<Router> objects = triggerRouterService.getRouters(true);
            for (Router router : objects) {
                triggerRouterService.deleteRouter(router);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_CONFLICT));
        if (table != null) {
            List<ConflictNodeGroupLink> objects = dataLoaderService.getConflictSettingsNodeGroupLinks();
            for (ConflictNodeGroupLink obj : objects) {
                dataLoaderService.delete(obj);
            }
        }
        table = platform.readTableFromDatabase(null, null, TableConstants.getTableName(parameterService.getTablePrefix(), TableConstants.SYM_NODE_GROUP_LINK));
        if (table != null) {
            // remove the links so the symmetric table trigger will be
            // removed
            List<NodeGroupLink> links = configurationService.getNodeGroupLinks(false);
            for (NodeGroupLink nodeGroupLink : links) {
                configurationService.deleteNodeGroupLink(nodeGroupLink);
            }
        }
        if (table != null) {
            // this should remove all triggers because we have removed all the
            // trigger configuration
            triggerRouterService.syncTriggers();
        }
    } catch (SqlException ex) {
        log.warn("Error while trying remove triggers on tables", ex);
    }
    // remove any additional triggers that may remain because they were not in trigger history
    symmetricDialect.cleanupTriggers();
    symmetricDialect.dropTablesAndDatabaseObjects();
    // force cache to be cleared
    nodeService.deleteIdentity();
    parameterService.setDatabaseHasBeenInitialized(false);
    log.warn("Finished uninstalling SymmetricDS database objects from the database");
}
Also used : Table(org.jumpmind.db.model.Table) ConflictNodeGroupLink(org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink) SqlException(org.jumpmind.db.sql.SqlException) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) Grouplet(org.jumpmind.symmetric.model.Grouplet) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) FileTriggerRouter(org.jumpmind.symmetric.model.FileTriggerRouter) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink) ConflictNodeGroupLink(org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink) NodeGroupLink(org.jumpmind.symmetric.model.NodeGroupLink) TransformTableNodeGroupLink(org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)

Example 2 with Grouplet

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

the class GroupletService method getGrouplets.

public List<Grouplet> getGrouplets(boolean refreshCache) {
    long maxCacheTime = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_GROUPLETS_IN_MS);
    List<Grouplet> all = cache;
    if (all == null || System.currentTimeMillis() - lastCacheTime >= maxCacheTime || lastCacheTime == 0 || refreshCache) {
        ISqlTemplate sqlTemplate = platform.getSqlTemplate();
        final Map<String, Grouplet> groupletMap = new HashMap<String, Grouplet>();
        all = sqlTemplate.query(getSql("selectGroupletSql"), new ISqlRowMapper<Grouplet>() {

            public Grouplet mapRow(Row rs) {
                Grouplet grouplet = new Grouplet();
                grouplet.setGroupletId(rs.getString("grouplet_id"));
                grouplet.setDescription(rs.getString("description"));
                grouplet.setGroupletLinkPolicy(GroupletLinkPolicy.valueOf(rs.getString("grouplet_link_policy")));
                grouplet.setCreateTime(rs.getDateTime("create_time"));
                grouplet.setLastUpdateBy(rs.getString("last_update_by"));
                grouplet.setLastUpdateTime(rs.getDateTime("last_update_time"));
                groupletMap.put(grouplet.getGroupletId(), grouplet);
                return grouplet;
            }
        });
        sqlTemplate.query(getSql("selectGroupletLinkSql"), new ISqlRowMapper<GroupletLink>() {

            public GroupletLink mapRow(Row rs) {
                GroupletLink groupletLink = new GroupletLink();
                String groupletId = rs.getString("grouplet_id");
                Grouplet grouplet = groupletMap.get(groupletId);
                groupletLink.setExternalId(rs.getString("external_id"));
                groupletLink.setCreateTime(rs.getDateTime("create_time"));
                groupletLink.setLastUpdateBy(rs.getString("last_update_by"));
                groupletLink.setLastUpdateTime(rs.getDateTime("last_update_time"));
                if (grouplet != null) {
                    grouplet.getGroupletLinks().add(groupletLink);
                }
                return groupletLink;
            }
        });
        sqlTemplate.query(getSql("selectTriggerRouterGroupletSql"), new ISqlRowMapper<TriggerRouterGrouplet>() {

            public TriggerRouterGrouplet mapRow(Row rs) {
                TriggerRouterGrouplet trGrouplet = new TriggerRouterGrouplet();
                String groupletId = rs.getString("grouplet_id");
                Grouplet grouplet = groupletMap.get(groupletId);
                trGrouplet.setAppliesWhen(AppliesWhen.valueOf(rs.getString("applies_when")));
                trGrouplet.setRouterId(rs.getString("router_id"));
                trGrouplet.setTriggerId(rs.getString("trigger_id"));
                trGrouplet.setCreateTime(rs.getDateTime("create_time"));
                trGrouplet.setLastUpdateBy(rs.getString("last_update_by"));
                trGrouplet.setLastUpdateTime(rs.getDateTime("last_update_time"));
                if (grouplet != null) {
                    grouplet.getTriggerRouterGrouplets().add(trGrouplet);
                }
                return trGrouplet;
            }
        });
        cache = all;
        lastCacheTime = System.currentTimeMillis();
    }
    return all;
}
Also used : HashMap(java.util.HashMap) TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) GroupletLink(org.jumpmind.symmetric.model.GroupletLink) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Example 3 with Grouplet

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

the class GroupletService method getGroupletsFor.

protected List<Grouplet> getGroupletsFor(TriggerRouter triggerRouter, AppliesWhen appliesWhen, boolean refreshCache) {
    List<Grouplet> all = getGrouplets(refreshCache);
    List<Grouplet> grouplets = new ArrayList<Grouplet>();
    for (Grouplet grouplet : all) {
        List<TriggerRouterGrouplet> trGrouplets = grouplet.getTriggerRouterGrouplets();
        for (TriggerRouterGrouplet trGrouplet : trGrouplets) {
            if (trGrouplet.getTriggerId().equals(triggerRouter.getTrigger().getTriggerId()) && trGrouplet.getRouterId().equals(triggerRouter.getRouter().getRouterId()) && (trGrouplet.getAppliesWhen() == appliesWhen || trGrouplet.getAppliesWhen() == AppliesWhen.B)) {
                grouplets.add(grouplet);
            }
        }
    }
    return grouplets;
}
Also used : TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) ArrayList(java.util.ArrayList)

Example 4 with Grouplet

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

the class GroupletService method isSourceEnabled.

public boolean isSourceEnabled(TriggerRouter triggerRouter) {
    boolean enabled = true;
    Node node = engine.getNodeService().findIdentity();
    if (node == null) {
        enabled = false;
    } else {
        List<Grouplet> grouplets = getGroupletsFor(triggerRouter, AppliesWhen.S, false);
        if (grouplets != null && grouplets.size() > 0) {
            enabled = false;
            for (Grouplet grouplet : grouplets) {
                GroupletLinkPolicy policy = grouplet.getGroupletLinkPolicy();
                List<GroupletLink> links = grouplet.getGroupletLinks();
                boolean foundMatch = false;
                for (GroupletLink groupletLink : links) {
                    if (groupletLink.getExternalId().equals(node.getExternalId())) {
                        foundMatch = true;
                    }
                }
                if ((foundMatch && policy == GroupletLinkPolicy.I) || (!foundMatch && policy == GroupletLinkPolicy.E)) {
                    enabled = true;
                }
            }
        }
    }
    return enabled;
}
Also used : TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) GroupletLink(org.jumpmind.symmetric.model.GroupletLink) Node(org.jumpmind.symmetric.model.Node) GroupletLinkPolicy(org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy)

Example 5 with Grouplet

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

the class GroupletService method getTargetEnabled.

public Set<Node> getTargetEnabled(TriggerRouter triggerRouter, Set<Node> nodes) {
    Set<Node> matchedNodes = new HashSet<Node>();
    Set<Node> excludedNodes = new HashSet<Node>();
    List<Grouplet> grouplets = getGroupletsFor(triggerRouter, AppliesWhen.T, false);
    if (grouplets != null && grouplets.size() > 0) {
        for (Grouplet grouplet : grouplets) {
            GroupletLinkPolicy policy = grouplet.getGroupletLinkPolicy();
            List<GroupletLink> links = grouplet.getGroupletLinks();
            for (GroupletLink groupletLink : links) {
                for (Node node : nodes) {
                    if (groupletLink.getExternalId().equals(node.getExternalId())) {
                        if (policy == GroupletLinkPolicy.I) {
                            matchedNodes.add(node);
                        } else {
                            excludedNodes.add(node);
                        }
                    }
                }
            }
        }
        Set<Node> toReturn = new HashSet<Node>();
        excludedNodes.removeAll(matchedNodes);
        if (excludedNodes.size() > 0) {
            toReturn.addAll(nodes);
            toReturn.removeAll(excludedNodes);
        } else {
            toReturn.addAll(matchedNodes);
        }
        return toReturn;
    } else {
        return nodes;
    }
}
Also used : TriggerRouterGrouplet(org.jumpmind.symmetric.model.TriggerRouterGrouplet) Grouplet(org.jumpmind.symmetric.model.Grouplet) GroupletLink(org.jumpmind.symmetric.model.GroupletLink) Node(org.jumpmind.symmetric.model.Node) GroupletLinkPolicy(org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy) HashSet(java.util.HashSet)

Aggregations

Grouplet (org.jumpmind.symmetric.model.Grouplet)5 TriggerRouterGrouplet (org.jumpmind.symmetric.model.TriggerRouterGrouplet)4 GroupletLink (org.jumpmind.symmetric.model.GroupletLink)3 GroupletLinkPolicy (org.jumpmind.symmetric.model.Grouplet.GroupletLinkPolicy)2 Node (org.jumpmind.symmetric.model.Node)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Table (org.jumpmind.db.model.Table)1 ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)1 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)1 Row (org.jumpmind.db.sql.Row)1 SqlException (org.jumpmind.db.sql.SqlException)1 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)1 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)1 Router (org.jumpmind.symmetric.model.Router)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 ConflictNodeGroupLink (org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink)1 TransformTableNodeGroupLink (org.jumpmind.symmetric.service.impl.TransformService.TransformTableNodeGroupLink)1