openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r897056 - in /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc: schema/SchemaGroup.java schema/SchemaTool.java sql/DB2Dictionary.java sql/DBDictionary.java
Date Thu, 07 Jan 2010 23:42:33 GMT
Author: faywang
Date: Thu Jan  7 23:42:31 2010
New Revision: 897056

URL: http://svn.apache.org/viewvc?rev=897056&view=rev
Log:
OPENJPA-1455: fix add column problem involving tables with same name in multiple schemas for
DB2

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaTool.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java?rev=897056&r1=897055&r2=897056&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGroup.java
Thu Jan  7 23:42:31 2010
@@ -209,6 +209,14 @@
      * separator. Returns null if no table found.
      */
     public Table findTable(Schema inSchema, String name) {
+        return findTable(inSchema, name, null);
+    }
+    
+    /**
+     * Find the table with the given name in the group, using '.' as the catalog
+     * separator. Returns null if no table found.
+     */
+    public Table findTable(Schema inSchema, String name, String defaultSchemaName) {
         if (name == null)
             return null;
 
@@ -231,8 +239,14 @@
                 // We can't handle the case that one entity has schema name
                 // and other entity does not have schema name but both entities
                 // map to the same table.
+                boolean isDefaultSchema = inSchema.getName() == null && 
+                    defaultSchemaName != null && 
+                    defaultSchemaName.equalsIgnoreCase(schemas[i].getName());
+                boolean hasNoDefaultSchema = inSchema.getName() == null && 
+                    defaultSchemaName == null; 
+                
                 if (tab != null &&
-                        (schemas[i] == inSchema || inSchema.getName() == null))
+                    (schemas[i] == inSchema || isDefaultSchema || hasNoDefaultSchema)) 
                     return tab;
 
             }

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=897056&r1=897055&r2=897056&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
Thu Jan  7 23:42:31 2010
@@ -472,11 +472,12 @@
         Column[] cols;
         Column col;
         String delim = _dict.getDelimiter();
+        String defaultSchemaName = _dict.getDefaultSchemaName();
         for (int i = 0; i < schemas.length; i++) {
             tabs = schemas[i].getTables();
             for (int j = 0; j < tabs.length; j++) {
                 cols = tabs[j].getColumns();
-                dbTable = db.findTable(schemas[i], tabs[j].getFullName());
+                dbTable = db.findTable(schemas[i], tabs[j].getFullName(), defaultSchemaName);
                 for (int k = 0; k < cols.length; k++) {
                     if (dbTable != null) {
                         String colName = cols[k].getName();

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=897056&r1=897055&r2=897056&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu Jan  7 23:42:31 2010
@@ -266,6 +266,7 @@
         super.connectedConfiguration(conn);
 
         DatabaseMetaData metaData = conn.getMetaData();
+        setDefaultSchemaName(metaData.getUserName());
         String driverName = metaData.getDriverName();
         if (driverName != null && driverName.startsWith("IBM DB2"))
             driverVendor = VENDOR_IBM;

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=897056&r1=897055&r2=897056&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Thu Jan  7 23:42:31 2010
@@ -362,6 +362,7 @@
     public String delimiter = "\""; // This is public so it can be changed by a user with
a property
     // Assume mixed case by default.
     protected String delimitedCase = SCHEMA_CASE_PRESERVE;
+    private String defaultSchemaName = null;
     
     public static enum DBIdentifiers {
         TABLE_NAME,
@@ -5212,4 +5213,12 @@
     public Log getLog() { 
         return log;
     }
+    
+    public void setDefaultSchemaName(String defaultSchemaName) {
+        this.defaultSchemaName = defaultSchemaName;
+    }
+
+    public String getDefaultSchemaName() {
+        return defaultSchemaName;
+    }
 }



Mime
View raw message