use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class JavaColumnTransformTest method setUp.
@Before
public void setUp() throws Exception {
ISqlTransaction sqlTransaction = mock(ISqlTransaction.class);
platform = mock(IDatabasePlatform.class);
ISymmetricEngine engine = mock(ISymmetricEngine.class);
IParameterService parameterService = mock(IParameterService.class);
IDatabasePlatform platform = mock(IDatabasePlatform.class);
ISymmetricDialect dialect = mock(ISymmetricDialect.class);
when(dialect.getPlatform()).thenReturn(platform);
when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
when(engine.getParameterService()).thenReturn(parameterService);
when(engine.getSymmetricDialect()).thenReturn(dialect);
extensionService = new ExtensionService(engine);
when(engine.getExtensionService()).thenReturn(extensionService);
context = mock(DataContext.class);
when(context.findTransaction()).thenReturn(sqlTransaction);
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class DbFill method fillTables.
/**
* Perform an INSERT, UPDATE, or DELETE on every table in tables.
*
* @param tables Array of tables to perform statement on. Tables must be in
* insert order.
* @param tableProperties Map indicating IUD weights for each table name provided
* in the properties file.
*/
private void fillTables(List<Table> tables, Map<String, int[]> tableProperties) {
ISqlTransaction tran = platform.getSqlTemplate().startSqlTransaction();
int rowsInTransaction = 0;
for (int x = 0; x < repeat; x++) {
int numRowsToGenerate = inputLength;
int numRowsToCommit = maxRowsCommit;
if (useRandomCount) {
numRowsToGenerate = getRand().nextInt(inputLength);
numRowsToGenerate = numRowsToGenerate > 0 ? numRowsToGenerate : 1;
numRowsToCommit = getRand().nextInt(maxRowsCommit);
numRowsToCommit = numRowsToCommit > 0 ? numRowsToCommit : 1;
}
for (int i = 0; i < numRowsToGenerate; i++) {
ArrayList<Table> tablesToProcess = new ArrayList<Table>(tables);
while (tablesToProcess.size() > 0) {
Table tableToProcess = tablesToProcess.get(0);
int dmlType = INSERT;
if (tableProperties != null && tableProperties.containsKey(tableToProcess.getName())) {
dmlType = randomIUD(tableProperties.get(tableToProcess.getName()));
} else if (dmlWeight != null) {
dmlType = randomIUD(dmlWeight);
}
List<Table> groupTables = new ArrayList<Table>();
if (cascading && dmlType == INSERT) {
groupTables.addAll(foreignTables.get(tableToProcess));
if (groupTables.size() > 0) {
log.info("Cascade insert " + tableToProcess.getName() + ": " + toStringTables(groupTables));
}
} else if (cascadingSelect && dmlType == INSERT) {
List<Table> foreignList = foreignTables.get(tableToProcess);
for (Table foreignTable : foreignList) {
if (tables.contains(foreignTable)) {
groupTables.add(foreignTable);
} else {
selectRandomRecord(tran, foreignTable);
}
}
}
groupTables.add(tableToProcess);
if (truncate) {
for (Table table : groupTables) {
truncateTable(tran, table);
}
}
for (Table table : groupTables) {
switch(dmlType) {
case INSERT:
if (verbose) {
log.info("Inserting into table " + table.getName());
}
insertRandomRecord(tran, table);
break;
case UPDATE:
if (verbose) {
log.info("Updating record in table " + table.getName());
}
updateRandomRecord(tran, table);
break;
case DELETE:
if (verbose) {
log.info("Deleting record in table " + table.getName());
}
deleteRandomRecord(tran, table);
break;
}
if (++rowsInTransaction >= numRowsToCommit) {
if (commitDelay > 0) {
AppUtils.sleep(commitDelay);
}
if (percentRollback > 0 && getRand().nextInt(100) <= percentRollback) {
if (verbose) {
log.info("Rollback " + rowsInTransaction + " rows");
}
tran.rollback();
} else {
if (verbose) {
log.info("Commit " + rowsInTransaction + " rows");
}
tran.commit();
}
rowsInTransaction = 0;
AppUtils.sleep(interval);
}
}
tablesToProcess.removeAll(groupTables);
}
clearDependentColumnValues(tables);
}
if (rowsInTransaction > 0) {
if (commitDelay > 0) {
AppUtils.sleep(commitDelay);
}
if (verbose) {
log.info("Commit " + rowsInTransaction + " rows");
}
tran.commit();
}
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class SimpleIntegrationTest method test31ReloadMissingForeignKeys.
@Test
public void test31ReloadMissingForeignKeys() {
if (getClient().getSymmetricDialect().getName().equalsIgnoreCase(DatabaseNamesConstants.VOLTDB) || getClient().getSymmetricDialect().getName().equalsIgnoreCase(DatabaseNamesConstants.REDSHIFT) || getClient().getSymmetricDialect().getName().equalsIgnoreCase(DatabaseNamesConstants.GREENPLUM) || getClient().getSymmetricDialect().getName().equalsIgnoreCase(DatabaseNamesConstants.SQLITE) || getClient().getSymmetricDialect().getName().equalsIgnoreCase(DatabaseNamesConstants.GENERIC)) {
return;
}
ISqlTransaction tran = getServer().getSqlTemplate().startSqlTransaction();
getServer().getSymmetricDialect().disableSyncTriggers(tran, null);
tran.execute("insert into test_a (id) values ('1')");
tran.commit();
getServer().getSqlTemplate().update("insert into test_b (id, aid) values('1', '1')");
int tries = 0;
while (clientPull()) {
if (tries++ > 10) {
Assert.fail("Unable to resolve missing foreign key");
}
AppUtils.sleep(1000);
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class SequenceService method currVal.
public long currVal(String name) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
long val = currVal(transaction, name);
transaction.commit();
return val;
} 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 TransformService method saveTransformTable.
public void saveTransformTable(TransformTableNodeGroupLink transformTable, boolean saveTransformColumns) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
transformTable.setLastUpdateTime(new Date());
if (transaction.prepareAndExecute(getSql("updateTransformTableSql"), transformTable.getNodeGroupLink().getSourceNodeGroupId(), transformTable.getNodeGroupLink().getTargetNodeGroupId(), transformTable.getSourceCatalogName(), transformTable.getSourceSchemaName(), transformTable.getSourceTableName(), transformTable.getTargetCatalogName(), transformTable.getTargetSchemaName(), transformTable.getTargetTableName(), transformTable.getTransformPoint().toString(), transformTable.isUpdateFirst() ? 1 : 0, transformTable.getDeleteAction().toString(), transformTable.getTransformOrder(), transformTable.getColumnPolicy().toString(), transformTable.getLastUpdateTime(), transformTable.getLastUpdateBy(), transformTable.getTransformId()) == 0) {
transformTable.setCreateTime(new Date());
transaction.prepareAndExecute(getSql("insertTransformTableSql"), transformTable.getNodeGroupLink().getSourceNodeGroupId(), transformTable.getNodeGroupLink().getTargetNodeGroupId(), transformTable.getSourceCatalogName(), transformTable.getSourceSchemaName(), transformTable.getSourceTableName(), transformTable.getTargetCatalogName(), transformTable.getTargetSchemaName(), transformTable.getTargetTableName(), transformTable.getTransformPoint().toString(), transformTable.isUpdateFirst() ? 1 : 0, transformTable.getDeleteAction().toString(), transformTable.getTransformOrder(), transformTable.getColumnPolicy().toString(), transformTable.getLastUpdateTime(), transformTable.getLastUpdateBy(), transformTable.getCreateTime(), transformTable.getTransformId());
}
if (saveTransformColumns) {
deleteTransformColumns(transaction, transformTable.getTransformId());
List<TransformColumn> columns = transformTable.getTransformColumns();
if (columns != null) {
for (TransformColumn transformColumn : columns) {
saveTransformColumn(transaction, transformColumn);
}
}
}
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();
}
}
Aggregations