OPENJPA-528 committing patch provided by Jeremy Bauer

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@639681 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2008-03-21 15:48:30 +00:00
parent 635ee199fe
commit 831bd55051
3 changed files with 33 additions and 8 deletions

View File

@ -2812,12 +2812,24 @@ public class DBDictionary
/**
* 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 @@ public class DBDictionary
*/
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 @@ public class DBDictionary
}
// 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

View File

@ -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>

View File

@ -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 @@ public class PersistenceMappingDefaults
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);
}
}