You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by il...@apache.org on 2018/07/02 06:08:46 UTC
svn commit: r1834819 - in
/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc:
ant/MappingToolTask.java meta/MappingTool.java schema/SchemaTool.java
Author: ilgrosso
Date: Mon Jul 2 06:08:46 2018
New Revision: 1834819
URL: http://svn.apache.org/viewvc?rev=1834819&view=rev
Log:
[OPENPJA-2742] Rollback before DDL can be disabled - default behavior is kept
Modified:
openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
Modified: openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java?rev=1834819&r1=1834818&r2=1834819&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java (original)
+++ openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java Mon Jul 2 06:08:46 2018
@@ -40,6 +40,7 @@ import org.apache.openjpa.util.MultiLoad
* <li><code>action</code></li>
* <li><code>meta</code></li>
* <li><code>schemaAction</code></li>
+ * <li><code>rollbackBeforeDDL</code></li>
* <li><code>dropTables</code></li>
* <li><code>ignoreErrors</code></li>
* <li><code>readSchema</code></li>
@@ -102,6 +103,13 @@ public class MappingToolTask
}
/**
+ * Set whether the MappingTool should rollback will be performed before each DDL statement is executed.
+ */
+ public void setRollbackBeforeDDL(boolean rollbackBeforeDDL) {
+ flags.rollbackBeforeDDL = rollbackBeforeDDL;
+ }
+
+ /**
* Set whether to drop OpenJPA tables.
*/
public void setOpenJPATables(boolean openjpaTables) {
Modified: openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=1834819&r1=1834818&r2=1834819&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java (original)
+++ openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java Mon Jul 2 06:08:46 2018
@@ -123,6 +123,7 @@ public class MappingTool
private boolean _seqs = true;
private boolean _dropUnused = true;
private boolean _ignoreErrors = false;
+ private boolean _rollbackBeforeDDL = false;
private File _file = null;
private Writer _mappingWriter = null;
private Writer _schemaWriter = null;
@@ -314,6 +315,20 @@ public class MappingTool
public boolean getIgnoreErrors() {
return _ignoreErrors;
}
+
+ /**
+ * If true, rollback will be performed before each DDL statement is executed. Defaults to true.
+ */
+ public boolean getRollbackBeforeDDL() {
+ return _rollbackBeforeDDL;
+ }
+
+ /**
+ * If true, rollback will be performed before each DDL statement is executed. Defaults to true.
+ */
+ public void setRollbackBeforeDDL(boolean rollbackBeforeDDL) {
+ _rollbackBeforeDDL = rollbackBeforeDDL;
+ }
/**
* Return the schema tool to use for schema modification.
@@ -327,6 +342,7 @@ public class MappingTool
tool.setForeignKeys(getForeignKeys());
tool.setIndexes(getIndexes());
tool.setSequences(getSequences());
+ tool.setRollbackBeforeDDL(getRollbackBeforeDDL());
return tool;
}
@@ -507,6 +523,7 @@ public class MappingTool
// configure the tool with additional settings
if (flags != null) {
tool.setDropTables(flags.dropTables);
+ tool.setRollbackBeforeDDL(flags.rollbackBeforeDDL);
tool.setDropSequences(flags.dropSequences);
tool.setWriter(flags.sqlWriter);
tool.setOpenJPATables(flags.openjpaTables);
@@ -974,6 +991,8 @@ public class MappingTool
flags.schemaAction);
flags.dropTables = opts.removeBooleanProperty
("dropTables", "dt", flags.dropTables);
+ flags.rollbackBeforeDDL = opts.removeBooleanProperty
+ ("rollbackBeforeDDL", "rbddl", flags.rollbackBeforeDDL);
flags.openjpaTables = opts.removeBooleanProperty
("openjpaTables", "ot", flags.openjpaTables);
flags.dropSequences = opts.removeBooleanProperty
@@ -1091,6 +1110,7 @@ public class MappingTool
tool.setForeignKeys(flags.foreignKeys);
tool.setIndexes(flags.indexes);
tool.setSequences(flags.sequences || flags.dropSequences);
+ tool.setRollbackBeforeDDL(flags.rollbackBeforeDDL);
// and run the action
for (int i = 0; i < act.length; i++) {
@@ -1141,6 +1161,7 @@ public class MappingTool
public boolean ignoreErrors = false;
public boolean readSchema = false;
public boolean dropTables = false;
+ public boolean rollbackBeforeDDL = false;
public boolean openjpaTables = false;
public boolean dropSequences = false;
public boolean sequences = true;
Modified: openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java?rev=1834819&r1=1834818&r2=1834819&view=diff
==============================================================================
--- openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java (original)
+++ openjpa/branches/2.4.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java Mon Jul 2 06:08:46 2018
@@ -105,6 +105,7 @@ public class SchemaTool {
private boolean _fks = true;
private boolean _indexes = true;
private boolean _seqs = true;
+ private boolean _rollbackBeforeDDL = true;
private PrintWriter _writer = null;
private SchemaGroup _group = null;
private SchemaGroup _db = null;
@@ -225,6 +226,20 @@ public class SchemaTool {
}
/**
+ * If true, rollback will be performed before each DDL statement is executed. Defaults to true.
+ */
+ public boolean getRollbackBeforeDDL() {
+ return _rollbackBeforeDDL;
+ }
+
+ /**
+ * If true, rollback will be performed before each DDL statement is executed. Defaults to true.
+ */
+ public void setRollbackBeforeDDL(boolean rollbackBeforeDDL) {
+ _rollbackBeforeDDL = rollbackBeforeDDL;
+ }
+
+ /**
* Whether sequences should be manipulated. Defaults to true.
*/
public boolean getSequences() {
@@ -1251,23 +1266,28 @@ public class SchemaTool {
Statement statement = null;
boolean wasAuto = true;
try {
- wasAuto = conn.getAutoCommit();
- if (!wasAuto)
- conn.setAutoCommit(true);
+ if (_rollbackBeforeDDL) {
+ wasAuto = conn.getAutoCommit();
+ if (!wasAuto) {
+ conn.setAutoCommit(true);
+ }
+ }
for (int i = 0; i < sql.length; i++) {
try {
- // some connections require that rollback be
- // called on the connection before any DDL statements
- // can be run on it, even when autocommit is on.
- // This is sometimes because the connection does not
- // allow DDL statements when there are multiple
- // commands issued on the connection, and the
- // connection pool may have issued some validation SQL.
- try {
- conn.rollback();
- } catch (Exception e) {
+ if (_rollbackBeforeDDL) {
+ // some connections require that rollback be
+ // called on the connection before any DDL statements
+ // can be run on it, even when autocommit is on.
+ // This is sometimes because the connection does not
+ // allow DDL statements when there are multiple
+ // commands issued on the connection, and the
+ // connection pool may have issued some validation SQL.
+ try {
+ conn.rollback();
+ } catch (Exception e) {
+ }
}
-
+
statement = conn.createStatement();
statement.executeUpdate(sql[i]);
@@ -1293,7 +1313,7 @@ public class SchemaTool {
}
}
finally {
- if (!wasAuto) {
+ if (_rollbackBeforeDDL && !wasAuto) {
conn.setAutoCommit(false);
}
@@ -1361,6 +1381,9 @@ public class SchemaTool {
* to true to drop sequences that appear to be unused during
* <code>retain</code> and <code>refresh</code> actions. Defaults to
* <code>true</code>.</li>
+ * <li><i>-rollbackBeforeDDL/-rbddl <true/t | false/f></i>: Set this option
+ * to true to send an initail rollback on the connection before any DDL statement
+ * is sent</li>
* <li><i>-primaryKeys/-pk <true/t | false/f></i>: Whether primary
* keys on existing tables are manipulated. Defaults to true.</li>
* <li><i>-foreignKeys/-fk <true/t | false/f></i>: Whether foreign
@@ -1455,6 +1478,8 @@ public class SchemaTool {
("dropTables", "dt", flags.dropTables);
flags.dropSequences = opts.removeBooleanProperty
("dropSequences", "dsq", flags.dropSequences);
+ flags.rollbackBeforeDDL = opts.removeBooleanProperty
+ ("rollbackBeforeDDL", "rbddl", flags.rollbackBeforeDDL);
flags.ignoreErrors = opts.removeBooleanProperty
("ignoreErrors", "i", flags.ignoreErrors);
flags.openjpaTables = opts.removeBooleanProperty
@@ -1570,6 +1595,7 @@ public class SchemaTool {
tool.setDropTables(flags.dropTables);
tool.setSequences(flags.sequences); // set before dropseqs
tool.setDropSequences(flags.dropSequences);
+ tool.setRollbackBeforeDDL(flags.rollbackBeforeDDL);
tool.setPrimaryKeys(flags.primaryKeys);
tool.setForeignKeys(flags.foreignKeys);
tool.setIndexes(flags.indexes);
@@ -1608,6 +1634,7 @@ public class SchemaTool {
public String action = ACTION_ADD;
public Writer writer = null;
public boolean dropTables = true;
+ public boolean rollbackBeforeDDL = true;
public boolean dropSequences = true;
public boolean ignoreErrors = false;
public boolean openjpaTables = false;