Search in sources :

Example 11 with ISqlTransaction

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

the class DataService method insertDataAndDataEventAndOutgoingBatch.

public void insertDataAndDataEventAndOutgoingBatch(Data data, String channelId, List<Node> nodes, String routerId, boolean isLoad, long loadId, String createBy) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        long dataId = insertData(transaction, data);
        for (Node node : nodes) {
            insertDataEventAndOutgoingBatch(transaction, dataId, channelId, node.getNodeId(), data.getDataEventType(), routerId, isLoad, loadId, createBy, Status.NE);
        }
        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);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) Node(org.jumpmind.symmetric.model.Node)

Example 12 with ISqlTransaction

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

the class DataService method insertDataGap.

public void insertDataGap(DataGap gap) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        insertDataGap(transaction, gap);
        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);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction)

Example 13 with ISqlTransaction

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

the class DataService method insertData.

public long insertData(Data data) {
    ISqlTransaction transaction = null;
    long dataId = -1;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        dataId = insertData(transaction, data);
        transaction.commit();
        return dataId;
    } 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 14 with ISqlTransaction

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

the class PostgreSqlSymmetricDialect method createRequiredDatabaseObjects.

@Override
public void createRequiredDatabaseObjects() {
    ISqlTransaction transaction = null;
    try {
        transaction = platform.getSqlTemplate().startSqlTransaction();
        enableSyncTriggers(transaction);
    } catch (Exception e) {
        String message = "Please add \"custom_variable_classes = 'symmetric'\" to your postgresql.conf file";
        log.error(message);
        throw new SymmetricException(message, e);
    } finally {
        if (transaction != null) {
            transaction.close();
        }
    }
    String triggersDisabled = this.parameterService.getTablePrefix() + "_" + "triggers_disabled";
    if (!installed(SQL_FUNCTION_INSTALLED, triggersDisabled)) {
        String sql = "CREATE or REPLACE FUNCTION $(functionName)() RETURNS INTEGER AS $$                                                                                                                     " + "                                DECLARE                                                                                                                                                                " + "                                  triggerDisabled INTEGER;                                                                                                                                             " + "                                BEGIN                                                                                                                                                                  " + "                                  select current_setting('symmetric.triggers_disabled') into triggerDisabled;                                                                                          " + "                                  return triggerDisabled;                                                                                                                                              " + "                                EXCEPTION WHEN OTHERS THEN                                                                                                                                             " + "                                  return 0;                                                                                                                                                            " + "                                END;                                                                                                                                                                   " + "                                $$ LANGUAGE plpgsql;                                                                                                                                                   ";
        install(sql, triggersDisabled);
    }
    String nodeDisabled = this.parameterService.getTablePrefix() + "_" + "node_disabled";
    if (!installed(SQL_FUNCTION_INSTALLED, nodeDisabled)) {
        String sql = "CREATE or REPLACE FUNCTION $(functionName)() RETURNS VARCHAR AS $$                                                                                                                     " + "                                DECLARE                                                                                                                                                                " + "                                  nodeId VARCHAR(50);                                                                                                                                                  " + "                                BEGIN                                                                                                                                                                  " + "                                  select current_setting('symmetric.node_disabled') into nodeId;                                                                                                       " + "                                  return nodeId;                                                                                                                                                       " + "                                EXCEPTION WHEN OTHERS THEN                                                                                                                                             " + "                                  return '';                                                                                                                                                           " + "                                END;                                                                                                                                                                   " + "                                $$ LANGUAGE plpgsql;                                                                                                                                                   ";
        install(sql, nodeDisabled);
    }
    String largeObjects = this.parameterService.getTablePrefix() + "_" + "largeobject";
    if (!installed(SQL_FUNCTION_INSTALLED, largeObjects)) {
        String sql = "CREATE OR REPLACE FUNCTION $(functionName)(objectId oid) RETURNS text AS $$                                                                                                            " + "                                DECLARE                                                                                                                                                                " + "                                  encodedBlob text;                                                                                                                                                    " + "                                  encodedBlobPage text;                                                                                                                                                " + "                                BEGIN                                                                                                                                                                  " + "                                  encodedBlob := '';                                                                                                                                                   " + "                                  FOR encodedBlobPage IN SELECT pg_catalog.encode(data, 'escape')                                                                                                                 " + "                                  FROM pg_largeobject WHERE loid = objectId ORDER BY pageno LOOP                                                                                                       " + "                                    encodedBlob := encodedBlob || encodedBlobPage;                                                                                                                     " + "                                  END LOOP;                                                                                                                                                            " + "                                  RETURN pg_catalog.encode(pg_catalog.decode(encodedBlob, 'escape'), 'base64');                                                                                                              " + "                                EXCEPTION WHEN OTHERS THEN                                                                                                                                             " + "                                  RETURN '';                                                                                                                                                           " + "                                END                                                                                                                                                                    " + "                                $$ LANGUAGE plpgsql;                                                                                                                                                   ";
        install(sql, largeObjects);
    }
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) SymmetricException(org.jumpmind.symmetric.SymmetricException) SymmetricException(org.jumpmind.symmetric.SymmetricException)

Example 15 with ISqlTransaction

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

the class NodeService method deleteNode.

public void deleteNode(String nodeId, boolean syncChange) {
    ISqlTransaction transaction = null;
    try {
        transaction = sqlTemplate.startSqlTransaction();
        if (!syncChange) {
            symmetricDialect.disableSyncTriggers(transaction, nodeId);
        }
        if (StringUtils.isNotBlank(nodeId)) {
            if (nodeId.equals(findIdentityNodeId())) {
                transaction.prepareAndExecute(getSql("deleteNodeIdentitySql"));
            }
            transaction.prepareAndExecute(getSql("deleteNodeSecuritySql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteNodeHostSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteNodeSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteNodeChannelCtlSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteIncomingErrorSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteExtractRequestSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteNodeCommunicationSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteTableReloadRequestSql"), new Object[] { nodeId, nodeId });
            transaction.prepareAndExecute(getSql("setOutgoingBatchOkSql"), new Object[] { nodeId });
            transaction.prepareAndExecute(getSql("deleteIncomingBatchSql"), new Object[] { nodeId });
        }
    } catch (Error ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } catch (RuntimeException ex) {
        if (transaction != null) {
            transaction.rollback();
        }
        throw ex;
    } finally {
        if (!syncChange) {
            symmetricDialect.enableSyncTriggers(transaction);
        }
        close(transaction);
    }
}
Also used : 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