Search in sources :

Example 11 with SymmetricException

use of org.jumpmind.symmetric.SymmetricException in project symmetric-ds by JumpMind.

the class MsSqlSymmetricDialect method verifyDatabaseIsCompatible.

@Override
public void verifyDatabaseIsCompatible() {
    super.verifyDatabaseIsCompatible();
    ISqlTemplate template = getPlatform().getSqlTemplate();
    if (template.queryForInt("select case when (512 & @@options) = 512 then 1 else 0 end") == 1) {
        throw new SymmetricException("NOCOUNT is currently turned ON.  SymmetricDS will not function with NOCOUNT turned ON.");
    }
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) SymmetricException(org.jumpmind.symmetric.SymmetricException)

Example 12 with SymmetricException

use of org.jumpmind.symmetric.SymmetricException in project symmetric-ds by JumpMind.

the class BshDatabaseWriterFilter method executeScripts.

@Override
protected void executeScripts(DataContext context, String key, Set<String> scripts, boolean isFailOnError) {
    Interpreter interpreter = getInterpreter(context);
    String currentScript = null;
    try {
        bind(interpreter, context, null, null, null);
        if (scripts != null) {
            for (String script : scripts) {
                currentScript = script;
                interpreter.eval(script);
            }
        }
    } catch (EvalError e) {
        if (e instanceof ParseException) {
            String errorMsg = String.format("Evaluation error while parsing the following beanshell script:\n\n%s\n\nThe error was on line %d and the error message was: %s", currentScript, e.getErrorLineNumber(), e.getMessage());
            log.error(errorMsg, e);
            if (isFailOnError) {
                throw new SymmetricException(errorMsg);
            }
        } else if (e instanceof TargetError) {
            Throwable target = ((TargetError) e).getTarget();
            String errorMsg = String.format("Evaluation error occured in the following beanshell script:\n\n%s\n\nThe error was on line %d", currentScript, e.getErrorLineNumber());
            log.error(errorMsg, target);
            if (isFailOnError) {
                if (target instanceof RuntimeException) {
                    throw (RuntimeException) target;
                } else {
                    throw new SymmetricException(target);
                }
            } else {
                log.error("Failed while evaluating script", target);
            }
        }
    }
}
Also used : Interpreter(bsh.Interpreter) SymmetricException(org.jumpmind.symmetric.SymmetricException) EvalError(bsh.EvalError) ParseException(bsh.ParseException) TargetError(bsh.TargetError)

Example 13 with SymmetricException

use of org.jumpmind.symmetric.SymmetricException in project symmetric-ds by JumpMind.

the class DataExtractorService method lookupAndOrderColumnsAccordingToTriggerHistory.

protected Table lookupAndOrderColumnsAccordingToTriggerHistory(String routerId, TriggerHistory triggerHistory, boolean setTargetTableName, boolean useDatabaseDefinition) {
    String catalogName = triggerHistory.getSourceCatalogName();
    String schemaName = triggerHistory.getSourceSchemaName();
    String tableName = triggerHistory.getSourceTableName();
    Table table = null;
    if (useDatabaseDefinition) {
        table = platform.getTableFromCache(catalogName, schemaName, tableName, false);
        if (table != null && table.getColumnCount() < triggerHistory.getParsedColumnNames().length) {
            /*
                 * If the column count is less than what trigger history
                 * reports, then chances are the table cache is out of date.
                 */
            table = platform.getTableFromCache(catalogName, schemaName, tableName, true);
        }
        if (table != null) {
            table = table.copyAndFilterColumns(triggerHistory.getParsedColumnNames(), triggerHistory.getParsedPkColumnNames(), true);
        } else {
            throw new SymmetricException("Could not find the following table.  It might have been dropped: %s", Table.getFullyQualifiedTableName(catalogName, schemaName, tableName));
        }
    } else {
        table = new Table(tableName);
        table.addColumns(triggerHistory.getParsedColumnNames());
        table.setPrimaryKeys(triggerHistory.getParsedPkColumnNames());
    }
    Router router = triggerRouterService.getRouterById(true, routerId, false);
    if (router != null && setTargetTableName) {
        if (router.isUseSourceCatalogSchema()) {
            table.setCatalog(catalogName);
            table.setSchema(schemaName);
        } else {
            table.setCatalog(null);
            table.setSchema(null);
        }
        if (StringUtils.equals(Constants.NONE_TOKEN, router.getTargetCatalogName())) {
            table.setCatalog(null);
        } else if (StringUtils.isNotBlank(router.getTargetCatalogName())) {
            table.setCatalog(router.getTargetCatalogName());
        }
        if (StringUtils.equals(Constants.NONE_TOKEN, router.getTargetSchemaName())) {
            table.setSchema(null);
        } else if (StringUtils.isNotBlank(router.getTargetSchemaName())) {
            table.setSchema(router.getTargetSchemaName());
        }
        if (StringUtils.isNotBlank(router.getTargetTableName())) {
            table.setName(router.getTargetTableName());
        }
    }
    return table;
}
Also used : TransformTable(org.jumpmind.symmetric.io.data.transform.TransformTable) Table(org.jumpmind.db.model.Table) SymmetricException(org.jumpmind.symmetric.SymmetricException) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router)

Example 14 with SymmetricException

use of org.jumpmind.symmetric.SymmetricException in project symmetric-ds by JumpMind.

the class AbstractService method readAcks.

protected List<BatchAck> readAcks(List<OutgoingBatch> batches, IOutgoingWithResponseTransport transport, ITransportManager transportManager, IAcknowledgeService acknowledgeService) throws IOException {
    Set<Long> batchIds = new HashSet<Long>(batches.size());
    for (OutgoingBatch outgoingBatch : batches) {
        if (outgoingBatch.getStatus() == OutgoingBatch.Status.LD) {
            batchIds.add(outgoingBatch.getBatchId());
        }
    }
    BufferedReader reader = transport.readResponse();
    String ackString = reader.readLine();
    String ackExtendedString = reader.readLine();
    log.debug("Reading ack: {}", ackString);
    log.debug("Reading extend ack: {}", ackExtendedString);
    String line = null;
    do {
        line = reader.readLine();
        if (line != null) {
            log.info("Read another unexpected line {}", line);
        }
    } while (line != null);
    if (StringUtils.isBlank(ackString)) {
        throw new SymmetricException("Did not receive an acknowledgement for the batches sent.  " + "The 'ack string' was: '%s' and the 'extended ack string' was: '%s'", ackString, ackExtendedString);
    }
    List<BatchAck> batchAcks = transportManager.readAcknowledgement(ackString, ackExtendedString);
    long batchIdInError = Long.MAX_VALUE;
    for (BatchAck batchInfo : batchAcks) {
        batchIds.remove(batchInfo.getBatchId());
        if (batchInfo.getStatus() == Status.ER) {
            batchIdInError = batchInfo.getBatchId();
        }
        log.debug("Saving ack: {}, {}", batchInfo.getBatchId(), batchInfo.getStatus());
        acknowledgeService.ack(batchInfo);
    }
    for (Long batchId : batchIds) {
        if (batchId < batchIdInError) {
            log.error("We expected but did not receive an ack for batch {}", batchId);
        }
    }
    return batchAcks;
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) SymmetricException(org.jumpmind.symmetric.SymmetricException) BufferedReader(java.io.BufferedReader) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) HashSet(java.util.HashSet)

Aggregations

SymmetricException (org.jumpmind.symmetric.SymmetricException)14 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)3 Node (org.jumpmind.symmetric.model.Node)3 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)3 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Table (org.jumpmind.db.model.Table)2 IoException (org.jumpmind.exception.IoException)2 TransformTable (org.jumpmind.symmetric.io.data.transform.TransformTable)2 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)2 Router (org.jumpmind.symmetric.model.Router)2 InternalIncomingTransport (org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 ParseException (bsh.ParseException)1 TargetError (bsh.TargetError)1 DB (com.mongodb.DB)1