use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class DataService method insertDataAndDataEventAndOutgoingBatch.
/**
* @return The inserted batch id
*/
public long insertDataAndDataEventAndOutgoingBatch(ISqlTransaction transaction, Data data, String nodeId, String routerId, boolean isLoad, long loadId, String createBy, Status status, String overrideChannelId) {
long dataId = insertData(transaction, data);
String channelId = null;
if (isLoad) {
if (overrideChannelId != null) {
channelId = overrideChannelId;
} else {
TriggerHistory history = data.getTriggerHistory();
if (history != null && channelId == null) {
Trigger trigger = engine.getTriggerRouterService().getTriggerById(history.getTriggerId());
channelId = getReloadChannelIdForTrigger(trigger, engine.getConfigurationService().getChannels(false));
}
}
} else {
channelId = data.getChannelId();
}
return insertDataEventAndOutgoingBatch(transaction, dataId, channelId, nodeId, data.getDataEventType(), routerId, isLoad, loadId, createBy, status, data.getTableName());
}
use of org.jumpmind.symmetric.model.Trigger 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(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();
}
}
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method updateOrCreateDatabaseTriggers.
protected void updateOrCreateDatabaseTriggers(final List<Trigger> triggers, final StringBuilder sqlBuffer, final boolean force, final boolean verifyInDatabase, final List<TriggerHistory> activeTriggerHistories, final boolean useTableCache) {
int numThreads = getNumberOfThreadsToUseForSyncTriggers();
ExecutorService executor = Executors.newFixedThreadPool(numThreads, new SyncTriggersThreadFactory());
List<Future<?>> futures = new ArrayList<Future<?>>();
for (final Trigger trigger : triggers) {
Runnable task = new Runnable() {
public void run() {
updateOrCreateDatabaseTrigger(trigger, triggers, sqlBuffer, force, verifyInDatabase, activeTriggerHistories, useTableCache);
}
};
futures.add(executor.submit(task));
}
awaitTermination(executor, futures);
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method syncTriggers.
public void syncTriggers(StringBuilder sqlBuffer, boolean force) {
if ((parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS) || isCalledFromSymmetricAdminTool())) {
synchronized (this) {
if (clusterService.lock(ClusterConstants.SYNCTRIGGERS)) {
try {
String additionalMessage = "";
if (isCalledFromSymmetricAdminTool() && !parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
additionalMessage = " " + ParameterConstants.AUTO_SYNC_TRIGGERS + " is set to false, but the sync triggers process will run so that needed changes can be written to a file so they can be applied manually. Once all of the triggers have been successfully applied this process should not show triggers being created";
}
log.info("Synchronizing triggers{}", additionalMessage);
// make sure all tables are freshly read in
platform.resetCachedTableModel();
clearCache();
// make sure channels are read from the database
configurationService.clearCache();
List<Trigger> triggersForCurrentNode = getTriggersForCurrentNode();
boolean createTriggersForTables = false;
String nodeId = nodeService.findIdentityNodeId();
if (StringUtils.isNotBlank(nodeId)) {
NodeSecurity nodeSecurity = nodeService.findNodeSecurity(nodeId);
if (nodeSecurity != null && (nodeSecurity.isInitialLoadEnabled() || nodeSecurity.getInitialLoadTime() == null)) {
createTriggersForTables = parameterService.is(ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD);
if (!createTriggersForTables) {
log.info("Trigger creation has been disabled by " + ParameterConstants.TRIGGER_CREATE_BEFORE_INITIAL_LOAD + " because an initial load is in progress or has not yet been requested");
}
} else {
createTriggersForTables = true;
}
}
if (!createTriggersForTables) {
triggersForCurrentNode.clear();
}
List<TriggerHistory> activeTriggerHistories = getActiveTriggerHistories();
inactivateTriggers(triggersForCurrentNode, sqlBuffer, activeTriggerHistories);
updateOrCreateDatabaseTriggers(triggersForCurrentNode, sqlBuffer, force, true, activeTriggerHistories, true);
resetTriggerRouterCacheByNodeGroupId();
if (createTriggersForTables) {
updateOrCreateDdlTriggers(sqlBuffer);
}
} finally {
clusterService.unlock(ClusterConstants.SYNCTRIGGERS);
log.info("Done synchronizing triggers");
}
} else {
Lock lock = clusterService.findLocks().get(ClusterConstants.SYNCTRIGGERS);
if (lock != null) {
log.info("Sync triggers was locked by the cluster service. The locking server id was: {}. The lock time was: {}", lock.getLockingServerId(), lock.getLockTime());
} else {
log.info("Sync triggers was locked by something but lock details were found");
}
}
}
} else {
log.info("Not synchronizing triggers. {} is set to false", ParameterConstants.AUTO_SYNC_TRIGGERS);
}
}
use of org.jumpmind.symmetric.model.Trigger in project symmetric-ds by JumpMind.
the class TriggerRouterService method enhanceTriggerRouters.
private List<TriggerRouter> enhanceTriggerRouters(List<TriggerRouter> triggerRouters) {
HashMap<String, Router> routersById = new HashMap<String, Router>();
for (Router router : getRouters()) {
routersById.put(router.getRouterId().trim().toUpperCase(), router);
}
HashMap<String, Trigger> triggersById = new HashMap<String, Trigger>();
for (Trigger trigger : getTriggers()) {
triggersById.put(trigger.getTriggerId().trim().toUpperCase(), trigger);
}
for (TriggerRouter triggerRouter : triggerRouters) {
triggerRouter.setTrigger(triggersById.get(triggerRouter.getTrigger().getTriggerId().trim().toUpperCase()));
triggerRouter.setRouter(routersById.get(triggerRouter.getRouter().getRouterId().trim().toUpperCase()));
}
return triggerRouters;
}
Aggregations