openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r1102047 - in /openjpa/branches/2.1.x/openjpa-jdbc/src: main/java/org/apache/openjpa/jdbc/schema/Table.java main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
Date Wed, 11 May 2011 19:34:21 GMT
Author: mikedd
Date: Wed May 11 19:34:20 2011
New Revision: 1102047

URL: http://svn.apache.org/viewvc?rev=1102047&view=rev
Log:
OPENJPA-1725: Do not include schema name when checking table name length. Merged from trunk

Added:
    openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
      - copied, changed from r1101243, openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
Modified:
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
    openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java?rev=1102047&r1=1102046&r2=1102047&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/Table.java
Wed May 11 19:34:20 2011
@@ -178,12 +178,18 @@ public class Table
     /**
      * Set the name of the table. This method can only be called on tables
      * that are not part of a schema.
-     * @deprecated
+     * @deprecated use {@link #setIdentifier(DBIdentifier)} instead.
      */
+    @Deprecated
     public void setName(String name) {
         setIdentifier(DBIdentifier.newTable(name));
     }
 
+    /**
+     * Set the name of the table. This method can only be called on tables which are not
part of a schema. 
+     * @param name The name of the table. 
+     * @throws IllegalStateException if {@link #getSchema()} does not return null. 
+     */
     public void setIdentifier(DBIdentifier name) {
         if (getSchema() != null)
             throw new IllegalStateException();

Modified: openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=1102047&r1=1102046&r2=1102047&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
Wed May 11 19:34:20 2011
@@ -337,6 +337,7 @@ public class DBDictionary
     public boolean supportsNullTableForGetImportedKeys = false;
     public boolean useGetBestRowIdentifierForPrimaryKeys = false;
     public boolean requiresAutoCommitForMetaData = false;
+    public boolean tableLengthIncludesSchema = false; 
 
     // auto-increment
     public int maxAutoAssignNameLength = 31;
@@ -3316,8 +3317,9 @@ public class DBDictionary
      */
     public String[] getCreateTableSQL(Table table) {
         StringBuilder buf = new StringBuilder();
-        String tableName = checkNameLength(getFullName(table, false), 
-                maxTableNameLength, "long-table-name");
+        String tableName =
+            checkNameLength(getFullIdentifier(table, false), maxTableNameLength, "long-table-name",
+                tableLengthIncludesSchema);
         buf.append("CREATE TABLE ").append(tableName);
         if (supportsComments && table.hasComment()) {
             buf.append(" ");
@@ -5257,9 +5259,48 @@ public class DBDictionary
      * given message key otherwise returns the same name.
      */
     final String checkNameLength(String name, int length, String msgKey) {
-        if (name.length() > length)
-            throw new UserException(_loc.get(msgKey, name, name.length(), 
-                    length));
+        if (name.length() > length) {
+            throw new UserException(_loc.get(msgKey, name, name.length(), length));
+        }
+        return name;
+    }
+    
+    /**
+     * Validate that the given name is not longer than given maximum length. Uses the unqualified
name
+     * from the supplied {@link DBIdentifier} by default..
+     * 
+     * @param identifer The database identifier to check.
+     * @param length    Max length for this type of identifier
+     * @param msgKey    message identifier for the exception.
+     * @param qualified If true the qualified name of the DBIdentifier will be used. 
+     * 
+     * @throws {@link UserException} with the given message key if the given name is indeed
longer.
+     * @return the same name.
+     */
+    final String checkNameLength(DBIdentifier identifier, int length, String msgKey) {
+        return checkNameLength(identifier, length, msgKey, false);
+    }
+
+    /**
+     * Validate that the given name is not longer than given maximum length. Conditionally
uses the unqualified name
+     * from the supplied {@link DBIdentifier}.
+     * 
+     * @param identifer The database identifier to check.
+     * @param length    Max length for this type of identifier
+     * @param msgKey    message identifier for the exception.
+     * @param qualified If true the qualified name of the DBIdentifier will be used. 
+     * 
+     * @throws {@link UserException} with the given message key if the given name is indeed
longer.
+     * @return the same name.
+     */
+    final String checkNameLength(DBIdentifier identifier, int length, String msgKey, boolean
qualified) {
+        // always return the input name, 
+        String name = toDBName(identifier);
+        String compareName = qualified ? name : toDBName(identifier.getUnqualifiedName());
+        
+        if (compareName.length() > length) {
+            throw new UserException(_loc.get(msgKey, name, name.length(), length));
+        }
         return name;
     }
 

Copied: openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
(from r1101243, openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java)
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java?p2=openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java&p1=openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java&r1=1101243&r2=1102047&rev=1102047&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
(original)
+++ openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
Wed May 11 19:34:20 2011
@@ -52,7 +52,7 @@ public class TestDBDictionaryGeneratedSQ
             dict.getCreateTableSQL(table);
             fail("Expected a UserException");
         } catch (UserException ue) {
-            // expected - check message incase a different UserException is thrown.
+            // expected - check message in case a different UserException is thrown.
             assertTrue(ue.getMessage().contains("Table name \"NameIsTooLong\""));
         }
     }
@@ -83,7 +83,7 @@ public class TestDBDictionaryGeneratedSQ
             dict.getCreateTableSQL(table);
             fail("Expected a UserException");
         } catch (UserException ue) {
-            // expected - check message incase a different UserException is thrown.
+            // expected - check message in case a different UserException is thrown.
             assertTrue(ue.getMessage().contains("Table name \"IAmASchema.NameIsTooLong\""));
         } 
     }



Mime
View raw message