Search in sources :

Example 21 with ISqlTransaction

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

Example 22 with ISqlTransaction

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

Example 23 with ISqlTransaction

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

Example 24 with ISqlTransaction

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

Example 25 with ISqlTransaction

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

Aggregations

ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)53 Node (org.jumpmind.symmetric.model.Node)7 ArrayList (java.util.ArrayList)6 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)6 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)6 List (java.util.List)5 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)5 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)5 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)5 SymmetricException (org.jumpmind.symmetric.SymmetricException)4 Trigger (org.jumpmind.symmetric.model.Trigger)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 INodeService (org.jumpmind.symmetric.service.INodeService)3 Test (org.junit.Test)3 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)2