use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class TransformService method deleteTransformTable.
public void deleteTransformTable(String transformTableId) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
deleteTransformColumns(transaction, transformTableId);
transaction.prepareAndExecute(getSql("deleteTransformTableSql"), (Object) transformTableId);
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);
clearCache();
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class IncomingBatchService method updateIncomingBatch.
public int updateIncomingBatch(IncomingBatch batch) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
int count = updateIncomingBatch(transaction, batch);
transaction.commit();
return count;
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
close(transaction);
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class LookupColumnTransform method transform.
public String transform(IDatabasePlatform platform, DataContext context, TransformColumn column, TransformedData data, Map<String, String> sourceValues, String newValue, String oldValue) throws IgnoreColumnException, IgnoreRowException {
String sql = doTokenReplacementOnSql(context, column.getTransformExpression());
String lookupValue = null;
if (StringUtils.isNotBlank(sql)) {
ISqlTransaction transaction = context.findTransaction();
List<String> values = null;
if (transaction != null) {
values = transaction.query(sql, lookupColumnRowMapper, new LinkedCaseInsensitiveMap<Object>(sourceValues));
} else {
values = platform.getSqlTemplate().query(sql, lookupColumnRowMapper, new LinkedCaseInsensitiveMap<Object>(sourceValues));
}
int rowCount = values.size();
if (rowCount == 1) {
lookupValue = values.get(0);
} else if (rowCount > 1) {
lookupValue = values.get(0);
log.warn("Expected a single row, but returned multiple rows from lookup for target column {} on transform {} ", column.getTargetColumnName(), column.getTransformId());
} else if (values.size() == 0) {
log.info("Expected a single row, but returned no rows from lookup for target column {} on transform {}", column.getTargetColumnName(), column.getTransformId());
}
} else {
log.warn("Expected SQL expression for lookup transform, but no expression was found for target column {} on transform {}", column.getTargetColumnName(), column.getTransformId());
}
return lookupValue;
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method testBshTransactionalRoutingOnUpdate.
public void testBshTransactionalRoutingOnUpdate() {
resetBatches();
TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.getRouter().setRouterType("bsh");
trigger1.getRouter().setRouterExpression("targetNodes.add(ROUTING_VARCHAR); targetNodes.add(OLD_ROUTING_VARCHAR);");
getTriggerRouterService().saveTriggerRouter(trigger1);
getTriggerRouterService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
testChannel.setMaxBatchToSend(1000);
testChannel.setMaxBatchSize(5);
testChannel.setBatchAlgorithm("transactional");
getConfigurationService().saveChannel(testChannel, true);
long ts = System.currentTimeMillis();
ISqlTransaction transaction = null;
int count = 0;
try {
transaction = getSqlTemplate().startSqlTransaction();
count = transaction.prepareAndExecute(String.format("update %s set routing_varchar=?", TEST_TABLE_1), NODE_GROUP_NODE_3.getNodeId());
transaction.commit();
} finally {
transaction.close();
}
logger.info("Just recorded a change to " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
ts = System.currentTimeMillis();
getRouterService().routeData(true);
logger.info("Just routed " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
filterForChannels(batches, testChannel);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
filterForChannels(batches, testChannel);
// Node 2 has sync disabled
Assert.assertEquals(0, batches.getBatches().size());
batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
filterForChannels(batches, testChannel);
Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
resetBatches();
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method insert.
protected void insert(final String tableName, final int count, boolean transactional, final String node2disable, final String routingVarcharFieldValue, final boolean rollback) {
ISymmetricDialect dialect = getDbDialect();
IDatabasePlatform platform = dialect.getPlatform();
String columnName = platform.alterCaseToMatchDatabaseDefaultCase("ROUTING_VARCHAR");
ISqlTransaction transaction = null;
try {
transaction = platform.getSqlTemplate().startSqlTransaction();
if (node2disable != null) {
dialect.disableSyncTriggers(transaction, node2disable);
}
transaction.prepare(String.format("insert into %s (%s) values(?)", tableName, columnName));
for (int i = 0; i < count; i++) {
transaction.addRow(i, new Object[] { routingVarcharFieldValue }, new int[] { Types.VARCHAR });
if (!transactional) {
transaction.commit();
}
}
if (node2disable != null) {
dialect.enableSyncTriggers(transaction);
}
if (rollback) {
transaction.rollback();
} else {
transaction.flush();
transaction.commit();
}
} finally {
if (transaction != null) {
transaction.close();
}
}
}
Aggregations