use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.
the class DatabaseUpgradeListener method dropTriggers.
protected void dropTriggers(Database currentModel, String tableName, String columnName) {
Table table = currentModel.findTable(tableName);
if (table != null && table.findColumn(columnName) != null) {
TriggerHistory hist = engine.getTriggerRouterService().findTriggerHistory(null, null, tableName);
if (hist != null) {
log.info("Dropping triggers on " + tableName + " because " + columnName + " needs dropped");
engine.getTriggerRouterService().dropTriggers(hist);
}
}
}
use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.
the class DataService method insertFileSyncBatchForReload.
private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction, ProcessInfo processInfo) {
if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE) && !Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
IFileSyncService fileSyncService = engine.getFileSyncService();
if (fileSyncService.getFileTriggerRoutersForCurrentNode().size() > 0) {
TriggerHistory fileSyncSnapshotHistory = triggerRouterService.findTriggerHistory(null, null, TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT));
String routerid = triggerRouterService.buildSymmetricTableRouterId(fileSyncSnapshotHistory.getTriggerId(), parameterService.getNodeGroupId(), targetNode.getNodeGroupId());
TriggerRouter fileSyncSnapshotTriggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(fileSyncSnapshotHistory.getTriggerId(), routerid, true);
List<TriggerHistory> triggerHistories = Arrays.asList(fileSyncSnapshotHistory);
List<TriggerRouter> triggerRouters = Arrays.asList(fileSyncSnapshotTriggerRouter);
Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = new HashMap<Integer, List<TriggerRouter>>();
triggerRoutersByHistoryId.put(fileSyncSnapshotHistory.getTriggerHistoryId(), triggerRouters);
if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, null, processInfo);
} else {
List<Channel> channels = engine.getConfigurationService().getFileSyncChannels();
for (Channel channel : channels) {
if (channel.isReloadFlag()) {
insertReloadEvent(transaction, targetNode, fileSyncSnapshotTriggerRouter, fileSyncSnapshotHistory, "reload_channel_id='" + channel.getChannelId() + "'", true, loadId, createBy, Status.NE, channel.getChannelId());
if (!transactional) {
transaction.commit();
}
}
}
}
}
}
}
use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.
the class DataService method insertReloadEvents.
public void insertReloadEvents(Node targetNode, boolean reverse, List<TableReloadRequest> reloadRequests, ProcessInfo processInfo) {
if (engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS)) {
try {
synchronized (engine.getTriggerRouterService()) {
engine.getClusterService().lock(ClusterConstants.SYNCTRIGGERS);
boolean isFullLoad = reloadRequests == null || (reloadRequests.size() == 1 && reloadRequests.get(0).isFullLoadRequest());
if (!reverse) {
log.info("Queueing up " + (isFullLoad ? "an initial" : "a") + " load to node " + targetNode.getNodeId());
} else {
log.info("Queueing up a reverse " + (isFullLoad ? "initial" : "") + " load to node " + targetNode.getNodeId());
}
/*
* Outgoing data events are pointless because we are
* reloading all data
*/
if (isFullLoad) {
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);
processInfo.setCurrentLoadId(loadId);
String createBy = reverse ? nodeSecurity.getRevInitialLoadCreateBy() : nodeSecurity.getInitialLoadCreateBy();
List<TriggerHistory> triggerHistories = new ArrayList<TriggerHistory>();
if (isFullLoad) {
triggerHistories = triggerRouterService.getActiveTriggerHistories();
} else {
for (TableReloadRequest reloadRequest : reloadRequests) {
triggerHistories.addAll(engine.getTriggerRouterService().getActiveTriggerHistories(new Trigger(reloadRequest.getTriggerId(), null)));
}
}
processInfo.setDataCount(triggerHistories.size());
Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = triggerRouterService.fillTriggerRoutersByHistIdAndSortHist(sourceNode.getNodeGroupId(), targetNode.getNodeGroupId(), triggerHistories);
if (isFullLoad) {
callReloadListeners(true, targetNode, transactional, transaction, loadId);
insertCreateSchemaScriptPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction);
}
Map<String, TableReloadRequest> mapReloadRequests = convertReloadListToMap(reloadRequests);
String symNodeSecurityReloadChannel = null;
try {
symNodeSecurityReloadChannel = triggerRoutersByHistoryId.get(triggerHistories.get(0).getTriggerHistoryId()).get(0).getTrigger().getReloadChannelId();
} catch (Exception e) {
}
if (isFullLoad || (reloadRequests != null && reloadRequests.size() > 0)) {
insertSqlEventsPriorToReload(targetNode, nodeIdRecord, loadId, createBy, transactional, transaction, reverse, triggerHistories, triggerRoutersByHistoryId, mapReloadRequests, isFullLoad, symNodeSecurityReloadChannel);
}
insertCreateBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
insertDeleteBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
insertSQLBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests);
insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, mapReloadRequests, processInfo);
if (isFullLoad) {
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, processInfo);
if (isFullLoad) {
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, symNodeSecurityReloadChannel);
}
engine.getStatisticManager().incrementNodesLoaded(1);
if (reloadRequests != null && reloadRequests.size() > 0) {
for (TableReloadRequest request : reloadRequests) {
transaction.prepareAndExecute(getSql("updateProcessedTableReloadRequest"), loadId, new Date(), request.getTargetNodeId(), request.getSourceNodeId(), request.getTriggerId(), request.getRouterId(), request.getCreateTime());
}
log.info("Table reload request(s) for load id " + loadId + " have been processed.");
}
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");
}
}
use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.
the class XmlPublisherDataRouterTest method testPublishUpdateAsXml.
@Test
public void testPublishUpdateAsXml() {
Data data = new Data();
data.setDataEventType(DataEventType.UPDATE);
data.setRowData("2,updated data");
data.setTriggerHistory(new TriggerHistory(TABLE_NAME, "ID", "ID,DATA"));
data.setTableName(TABLE_NAME);
router.routeToNodes(context, new DataMetaData(data, table, null, null), null, false, false, null);
router.contextCommitted(context);
assertEquals(UPDATE_XML.trim(), output.toString().trim());
}
use of org.jumpmind.symmetric.model.TriggerHistory in project symmetric-ds by JumpMind.
the class XmlPublisherDataRouterTest method testPublishInsertAsXml.
@Test
public void testPublishInsertAsXml() {
Data data = new Data();
data.setDataEventType(DataEventType.INSERT);
data.setRowData("1,new inserted data");
data.setTriggerHistory(new TriggerHistory(TABLE_NAME, "ID", "ID,DATA"));
data.setTableName(TABLE_NAME);
router.routeToNodes(context, new DataMetaData(data, table, null, null), null, false, false, null);
router.contextCommitted(context);
assertEquals(INSERT_XML.trim(), output.toString().trim());
}
Aggregations