Search in sources :

Example 21 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class DataService method sendSchema.

public boolean sendSchema(String nodeId, String catalogName, String schemaName, String tableName, boolean isLoad) {
    Node sourceNode = engine.getNodeService().findIdentity();
    Node targetNode = engine.getNodeService().findNode(nodeId);
    if (targetNode == null) {
        log.error("Could not send schema to the node {}.  It does not exist", nodeId);
        return false;
    }
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    List<TriggerHistory> triggerHistories = triggerRouterService.findTriggerHistories(catalogName, schemaName, tableName);
    Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
    int eventCount = 0;
    for (TriggerHistory triggerHistory : triggerHistories) {
        List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
        for (TriggerRouter triggerRouter : triggerRouters) {
            eventCount++;
            insertCreateEvent(targetNode, triggerHistory, triggerRouter.getRouter().getRouterId(), false, -1, null);
        }
    }
    if (eventCount > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 22 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class DataService method insertReloadEvents.

public void insertReloadEvents(Node targetNode, boolean reverse) {
    if (engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS)) {
        try {
            synchronized (engine.getTriggerRouterService()) {
                engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS);
                if (!reverse) {
                    log.info("Queueing up an initial load to " + targetNode.getNodeId());
                } else {
                    log.info("Queueing up a reverse initial load to " + targetNode.getNodeId());
                }
                /*
                     * Outgoing data events are pointless because we are
                     * reloading all data
                     */
                engine.getOutgoingBatchService().markAllAsSentForNode(targetNode.getNodeId(), false);
                INodeService nodeService = engine.getNodeService();
                ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
                Node sourceNode = nodeService.findIdentity();
                boolean transactional = parameterService.is(ParameterConstants.DATA_RELOAD_IS_BATCH_INSERT_TRANSACTIONAL);
                String nodeIdRecord = reverse ? nodeService.findIdentityNodeId() : targetNode.getNodeId();
                NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeIdRecord);
                ISqlTransaction transaction = null;
                try {
                    transaction = platform.getSqlTemplate().startSqlTransaction();
                    long loadId = engine.getSequenceService().nextVal(transaction, Constants.SEQUENCE_OUTGOING_BATCH_LOAD_ID);
                    String createBy = reverse ? nodeSecurity.getRevInitialLoadCreateBy() : nodeSecurity.getInitialLoadCreateBy();
                    List<TriggerHistory> triggerHistories = triggerRouterService.getActiveTriggerHistories();
                    Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
                    callReloadListeners(true, targetNode, transactional, transaction, loadId);
                    insertCreateSchemaScriptPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction);
                    insertSqlEventsPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction, reverse);
                    insertCreateBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
                    insertDeleteBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
                    insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction);
                    String afterSql = parameterService.getString(reverse ? ParameterConstants.INITIAL_LOAD_REVERSE_AFTER_SQL : ParameterConstants.INITIAL_LOAD_AFTER_SQL);
                    if (isNotBlank(afterSql)) {
                        insertSqlEvent(transaction, targetNode, afterSql, true, loadId, createBy);
                    }
                    insertFileSyncBatchForReload(targetNode, loadId, createBy, transactional, transaction);
                    callReloadListeners(false, targetNode, transactional, transaction, loadId);
                    if (!reverse) {
                        nodeService.setInitialLoadEnabled(transaction, nodeIdRecord, false, false, loadId, createBy);
                    } else {
                        nodeService.setReverseInitialLoadEnabled(transaction, nodeIdRecord, false, false, loadId, createBy);
                    }
                    if (!Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
                        insertNodeSecurityUpdate(transaction, nodeIdRecord, targetNode.getNodeId(), true, loadId, createBy);
                    }
                    engine.getStatisticManager().incrementNodesLoaded(1);
                    transaction.commit();
                } catch (Error ex) {
                    if (transaction != null) {
                        transaction.rollback();
                    }
                    throw ex;
                } catch (RuntimeException ex) {
                    if (transaction != null) {
                        transaction.rollback();
                    }
                    throw ex;
                } finally {
                    close(transaction);
                }
                if (!reverse) {
                    /*
                         * Remove all incoming events for the node that we are
                         * starting a reload for
                         */
                    engine.getPurgeService().purgeAllIncomingEventsForNode(targetNode.getNodeId());
                }
            }
        } finally {
            engine.getClusterService().unlock(ClusterConstants.SYNCTRIGGERS);
        }
    } else {
        log.info("Not attempting to insert reload events because sync trigger is currently running");
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) Node(org.jumpmind.symmetric.model.Node) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) INodeService(org.jumpmind.symmetric.service.INodeService) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class DataService method sendSQL.

public String sendSQL(String nodeId, String catalogName, String schemaName, String tableName, String sql) {
    Node sourceNode = engine.getNodeService().findIdentity();
    Node targetNode = engine.getNodeService().findNode(nodeId);
    if (targetNode == null) {
        return "Unknown node " + nodeId;
    }
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    TriggerHistory triggerHistory = triggerRouterService.findTriggerHistory(catalogName, schemaName, tableName);
    if (triggerHistory == null) {
        return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
    } else {
        Trigger trigger = triggerRouterService.getTriggerById(true, triggerHistory.getTriggerId());
        if (trigger != null) {
            ISqlTransaction transaction = null;
            try {
                transaction = sqlTemplate.startSqlTransaction();
                insertSqlEvent(transaction, triggerHistory, trigger.getChannelId(), targetNode, sql, false, -1, null);
                transaction.commit();
                return "Successfully create SQL event for node " + targetNode.getNodeId();
            } catch (Error ex) {
                if (transaction != null) {
                    transaction.rollback();
                }
                throw ex;
            } catch (RuntimeException ex) {
                if (transaction != null) {
                    transaction.rollback();
                }
                throw ex;
            } finally {
                close(transaction);
            }
        } else {
            return "Trigger for table " + tableName + " does not exist from node " + sourceNode.getNodeGroupId();
        }
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Trigger(org.jumpmind.symmetric.model.Trigger) ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Node(org.jumpmind.symmetric.model.Node)

Example 24 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class RestService method syncTriggersImpl.

private void syncTriggersImpl(ISymmetricEngine engine, boolean force) {
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    StringBuilder buffer = new StringBuilder();
    triggerRouterService.syncTriggers(buffer, force);
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService)

Example 25 with ITriggerRouterService

use of org.jumpmind.symmetric.service.ITriggerRouterService in project symmetric-ds by JumpMind.

the class RestService method dropTriggersImpl.

private void dropTriggersImpl(ISymmetricEngine engine) {
    ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
    triggerRouterService.dropTriggers();
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService)

Aggregations

ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)27 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)12 Trigger (org.jumpmind.symmetric.model.Trigger)11 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)9 Node (org.jumpmind.symmetric.model.Node)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 Router (org.jumpmind.symmetric.model.Router)5 Table (org.jumpmind.db.model.Table)4 INodeService (org.jumpmind.symmetric.service.INodeService)4 File (java.io.File)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)3 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 IoException (org.jumpmind.exception.IoException)2