Search in sources :

Example 1 with UniqueKeyException

use of org.jumpmind.db.sql.UniqueKeyException in project symmetric-ds by JumpMind.

the class IncomingBatchService method acquireIncomingBatch.

public boolean acquireIncomingBatch(IncomingBatch batch) {
    boolean okayToProcess = true;
    if (batch.isPersistable()) {
        IncomingBatch existingBatch = null;
        if (isRecordOkBatchesEnabled()) {
            try {
                insertIncomingBatch(batch);
            } catch (UniqueKeyException e) {
                batch.setRetry(true);
                existingBatch = findIncomingBatch(batch.getBatchId(), batch.getNodeId());
            }
        } else {
            existingBatch = findIncomingBatch(batch.getBatchId(), batch.getNodeId());
            if (existingBatch != null) {
                batch.setRetry(true);
            }
        }
        if (batch.isRetry()) {
            if (existingBatch.getStatus() == Status.ER || existingBatch.getStatus() == Status.LD || existingBatch.getStatus() == Status.RS || !parameterService.is(ParameterConstants.INCOMING_BATCH_SKIP_DUPLICATE_BATCHES_ENABLED)) {
                okayToProcess = true;
                existingBatch.setStatus(Status.LD);
                log.info("Retrying batch {}", batch.getNodeBatchId());
            } else if (existingBatch.getStatus() == Status.IG) {
                okayToProcess = false;
                batch.setStatus(Status.OK);
                batch.incrementIgnoreCount();
                existingBatch.setStatus(Status.OK);
                existingBatch.incrementIgnoreCount();
                log.info("Ignoring batch {}", batch.getNodeBatchId());
            } else {
                okayToProcess = false;
                batch.setStatus(existingBatch.getStatus());
                batch.setByteCount(existingBatch.getByteCount());
                batch.setDatabaseMillis(existingBatch.getDatabaseMillis());
                batch.setNetworkMillis(existingBatch.getNetworkMillis());
                batch.setFilterMillis(existingBatch.getFilterMillis());
                batch.setSkipCount(existingBatch.getSkipCount() + 1);
                batch.setStatementCount(existingBatch.getStatementCount());
                existingBatch.setSkipCount(existingBatch.getSkipCount() + 1);
                log.info("Skipping batch {}", batch.getNodeBatchId());
            }
            updateIncomingBatch(existingBatch);
        }
    }
    return okayToProcess;
}
Also used : UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 2 with UniqueKeyException

use of org.jumpmind.db.sql.UniqueKeyException in project symmetric-ds by JumpMind.

the class DataService method insertCreateEvent.

public void insertCreateEvent(ISqlTransaction transaction, Node targetNode, TriggerHistory triggerHistory, String routerId, boolean isLoad, long loadId, String createBy) {
    Trigger trigger = engine.getTriggerRouterService().getTriggerById(triggerHistory.getTriggerId(), false);
    String reloadChannelId = getReloadChannelIdForTrigger(trigger, engine.getConfigurationService().getChannels(false));
    Data data = new Data(triggerHistory.getSourceTableName(), DataEventType.CREATE, null, null, triggerHistory, isLoad ? reloadChannelId : Constants.CHANNEL_CONFIG, null, null);
    data.setNodeList(targetNode.getNodeId());
    try {
        if (isLoad) {
            insertDataAndDataEventAndOutgoingBatch(transaction, data, targetNode.getNodeId(), routerId, isLoad, loadId, createBy, Status.NE);
        } else {
            insertData(transaction, data);
        }
    } catch (UniqueKeyException e) {
        if (e.getRootCause() != null && e.getRootCause() instanceof DataTruncation) {
            log.error("Table data definition XML was too large and failed.  The feature to send table creates during the initial load may be limited on your platform.  You may need to set the initial.load.create.first parameter to false.");
        }
        throw e;
    }
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException) Data(org.jumpmind.symmetric.model.Data) CsvData(org.jumpmind.symmetric.io.data.CsvData) DataTruncation(java.sql.DataTruncation)

Example 3 with UniqueKeyException

use of org.jumpmind.db.sql.UniqueKeyException in project symmetric-ds by JumpMind.

the class NodeService method findOrCreateNodeSecurity.

public NodeSecurity findOrCreateNodeSecurity(String nodeId) {
    try {
        if (nodeId != null) {
            NodeSecurity security = findNodeSecurity(nodeId, false);
            if (security == null) {
                insertNodeSecurity(nodeId);
                security = findNodeSecurity(nodeId, true);
            }
            return security;
        } else {
            log.debug("A 'null' node id was passed into findNodeSecurity");
            return null;
        }
    } catch (UniqueKeyException ex) {
        log.error("Could not find a node security row for '{}'", nodeId);
        throw ex;
    }
}
Also used : NodeSecurity(org.jumpmind.symmetric.model.NodeSecurity) UniqueKeyException(org.jumpmind.db.sql.UniqueKeyException)

Aggregations

UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)3 DataTruncation (java.sql.DataTruncation)1 CsvData (org.jumpmind.symmetric.io.data.CsvData)1 Data (org.jumpmind.symmetric.model.Data)1 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 Trigger (org.jumpmind.symmetric.model.Trigger)1