use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test10DisableTriggers.
@Test
public void test10DisableTriggers() throws Exception {
ISymmetricDialect dbDialect = getDbDialect();
ISqlTemplate jdbcTemplate = getSqlTemplate();
ISqlTransaction transaction = jdbcTemplate.startSqlTransaction();
try {
dbDialect.disableSyncTriggers(transaction);
int count = insert(INSERT1_VALUES, transaction, dbDialect);
dbDialect.enableSyncTriggers(transaction);
transaction.commit();
assertTrue(count == 1);
String csvString = getNextDataRow();
// DB2 captures decimal differently
csvString = csvString.replaceFirst("\"00001\\.\"", "\"1\"");
// Informix captures decimal differently
csvString = csvString.replaceFirst("\"1.0000000000000000\"", "\"1\"");
// ASA captures decimal differently
csvString = csvString.replaceFirst("\"1.000000\"", "\"1\"");
boolean match = csvString.endsWith(EXPECTED_INSERT2_CSV_ENDSWITH);
assertTrue(match, "Received " + csvString + ", Expected the string to end with " + EXPECTED_INSERT2_CSV_ENDSWITH);
} finally {
transaction.close();
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class AbstractTriggerRouterServiceTest method test12BinaryColumnTypesForPostgres.
@Test
public void test12BinaryColumnTypesForPostgres() {
ISymmetricDialect dialect = getDbDialect();
if (DatabaseNamesConstants.POSTGRESQL.equals(dialect.getName())) {
getSqlTemplate().update(DROP_POSTGRES_BINARY_TYPE);
getSqlTemplate().update(CREATE_POSTGRES_BINARY_TYPE);
TriggerRouter trouter = new TriggerRouter();
Trigger trigger = trouter.getTrigger();
trigger.setSourceTableName("test_postgres_binary_types");
trigger.setChannelId(TestConstants.TEST_CHANNEL_ID);
Router router = trouter.getRouter();
router.getNodeGroupLink().setSourceNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
router.getNodeGroupLink().setTargetNodeGroupId(TestConstants.TEST_ROOT_NODE_GROUP);
getTriggerRouterService().saveTriggerRouter(trouter);
ITriggerRouterService triggerService = getTriggerRouterService();
triggerService.syncTriggers();
Assert.assertEquals("Some triggers must have failed to build.", 0, triggerService.getFailedTriggers().size());
// new SerialBlob("test 1 2 3".getBytes())
ISqlTransaction transaction = getSqlTemplate().startSqlTransaction();
try {
getSqlTemplate().update(INSERT_POSTGRES_BINARY_TYPE_1, "test 1 2 3".getBytes());
transaction.commit();
} finally {
transaction.close();
}
String csvString = getNextDataRow();
Assert.assertEquals(EXPECTED_INSERT_POSTGRES_BINARY_TYPE_1, csvString);
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class SQLDatabaseWriterFilter method processLoadFilters.
@Override
protected boolean processLoadFilters(DataContext context, Table table, CsvData data, Exception error, WriteMethod writeMethod, List<LoadFilter> loadFiltersForTable) {
boolean writeRow = true;
LoadFilter currentFilter = null;
List<Boolean> values = null;
try {
LinkedCaseInsensitiveMap<Object> namedParams = null;
for (LoadFilter filter : loadFiltersForTable) {
currentFilter = filter;
values = null;
if (filter.isFilterOnDelete() && data.getDataEventType().equals(DataEventType.DELETE) || filter.isFilterOnInsert() && data.getDataEventType().equals(DataEventType.INSERT) || filter.isFilterOnUpdate() && data.getDataEventType().equals(DataEventType.UPDATE)) {
String sql = null;
if (writeMethod.equals(WriteMethod.BEFORE_WRITE) && filter.getBeforeWriteScript() != null) {
sql = doTokenReplacementOnSql(context, filter.getBeforeWriteScript());
} else if (writeMethod.equals(WriteMethod.AFTER_WRITE) && filter.getAfterWriteScript() != null) {
sql = doTokenReplacementOnSql(context, filter.getAfterWriteScript());
} else if (writeMethod.equals(WriteMethod.HANDLE_ERROR) && filter.getHandleErrorScript() != null) {
sql = doTokenReplacementOnSql(context, filter.getHandleErrorScript());
}
if (sql != null && !sql.trim().isEmpty()) {
if (namedParams == null) {
namedParams = getVariablesMap(table, data);
}
ISqlTransaction transaction = context.findTransaction();
values = transaction.query(sql, lookupColumnRowMapper, namedParams);
}
if (values != null && values.size() > 0) {
writeRow = values.get(0);
}
}
}
} catch (Exception ex) {
processError(currentFilter, table, ex);
}
return writeRow;
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class DataGapFastDetector method fixOverlappingGaps.
protected void fixOverlappingGaps(List<DataGap> gaps, ProcessInfo processInfo) {
try {
ISqlTransaction transaction = null;
log.debug("Looking for overlapping gaps");
try {
ISqlTemplate sqlTemplate = symmetricDialect.getPlatform().getSqlTemplate();
transaction = sqlTemplate.startSqlTransaction();
DataGap prevGap = null, lastGap = null;
for (int i = 0; i < gaps.size(); i++) {
DataGap curGap = gaps.get(i);
if (lastGap != null) {
log.warn("Removing gap found after last gap: " + curGap);
dataService.deleteDataGap(transaction, curGap);
gaps.remove(i--);
} else {
if (lastGap == null && curGap.gapSize() >= maxDataToSelect - 1) {
lastGap = curGap;
}
if (prevGap != null) {
if (prevGap.overlaps(curGap)) {
log.warn("Removing overlapping gaps: " + prevGap + ", " + curGap);
dataService.deleteDataGap(transaction, prevGap);
dataService.deleteDataGap(transaction, curGap);
DataGap newGap = null;
if (curGap.equals(lastGap)) {
newGap = new DataGap(prevGap.getStartId(), prevGap.getStartId() + maxDataToSelect - 1);
} else {
newGap = new DataGap(prevGap.getStartId(), prevGap.getEndId() > curGap.getEndId() ? prevGap.getEndId() : curGap.getEndId());
}
log.warn("Inserting new gap to fix overlap: " + newGap);
dataService.insertDataGap(transaction, newGap);
gaps.remove(i--);
gaps.set(i, newGap);
curGap = newGap;
}
}
}
prevGap = curGap;
}
transaction.commit();
} catch (Error ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} catch (RuntimeException ex) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
} finally {
if (transaction != null) {
transaction.close();
}
}
} catch (RuntimeException ex) {
processInfo.setStatus(Status.ERROR);
throw ex;
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class DataExtractorService method resetExtractRequest.
@Override
public void resetExtractRequest(OutgoingBatch batch) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
batch.setStatus(Status.RQ);
outgoingBatchService.updateOutgoingBatch(transaction, batch);
transaction.prepareAndExecute(getSql("resetExtractRequestStatus"), ExtractStatus.NE.name(), batch.getBatchId(), batch.getBatchId(), batch.getNodeId());
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