openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r639681 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java openjpa-persistence-jdbc/pom.xml openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Date Fri, 21 Mar 2008 15:48:34 GMT
Author: mikedd
Date: Fri Mar 21 08:48:30 2008
New Revision: 639681

URL: http://svn.apache.org/viewvc?rev=639681&view=rev
Log:
OPENJPA-528 committing patch provided by Jeremy Bauer

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
    openjpa/trunk/openjpa-persistence-jdbc/pom.xml
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java

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=639681&r1=639680&r2=639681&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
Fri Mar 21 08:48:30 2008
@@ -2812,12 +2812,24 @@
 
     /**
      * Make any necessary changes to the given column name to make it valid
-     * for the current DB.
+     * for the current DB.  The column name will be made unique for the
+     * specified table.
      */
     public String getValidColumnName(String name, Table table) {
+        return getValidColumnName(name, table, true);
+    }
+
+    /**
+     * Make any necessary changes to the given column name to make it valid
+     * for the current DB.  If checkForUniqueness is true, the column name will 
+     * be made unique for the specified table.
+     */
+    public String getValidColumnName(String name, Table table,
+        boolean checkForUniqueness) {
         while (name.startsWith("_"))
             name = name.substring(1);
-        return makeNameValid(name, table, maxColumnNameLength, NAME_ANY);
+        return makeNameValid(name, table, maxColumnNameLength, NAME_ANY,
+            checkForUniqueness);
     }
 
     /**
@@ -2924,6 +2936,20 @@
      */
     protected String makeNameValid(String name, NameSet set, int maxLen,
         int nameType) {
+        return makeNameValid(name, set, maxLen, nameType, true);
+    }
+
+    /**
+     * Shortens the given name to the given maximum length, then checks that
+     * it is not a reserved word. If it is reserved, appends a "0". If
+     * the name conflicts with an existing schema component and uniqueness
+     * checking is enabled, the last character is replace with '0', then 
+     * '1', etc. 
+     * Note that the given max len may be 0 if the database metadata is 
+     * incomplete.
+     */
+    protected String makeNameValid(String name, NameSet set, int maxLen,
+        int nameType, boolean checkForUniqueness) {
         if (maxLen < 1)
             maxLen = 255;
         if (name.length() > maxLen)
@@ -2935,7 +2961,7 @@
         }
 
         // now make sure the name is unique
-        if (set != null) {
+        if (set != null && checkForUniqueness) {
             outer:
             for (int version = 1, chars = 1; true; version++) {
                 // for table names, we check for the table itself in case the

Modified: openjpa/trunk/openjpa-persistence-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/pom.xml?rev=639681&r1=639680&r2=639681&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/pom.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/pom.xml Fri Mar 21 08:48:30 2008
@@ -481,8 +481,6 @@
                         <exclude>org/apache/openjpa/persistence/meta/TestValueStrategies.java</exclude>
                         <exclude>org/apache/openjpa/persistence/meta/TestXMLPersistenceMetaDataSerializer.java</exclude>
                   
-                        <!--  Exclude until root cause of TCK problem is found. -->
-                        <exclude>org/apache/openjpa/persistence/jdbc/TestFKColumnNames.java</exclude>
                     </excludes>
                     <systemProperties>
                         <property>

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=639681&r1=639680&r2=639681&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
Fri Mar 21 08:48:30 2008
@@ -18,7 +18,6 @@
  */
 package org.apache.openjpa.persistence.jdbc;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.Discriminator;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
@@ -192,8 +191,10 @@
             if (isRemoveHungarianNotation())
                 name = removeHungarianNotation(name);
 
-            name = dict.getValidColumnName(name, local);
-            col.setName(name + "_" + ((Column) target).getName());
+            name = name + "_" + ((Column) target).getName();
+            // No need to check for uniqueness.
+            name = dict.getValidColumnName(name, local, false);
+            col.setName(name);
         }
     }
 



Mime
View raw message