Navigation Menu

Skip to content

Commit

Permalink
0003366: Support transactional sync triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 17, 2018
1 parent ad645c8 commit 0890365
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
Expand Up @@ -178,7 +178,7 @@ public void dropTables(boolean continueOnError, Table... tables) {

public void dropDatabase(Database database, boolean continueOnError) {
String sql = ddlBuilder.dropTables(database);
new SqlScript(sql, getSqlTemplate(), !continueOnError, null).execute(continueOnError ? true : getDatabaseInfo().isRequiresAutoCommitForDdl());
new SqlScript(sql, getSqlTemplate(), !continueOnError, null).execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
}

public void createTables(boolean dropTablesFirst, boolean continueOnError, Table... tables) {
Expand All @@ -200,7 +200,7 @@ public void createDatabase(Database targetDatabase, boolean dropTablesFirst, boo

String delimiter = getDdlBuilder().getDatabaseInfo().getSqlCommandDelimiter();
new SqlScript(createSql, getSqlTemplate(), !continueOnError, false, false, delimiter, null)
.execute(continueOnError ? true : getDatabaseInfo().isRequiresAutoCommitForDdl());
.execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
}

public void alterDatabase(Database desiredDatabase, boolean continueOnError) {
Expand Down Expand Up @@ -231,7 +231,7 @@ public void alterTables(boolean continueOnError, Table... desiredTables) {
log.info("Running alter sql:\n{}", alterSql);
String delimiter = getDdlBuilder().getDatabaseInfo().getSqlCommandDelimiter();
new SqlScript(alterSql, getSqlTemplate(), !continueOnError, false, false, delimiter, null)
.execute(continueOnError ? true : getDatabaseInfo().isRequiresAutoCommitForDdl());
.execute(getDatabaseInfo().isRequiresAutoCommitForDdl());
} else {
log.info("Tables up to date. No alters found for {}", tablesProcessed);
}
Expand Down Expand Up @@ -1079,18 +1079,17 @@ public boolean isUseMultiThreadSyncTriggers() {

@Override
public boolean supportsTransactions() {
if (supportsTransactions == null) {
if (this.getDataSource() instanceof DataSource) {
try {
supportsTransactions = ((DataSource) this.getDataSource()).getConnection().getMetaData().supportsTransactions();
}
catch (Exception e) {
log.warn("Unable to determine if transactions are supported from connection meta data ", e);
}
} else {
supportsTransactions = true;
}
}
return supportsTransactions;
}
if (supportsTransactions == null) {
if (this.getDataSource() instanceof DataSource) {
try {
supportsTransactions = ((DataSource) this.getDataSource()).getConnection().getMetaData().supportsTransactions();
} catch (Exception e) {
log.warn("Unable to determine if transactions are supported from connection meta data ", e);
}
} else {
supportsTransactions = true;
}
}
return supportsTransactions;
}
}
10 changes: 9 additions & 1 deletion symmetric-db/src/main/java/org/jumpmind/db/sql/SqlScript.java
Expand Up @@ -28,12 +28,16 @@
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class parses and runs SQL from an input file or buffer using the
* designed {@link ISqlTemplate}.
*/
public class SqlScript {

final static Logger log = LoggerFactory.getLogger(SqlScript.class);

private ISqlTemplate sqlTemplate;

Expand Down Expand Up @@ -102,8 +106,12 @@ public long execute() {
return execute(false);
}

public long execute(final boolean autoCommit) {
public long execute(boolean autoCommit) {
try {
if (!autoCommit && (!failOnDrop || !failOnError || !failOnSequenceCreate)) {
log.debug("Autocommit was set to false, however either failOnDrop({}) or failOnError({}) or failOnSequenceCreate({}) were set to false which means that autoCommit needs to be enabled. We are setting it to true", failOnDrop, failOnError, failOnSequenceCreate);
autoCommit = true;
}
long count = this.sqlTemplate.update(autoCommit, failOnError, failOnDrop, failOnSequenceCreate,
commitRate, this.resultsListener, this.scriptReader);
return count;
Expand Down

0 comments on commit 0890365

Please sign in to comment.