From 93ae72d15f2b767c41ffc4458d95d4c64e3cc74d Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Mon, 16 Nov 2009 15:58:24 +0000 Subject: [PATCH] OPENJPA-1051: Simplify check for uniqueness of column names. Patch contributed by Ravi Palacherla. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@880821 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/meta/MappingDefaultsImpl.java | 19 ++++------------ .../apache/openjpa/jdbc/schema/NameSet.java | 22 +------------------ 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java index 5624308e7..e3eb12349 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java @@ -539,9 +539,7 @@ public class MappingDefaultsImpl else if (_dsIdName != null) cols[i].setName(_dsIdName + i); correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); } - table.resetSubColumns(); } /** @@ -553,7 +551,9 @@ public class MappingDefaultsImpl String name = col.getName(); if (_removeHungarianNotation) name = removeHungarianNotation(name); - col.setName(dict.getValidColumnName(name, table)); + String correctedName = dict.getValidColumnName(name, table); + col.setName(correctedName); + table.addCorrectedColumnName(correctedName, true); } } @@ -584,9 +584,7 @@ public class MappingDefaultsImpl } else if (_versName != null) cols[i].setName(_versName + i); correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); } - table.resetSubColumns(); } public void populateColumns(Discriminator disc, Table table, @@ -597,9 +595,7 @@ public class MappingDefaultsImpl else if (_discName != null) cols[i].setName(_discName + i); correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); } - table.resetSubColumns(); } public void populateJoinColumn(ClassMapping cm, Table local, Table foreign, @@ -624,11 +620,8 @@ public class MappingDefaultsImpl public void populateColumns(ValueMapping vm, String name, Table table, Column[] cols) { - for (int i = 0; i < cols.length; i++) { + for (int i = 0; i < cols.length; i++) correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); - } - table.resetSubColumns(); } public boolean populateOrderColumns(FieldMapping fm, Table table, @@ -639,9 +632,7 @@ public class MappingDefaultsImpl else if (_orderName != null) cols[i].setName(_orderName + i); correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); } - table.resetSubColumns(); return _orderLists && (JavaTypes.ARRAY == fm.getTypeCode() || List.class.isAssignableFrom(fm.getType())); } @@ -654,9 +645,7 @@ public class MappingDefaultsImpl else if (_nullIndName != null) cols[i].setName(_nullIndName + i); correctName(table, cols[i]); - table.addSubColumn(cols[i].getName()); } - table.resetSubColumns(); return _addNullInd; } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java index 3f23c97f0..a3cc7c2a6 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/NameSet.java @@ -39,17 +39,13 @@ public class NameSet private Set _names = null; - // an additional names Set for checking name duplication - private Set _subNames = null; - /** * Return true if the given name is in use already. */ public boolean isNameTaken(String name) { if (name == null) return true; - return (_names != null && _names.contains(name.toUpperCase())) || - (_subNames != null && _subNames.contains(name.toUpperCase())); + return _names != null && _names.contains(name.toUpperCase()); } /** @@ -81,20 +77,4 @@ public class NameSet if (name != null && _names != null) _names.remove(name.toUpperCase()); } - - /** - * Attempt to add the given name to the set. - * - * @param name the name to add - */ - protected void addSubName(String name) { - if (_subNames == null) { - _subNames = new HashSet(); - } - _subNames.add(name.toUpperCase()); - } - - protected void resetSubNames() { - _subNames = null; - } }