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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations