Search in sources :

Example 6 with TableReloadRequest

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

the class DataService method insertDeleteBatchesForReload.

private void insertDeleteBatchesForReload(Node targetNode, long loadId, String createBy, List<TriggerHistory> triggerHistories, Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId, boolean transactional, ISqlTransaction transaction, Map<String, TableReloadRequest> reloadRequests) {
    if (reloadRequests != null && reloadRequests.size() > 0) {
        int deleteEventsSent = 0;
        for (ListIterator<TriggerHistory> triggerHistoryIterator = triggerHistories.listIterator(triggerHistories.size()); triggerHistoryIterator.hasPrevious(); ) {
            TriggerHistory triggerHistory = triggerHistoryIterator.previous();
            List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
            TableReloadRequest currentRequest = reloadRequests.get(ParameterConstants.ALL + ParameterConstants.ALL);
            boolean fullLoad = currentRequest == null ? false : true;
            for (ListIterator<TriggerRouter> iterator = triggerRouters.listIterator(triggerRouters.size()); iterator.hasPrevious(); ) {
                TriggerRouter triggerRouter = iterator.previous();
                if (!fullLoad) {
                    currentRequest = reloadRequests.get(triggerRouter.getTriggerId() + triggerRouter.getRouterId());
                }
                //Check the delete flag on the specific table reload request
                if (currentRequest != null && currentRequest.isDeleteFirst() && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
                    insertPurgeEvent(transaction, targetNode, triggerRouter, triggerHistory, true, currentRequest.getBeforeCustomSql(), loadId, createBy);
                    deleteEventsSent++;
                    if (!transactional) {
                        transaction.commit();
                    }
                }
            }
        }
        if (deleteEventsSent > 0) {
            log.info("Before sending load {} to target node {} delete data events were sent for {} tables", new Object[] { loadId, targetNode, deleteEventsSent });
        }
    } else {
        if (parameterService.is(ParameterConstants.INITIAL_LOAD_DELETE_BEFORE_RELOAD)) {
            for (ListIterator<TriggerHistory> triggerHistoryIterator = triggerHistories.listIterator(triggerHistories.size()); triggerHistoryIterator.hasPrevious(); ) {
                TriggerHistory triggerHistory = triggerHistoryIterator.previous();
                List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
                for (ListIterator<TriggerRouter> iterator = triggerRouters.listIterator(triggerRouters.size()); iterator.hasPrevious(); ) {
                    TriggerRouter triggerRouter = iterator.previous();
                    if (triggerRouter.getInitialLoadOrder() >= 0 && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode) && (!StringUtils.isBlank(parameterService.getString(ParameterConstants.INITIAL_LOAD_DELETE_FIRST_SQL)) || !StringUtils.isEmpty(triggerRouter.getInitialLoadDeleteStmt()))) {
                        insertPurgeEvent(transaction, targetNode, triggerRouter, triggerHistory, true, null, loadId, createBy);
                        if (!transactional) {
                            transaction.commit();
                        }
                    }
                }
            }
        }
    }
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TableReloadRequest(org.jumpmind.symmetric.model.TableReloadRequest)

Example 7 with TableReloadRequest

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

the class DataService method insertCreateBatchesForReload.

private void insertCreateBatchesForReload(Node targetNode, long loadId, String createBy, List<TriggerHistory> triggerHistories, Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId, boolean transactional, ISqlTransaction transaction, Map<String, TableReloadRequest> reloadRequests) {
    if (reloadRequests != null && reloadRequests.size() > 0) {
        int createEventsSent = 0;
        for (TriggerHistory triggerHistory : triggerHistories) {
            List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
            TableReloadRequest currentRequest = reloadRequests.get(ParameterConstants.ALL + ParameterConstants.ALL);
            boolean fullLoad = currentRequest == null ? false : true;
            for (TriggerRouter triggerRouter : triggerRouters) {
                if (!fullLoad) {
                    currentRequest = reloadRequests.get(triggerRouter.getTriggerId() + triggerRouter.getRouterId());
                }
                //Check the create flag on the specific table reload request
                if (currentRequest != null && currentRequest.isCreateTable() && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
                    insertCreateEvent(transaction, targetNode, triggerHistory, triggerRouter.getRouter().getRouterId(), true, loadId, createBy);
                    createEventsSent++;
                    if (!transactional) {
                        transaction.commit();
                    }
                }
            }
        }
        if (createEventsSent > 0) {
            log.info("Before sending load {} to target node {} create table events were sent for {} tables", new Object[] { loadId, targetNode, createEventsSent });
        }
    } else {
        if (parameterService.is(ParameterConstants.INITIAL_LOAD_CREATE_SCHEMA_BEFORE_RELOAD)) {
            for (TriggerHistory triggerHistory : triggerHistories) {
                List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
                for (TriggerRouter triggerRouter : triggerRouters) {
                    if (triggerRouter.getInitialLoadOrder() >= 0 && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
                        insertCreateEvent(transaction, targetNode, triggerHistory, triggerRouter.getRouter().getRouterId(), true, loadId, createBy);
                        if (!transactional) {
                            transaction.commit();
                        }
                    }
                }
            }
        }
    }
}
Also used : TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TableReloadRequest(org.jumpmind.symmetric.model.TableReloadRequest)

Aggregations

TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)7 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)6 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)2 Trigger (org.jumpmind.symmetric.model.Trigger)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1 Table (org.jumpmind.db.model.Table)1 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)1 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)1 IoException (org.jumpmind.exception.IoException)1 Channel (org.jumpmind.symmetric.model.Channel)1 Node (org.jumpmind.symmetric.model.Node)1 INodeService (org.jumpmind.symmetric.service.INodeService)1 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)1