use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class TestTablesService method insertIntoTestUseStreamLob.
// TODO support insert of blob test for postgres and informix
public boolean insertIntoTestUseStreamLob(int id, String tableName, String lobValue) {
if (symmetricDialect.isBlobSyncSupported()) {
ISqlTransaction transaction = null;
try {
transaction = sqlTemplate.startSqlTransaction();
boolean updated = transaction.prepareAndExecute(String.format("insert into %s (test_id, test_blob) values(?, ?)", tableName), new Object[] { id, lobValue.getBytes() }, new int[] { Types.INTEGER, Types.BLOB }) > 0;
transaction.commit();
return updated;
} finally {
if (transaction != null) {
transaction.close();
}
}
} else {
return false;
}
}
use of org.jumpmind.db.sql.ISqlTransaction in project symmetric-ds by JumpMind.
the class TestTablesService method insertIntoTestTriggerTable.
public void insertIntoTestTriggerTable(Object[] values) {
Table testTriggerTable = platform.getTableFromCache(null, null, "test_triggers_table", true);
DatabaseInfo dbInfo = getSymmetricDialect().getPlatform().getDatabaseInfo();
String quote = dbInfo.getDelimiterToken();
String catalogSeparator = dbInfo.getCatalogSeparator();
String schemaSeparator = dbInfo.getSchemaSeparator();
ISqlTransaction transaction = sqlTemplate.startSqlTransaction();
try {
transaction.allowInsertIntoAutoIncrementColumns(true, testTriggerTable, quote, catalogSeparator, schemaSeparator);
transaction.prepareAndExecute(getSql("insertIntoTestTriggersTableSql"), values);
transaction.commit();
} finally {
transaction.allowInsertIntoAutoIncrementColumns(false, testTriggerTable, quote, catalogSeparator, schemaSeparator);
transaction.close();
}
}
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);
}
}
Aggregations