openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1834818 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/ openjpa-project/src/doc/manual/
Date Mon, 02 Jul 2018 06:06:45 GMT
Author: ilgrosso
Date: Mon Jul  2 06:06:45 2018
New Revision: 1834818

URL: http://svn.apache.org/viewvc?rev=1834818&view=rev
Log:
[OPENPJA-2742] Rollback before DDL can be disabled - default behavior is kept

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
    openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_mapping.xml

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java?rev=1834818&r1=1834817&r2=1834818&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/ant/MappingToolTask.java
Mon Jul  2 06:06:45 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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java?rev=1834818&r1=1834817&r2=1834818&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
Mon Jul  2 06:06:45 2018
@@ -129,6 +129,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;
@@ -320,6 +321,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.
@@ -333,6 +348,7 @@ public class MappingTool
         tool.setForeignKeys(getForeignKeys());
         tool.setIndexes(getIndexes());
         tool.setSequences(getSequences());
+        tool.setRollbackBeforeDDL(getRollbackBeforeDDL());
         return tool;
     }
 
@@ -532,6 +548,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);
@@ -1011,6 +1028,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
@@ -1128,6 +1147,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++) {
@@ -1178,6 +1198,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/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java?rev=1834818&r1=1834817&r2=1834818&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
Mon Jul  2 06:06:45 2018
@@ -114,6 +114,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;
@@ -235,6 +236,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() {
@@ -1335,23 +1350,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]);
 
@@ -1377,7 +1397,7 @@ public class SchemaTool {
                 }
             }
             finally {
-                if (!wasAuto) {
+                if (_rollbackBeforeDDL && !wasAuto) {
                     conn.setAutoCommit(false);
                 }
 
@@ -1445,6 +1465,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 &lt;true/t | false/f&gt;</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 &lt;true/t | false/f&gt;</i>: Whether
primary
      * keys on existing tables are manipulated. Defaults to true.</li>
      * <li><i>-foreignKeys/-fk &lt;true/t | false/f&gt;</i>: Whether
foreign
@@ -1539,6 +1562,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
@@ -1654,6 +1679,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);
@@ -1692,6 +1718,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;

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml?rev=1834818&r1=1834817&r2=1834818&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_dbsetup.xml Mon Jul  2 06:06:45
2018
@@ -5448,6 +5448,12 @@ dropped. Defaults to <literal>false</lit
             </listitem>
             <listitem>
                 <para>
+<literal>-rollbackBeforeDDL/-rbddl &lt;true/t | false/f&gt;</literal>:
Set this option to
+<literal>true</literal> to send an initail rollback on the connection before
any DDL statement is sent.
+                </para>
+            </listitem>
+            <listitem>
+                <para>
 <literal>-dropTables/-dt &lt;true/t | false/f&gt;</literal>: Set this
option to
 <literal>true</literal> to drop tables that appear to be unused during <literal>
 retain</literal> and <literal>refresh</literal> actions. Defaults to <literal>

Modified: openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_mapping.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_mapping.xml?rev=1834818&r1=1834817&r2=1834818&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_mapping.xml (original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/ref_guide_mapping.xml Mon Jul  2 06:06:45
2018
@@ -138,6 +138,12 @@ same-named option on the schema tool.
             </listitem>
             <listitem>
                 <para>
+<literal>-rollbackBeforeDDL/-rbddl &lt;true/t | false/f&gt;</literal>:
Corresponds to the
+same-named option on the schema tool.
+                </para>
+            </listitem>
+            <listitem>
+                <para>
 <literal>-dropSequences/-dsq &lt;true/t | false/f&gt;</literal>: Corresponds
to
 the same-named option on the schema tool.
                 </para>



Mime
View raw message