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
This commit is contained in:
Pinaki Poddar 2009-11-16 15:58:24 +00:00
parent a91e85e6db
commit 93ae72d15f
2 changed files with 5 additions and 36 deletions

View File

@ -539,9 +539,7 @@ public class MappingDefaultsImpl
else if (_dsIdName != null) else if (_dsIdName != null)
cols[i].setName(_dsIdName + i); cols[i].setName(_dsIdName + i);
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
} }
table.resetSubColumns();
} }
/** /**
@ -553,7 +551,9 @@ public class MappingDefaultsImpl
String name = col.getName(); String name = col.getName();
if (_removeHungarianNotation) if (_removeHungarianNotation)
name = removeHungarianNotation(name); 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) } else if (_versName != null)
cols[i].setName(_versName + i); cols[i].setName(_versName + i);
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
} }
table.resetSubColumns();
} }
public void populateColumns(Discriminator disc, Table table, public void populateColumns(Discriminator disc, Table table,
@ -597,9 +595,7 @@ public class MappingDefaultsImpl
else if (_discName != null) else if (_discName != null)
cols[i].setName(_discName + i); cols[i].setName(_discName + i);
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
} }
table.resetSubColumns();
} }
public void populateJoinColumn(ClassMapping cm, Table local, Table foreign, 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, public void populateColumns(ValueMapping vm, String name, Table table,
Column[] cols) { Column[] cols) {
for (int i = 0; i < cols.length; i++) { for (int i = 0; i < cols.length; i++)
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
}
table.resetSubColumns();
} }
public boolean populateOrderColumns(FieldMapping fm, Table table, public boolean populateOrderColumns(FieldMapping fm, Table table,
@ -639,9 +632,7 @@ public class MappingDefaultsImpl
else if (_orderName != null) else if (_orderName != null)
cols[i].setName(_orderName + i); cols[i].setName(_orderName + i);
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
} }
table.resetSubColumns();
return _orderLists && (JavaTypes.ARRAY == fm.getTypeCode() return _orderLists && (JavaTypes.ARRAY == fm.getTypeCode()
|| List.class.isAssignableFrom(fm.getType())); || List.class.isAssignableFrom(fm.getType()));
} }
@ -654,9 +645,7 @@ public class MappingDefaultsImpl
else if (_nullIndName != null) else if (_nullIndName != null)
cols[i].setName(_nullIndName + i); cols[i].setName(_nullIndName + i);
correctName(table, cols[i]); correctName(table, cols[i]);
table.addSubColumn(cols[i].getName());
} }
table.resetSubColumns();
return _addNullInd; return _addNullInd;
} }

View File

@ -39,17 +39,13 @@ public class NameSet
private Set _names = null; 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. * Return true if the given name is in use already.
*/ */
public boolean isNameTaken(String name) { public boolean isNameTaken(String name) {
if (name == null) if (name == null)
return true; return true;
return (_names != null && _names.contains(name.toUpperCase())) || return _names != null && _names.contains(name.toUpperCase());
(_subNames != null && _subNames.contains(name.toUpperCase()));
} }
/** /**
@ -81,20 +77,4 @@ public class NameSet
if (name != null && _names != null) if (name != null && _names != null)
_names.remove(name.toUpperCase()); _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;
}
} }