use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DataService method insertSQLBatchesForReload.
private void insertSQLBatchesForReload(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 sqlEventsSent = 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 before custom sql is present on the specific table reload request
if (currentRequest != null && currentRequest.getBeforeCustomSql() != null && currentRequest.getBeforeCustomSql().length() > 0 && engine.getGroupletService().isTargetEnabled(triggerRouter, targetNode)) {
String tableName = triggerRouter.qualifiedTargetTableName(triggerHistory);
String formattedBeforeSql = String.format(currentRequest.getBeforeCustomSql(), tableName) + ";";
insertSqlEvent(transaction, triggerHistory, triggerRouter.getTrigger().getChannelId(), targetNode, formattedBeforeSql, true, loadId, createBy);
sqlEventsSent++;
if (!transactional) {
transaction.commit();
}
}
}
}
if (sqlEventsSent > 0) {
log.info("Before sending load {} to target node {} SQL data events were sent for {} tables", new Object[] { loadId, targetNode, sqlEventsSent });
}
}
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DataService method insertSqlEventsPriorToReload.
private void insertSqlEventsPriorToReload(Node targetNode, String nodeIdRecord, long loadId, String createBy, boolean transactional, ISqlTransaction transaction, boolean reverse, List<TriggerHistory> triggerHistories, Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId, Map<String, TableReloadRequest> reloadRequests, boolean isFullLoad, String channelId) {
if (!Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
/*
* Insert node security so the client doing the initial load knows
* that an initial load is currently happening
*/
insertNodeSecurityUpdate(transaction, nodeIdRecord, targetNode.getNodeId(), true, loadId, createBy, channelId);
if (isFullLoad) {
/*
* Mark incoming batches as OK at the target node because we marked
* outgoing batches as OK at the source
*/
insertSqlEvent(transaction, targetNode, String.format("update %s_incoming_batch set status='OK', error_flag=0 where node_id='%s' and status != 'OK'", tablePrefix, engine.getNodeService().findIdentityNodeId()), true, loadId, createBy);
}
}
if (!isFullLoad && reloadRequests != null && reloadRequests.size() > 0) {
String beforeSql = "";
int beforeSqlSent = 0;
for (TriggerHistory triggerHistory : triggerHistories) {
List<TriggerRouter> triggerRouters = triggerRoutersByHistoryId.get(triggerHistory.getTriggerHistoryId());
for (TriggerRouter triggerRouter : triggerRouters) {
String key = triggerRouter.getTriggerId() + triggerRouter.getRouterId();
TableReloadRequest currentRequest = reloadRequests.get(key);
if (currentRequest == null) {
throw new SymmetricException("Could not locate table reload request for key '" + key + "'. Available requests are: " + reloadRequests.keySet());
}
beforeSql = currentRequest.getBeforeCustomSql();
if (isNotBlank(beforeSql)) {
String tableName = triggerRouter.qualifiedTargetTableName(triggerHistory);
String formattedBeforeSql = String.format(beforeSql, tableName) + ";";
insertSqlEvent(transaction, targetNode, formattedBeforeSql, true, loadId, createBy);
beforeSqlSent++;
}
}
}
if (beforeSqlSent > 0) {
log.info("Before sending load {} to target node {} the before sql [{}] was sent for {} tables", new Object[] { loadId, targetNode, beforeSql, beforeSqlSent });
}
} else {
String beforeSql = parameterService.getString(reverse ? ParameterConstants.INITIAL_LOAD_REVERSE_BEFORE_SQL : ParameterConstants.INITIAL_LOAD_BEFORE_SQL);
if (isNotBlank(beforeSql)) {
insertSqlEvent(transaction, targetNode, beforeSql, true, loadId, createBy);
}
}
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DataService method createData.
public Data createData(ISqlTransaction transaction, String catalogName, String schemaName, String tableName, String whereClause) {
Data data = null;
Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(catalogName, schemaName, tableName, false);
if (triggerRouters != null && triggerRouters.size() > 0) {
data = createData(transaction, triggerRouters.iterator().next().getTrigger(), whereClause);
}
return data;
}
use of org.jumpmind.symmetric.model.TriggerRouter 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 {}. The target node 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;
}
}
use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.
the class DataService method insertHeartbeatEvent.
/**
* Because we can't add a trigger on the _node table, we are artificially
* generating heartbeat events.
*
* @param node
*/
public void insertHeartbeatEvent(Node node, boolean isReload) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
String tableName = TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST);
List<NodeGroupLink> links = engine.getConfigurationService().getNodeGroupLinksFor(parameterService.getNodeGroupId(), false);
for (NodeGroupLink nodeGroupLink : links) {
if (nodeGroupLink.getDataEventAction() == NodeGroupLinkAction.P) {
Set<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouterForTableForCurrentNode(nodeGroupLink, null, null, tableName, false);
if (triggerRouters != null && triggerRouters.size() > 0) {
Data data = createData(transaction, triggerRouters.iterator().next().getTrigger(), String.format(" t.node_id = '%s'", node.getNodeId()));
if (data != null) {
insertData(transaction, data);
} else {
log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
}
} else {
log.warn("Not generating data/data events for table {} " + "because a trigger or trigger hist is not created yet.", tableName);
}
}
}
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);
}
}
Aggregations