Search in sources :

Example 46 with ISqlTransaction

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;
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction)

Example 47 with ISqlTransaction

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();
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Table(org.jumpmind.db.model.Table) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo)

Example 48 with ISqlTransaction

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);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) ExtensionService(org.jumpmind.symmetric.service.impl.ExtensionService) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DataContext(org.jumpmind.symmetric.io.data.DataContext) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IParameterService(org.jumpmind.symmetric.service.IParameterService) Before(org.junit.Before)

Example 49 with ISqlTransaction

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();
        }
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Table(org.jumpmind.db.model.Table) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 50 with ISqlTransaction

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);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Test(org.junit.Test)

Aggregations

ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)50 Node (org.jumpmind.symmetric.model.Node)6 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)6 ArrayList (java.util.ArrayList)5 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)5 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)5 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)5 List (java.util.List)4 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 Trigger (org.jumpmind.symmetric.model.Trigger)4 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)4 Date (java.util.Date)3 Table (org.jumpmind.db.model.Table)3 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)3 Data (org.jumpmind.symmetric.model.Data)3 DataGap (org.jumpmind.symmetric.model.DataGap)3 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)3 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)2 SqlException (org.jumpmind.db.sql.SqlException)2 CsvData (org.jumpmind.symmetric.io.data.CsvData)2