This is an automated email from the ASF dual-hosted git repository.

struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit c6f42826b72940aa771a394d42173b2f7fec0428
Author: Mark Struberg <strub...@apache.org>
AuthorDate: Tue Jun 15 16:33:31 2021 +0200

    OPENJPA-2876 fix schema 'refresh'
    
    Also had to fix the schema handling via persistence.xml.
    Thinkfully this section has excellent unit test coverage.
---
 openjpa-examples/image-gallery/pom.xml             |  5 +++++
 openjpa-examples/openbooks/pom.xml                 |  5 +++++
 .../openjpa/jdbc/kernel/JDBCBrokerFactory.java     | 22 +++++++++-------------
 .../org/apache/openjpa/jdbc/meta/MappingTool.java  | 11 +++--------
 .../org/apache/openjpa/jdbc/schema/SchemaTool.java | 16 ++++------------
 5 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/openjpa-examples/image-gallery/pom.xml 
b/openjpa-examples/image-gallery/pom.xml
index 2c2107a..4b3f159 100644
--- a/openjpa-examples/image-gallery/pom.xml
+++ b/openjpa-examples/image-gallery/pom.xml
@@ -60,6 +60,11 @@
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-simple</artifactId>
     </dependency>
+    <dependency>
+      <groupId>com.sun.xml.bind</groupId>
+      <artifactId>jaxb-impl</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/openjpa-examples/openbooks/pom.xml 
b/openjpa-examples/openbooks/pom.xml
index 01a8836..d4ef913 100644
--- a/openjpa-examples/openbooks/pom.xml
+++ b/openjpa-examples/openbooks/pom.xml
@@ -75,6 +75,11 @@
             <artifactId>mysql-connector-java</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>com.sun.xml.bind</groupId>
+            <artifactId>jaxb-impl</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
index ecf0f8c..fe9baad 100644
--- 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
+++ 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCBrokerFactory.java
@@ -25,11 +25,6 @@ import static 
org.apache.openjpa.conf.SchemaGenerationSource.METADATA;
 import static 
org.apache.openjpa.conf.SchemaGenerationSource.METADATA_THEN_SCRIPT;
 import static org.apache.openjpa.conf.SchemaGenerationSource.SCRIPT;
 import static 
org.apache.openjpa.conf.SchemaGenerationSource.SCRIPT_THEN_METADATA;
-import static org.apache.openjpa.jdbc.meta.MappingTool.ACTION_ADD;
-import static org.apache.openjpa.jdbc.meta.MappingTool.ACTION_DROP;
-import static org.apache.openjpa.jdbc.meta.MappingTool.ACTION_SCRIPT_CREATE;
-import static org.apache.openjpa.jdbc.meta.MappingTool.ACTION_SCRIPT_DROP;
-import static org.apache.openjpa.jdbc.meta.MappingTool.ACTION_SCRIPT_LOAD;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -40,6 +35,7 @@ import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
 import org.apache.openjpa.jdbc.meta.MappingRepository;
 import org.apache.openjpa.jdbc.meta.MappingTool;
+import org.apache.openjpa.jdbc.schema.SchemaTool;
 import org.apache.openjpa.kernel.AbstractBrokerFactory;
 import org.apache.openjpa.kernel.Bootstrap;
 import org.apache.openjpa.kernel.BrokerImpl;
@@ -197,7 +193,7 @@ public class JDBCBrokerFactory extends 
AbstractBrokerFactory {
 
         String loadFile = conf.getLoadScriptSource();
         if (loadFile != null) {
-            actions += "," + ACTION_SCRIPT_LOAD;
+            actions += "," + MappingTool.ACTION_SCRIPT_LOAD;
         }
 
         if (actions.length() > 0) {
@@ -207,7 +203,7 @@ public class JDBCBrokerFactory extends 
AbstractBrokerFactory {
 
     private String generateSchemaCreation(JDBCConfiguration conf) {
         if (conf.getCreateScriptTarget() != null) {
-            return MappingTool.ACTION_ADD;
+            return SchemaTool.ACTION_BUILD;
         } else {
             int createSource = conf.getCreateSourceConstant();
             if (createSource == SchemaGenerationSource.NONE && 
conf.getCreateScriptSource() != null) {
@@ -215,13 +211,13 @@ public class JDBCBrokerFactory extends 
AbstractBrokerFactory {
             } else {
                 createSource = METADATA;
             }
-            return mapGenerationStrategyActions(createSource, ACTION_ADD, 
ACTION_SCRIPT_CREATE);
+            return mapGenerationStrategyActions(createSource, 
SchemaTool.ACTION_ADD, MappingTool.ACTION_SCRIPT_CREATE);
         }
     }
 
     private String generateSchemaDrop(JDBCConfiguration conf) {
         if (conf.getDropScriptTarget() != null) {
-            return MappingTool.ACTION_DROP;
+            return SchemaTool.ACTION_DROP;
         } else {
             int dropSource = conf.getDropSourceConstant();
             if (dropSource == SchemaGenerationSource.NONE && 
conf.getDropScriptSource() != null) {
@@ -229,16 +225,16 @@ public class JDBCBrokerFactory extends 
AbstractBrokerFactory {
             } else {
                 dropSource = METADATA;
             }
-            return mapGenerationStrategyActions(dropSource, ACTION_DROP, 
ACTION_SCRIPT_DROP);
+            return mapGenerationStrategyActions(dropSource, 
SchemaTool.ACTION_DROP, MappingTool.ACTION_SCRIPT_DROP);
         }
     }
 
     private String generateSchemaDropCreate(JDBCConfiguration conf) {
         if (conf.getCreateScriptTarget() != null && conf.getDropScriptTarget() 
!= null) {
-            return MappingTool.ACTION_ADD + "," + MappingTool.ACTION_DROP;
+            return SchemaTool.ACTION_BUILD + "," + SchemaTool.ACTION_DROP;
         } else {
-            return mapGenerationStrategyActions(conf.getDropSourceConstant(), 
ACTION_DROP, ACTION_SCRIPT_DROP) + "," +
-                   
mapGenerationStrategyActions(conf.getCreateSourceConstant(), ACTION_ADD, 
ACTION_SCRIPT_CREATE);
+            return mapGenerationStrategyActions(conf.getDropSourceConstant(), 
SchemaTool.ACTION_DROP, MappingTool.ACTION_SCRIPT_DROP) + "," +
+                   
mapGenerationStrategyActions(conf.getCreateSourceConstant(), 
SchemaTool.ACTION_ADD, MappingTool.ACTION_SCRIPT_CREATE);
         }
     }
 
diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
index 246cc89..4d7561b 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingTool.java
@@ -534,14 +534,14 @@ public class MappingTool
                             tool = newSchemaTool(schemaAction);
                         }
 
-                        if (schemaAction.equals(ACTION_ADD) && 
_conf.getCreateScriptTarget() != null) {
+                        if (schemaAction.equals(SchemaTool.ACTION_BUILD) && 
_conf.getCreateScriptTarget() != null) {
                             tool.setWriter(new 
PrintWriter(_conf.getCreateScriptTarget()));
                             tool.setIndexes(true);
                             tool.setForeignKeys(true);
                             tool.setSequences(true);
                         }
 
-                        if (schemaAction.equals(ACTION_DROP) && 
_conf.getDropScriptTarget() != null) {
+                        if (schemaAction.equals(SchemaTool.ACTION_DROP) && 
_conf.getDropScriptTarget() != null) {
                             tool.setWriter(new 
PrintWriter(_conf.getDropScriptTarget()));
                         }
 
@@ -1134,12 +1134,7 @@ public class MappingTool
             return false;
         }
 
-        MappingTool tool;
-        try {
-            tool = new MappingTool(conf, flags.action, flags.meta, loader);
-        } catch (IllegalArgumentException iae) {
-            return false;
-        }
+        MappingTool tool = new MappingTool(conf, flags.action, flags.meta, 
loader);
 
         // setup the tool
         tool.setIgnoreErrors(flags.ignoreErrors);
diff --git 
a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java 
b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
index 6abe8cd..d42c5ea 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
@@ -575,9 +575,7 @@ public class SchemaTool {
                 seqs = value.getSequences();
                 for (Sequence seq : seqs) {
                     if (considerDatabaseState && db.findSequence(value, 
seq.getQualifiedPath()) != null) {
-                        if (_writer == null) {
-                            continue;
-                        }
+                        continue;
                     }
 
                     if (createSequence(seq)) {
@@ -656,9 +654,7 @@ public class SchemaTool {
             tabs = schema1.getTables();
             for (Table tab : tabs) {
                 if (considerDatabaseState && db.findTable(schema1, 
tab.getQualifiedPath()) != null) {
-                    if (_writer == null) {
-                        continue;
-                    }
+                    continue;
                 }
 
                 if (createTable(tab)) {
@@ -712,9 +708,7 @@ public class SchemaTool {
             for (Table tab : tabs) {
                 // create unique constraints only on new tables
                 if (!newTables.contains(tab)) {
-                    if (_writer == null) {
-                        continue;
-                    }
+                    continue;
                 }
 
                 uniques = tab.getUniques();
@@ -740,9 +734,7 @@ public class SchemaTool {
                 // create foreign keys on new tables even if fks
                 // have been turned off
                 if (!_fks && !newTables.contains(tab)) {
-                    if (_writer == null) {
-                        continue;
-                    }
+                    continue;
                 }
 
                 fks = tab.getForeignKeys();

Reply via email to