You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/07/30 16:58:43 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata DescriptorRepository.java
arminw 2004/07/30 07:58:43
Modified: src/java/org/apache/ojb/broker/metadata
DescriptorRepository.java
Log:
fix bug in handling multiple mapped classes to the same table.
Method getFieldDescriptorsForMultiMappedTable(ClassDescriptor targetClass) now returns
all fields belonging to the target class + fields for other columns.
Revision Changes Path
1.51 +22 -10 db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
Index: DescriptorRepository.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- DescriptorRepository.java 2 Jun 2004 20:09:03 -0000 1.50
+++ DescriptorRepository.java 30 Jul 2004 14:58:43 -0000 1.51
@@ -215,12 +215,21 @@
{
for (int i = 0; i < fields.length; i++)
{
- /**
- * MBAIRD
- * hashmap will only allow one entry per unique key,
- * so no need to check contains(fields[i].getColumnName()).
+ /*
+ MBAIRD
+ hashmap will only allow one entry per unique key,
+ so no need to check contains(fields[i].getColumnName()).
+ arminw:
+ use contains to avoid overriding of target class fields by the same
+ field-descriptor of other classes mapped to the same DB table, because
+ the other class can use e.g. different FieldConversion.
+ In #getClassesMappedToSameTable(...) we make sure that target
+ class has first position in list.
*/
- map.put(fields[i].getColumnName(), fields[i]);
+ if(!map.containsKey(fields[i].getColumnName()))
+ {
+ map.put(fields[i].getColumnName(), fields[i]);
+ }
}
}
}
@@ -244,12 +253,15 @@
*/
Iterator iter = ((HashMap)descriptorTable.clone()).values().iterator();
List retval = new ArrayList();
+ // make sure that target class is at first position
+ retval.add(targetCld);
while (iter.hasNext())
{
ClassDescriptor cld = (ClassDescriptor) iter.next();
if (cld.getFullTableName() != null)
{
- if (cld.getFullTableName().equals(targetCld.getFullTableName()))
+ if (cld.getFullTableName().equals(targetCld.getFullTableName())
+ && !targetCld.getClassOfObject().equals(cld.getClassOfObject()))
{
retval.add(cld);
}
@@ -377,7 +389,7 @@
Iterator subIter = getAllConcreteSubclassDescriptors(extCld).iterator();
while (subIter.hasNext())
{
- ClassDescriptor subCld = (ClassDescriptor)subIter.next();
+ ClassDescriptor subCld = (ClassDescriptor)subIter.next();
if (!concreteSubclassClds.contains(subCld))
{
concreteSubclassClds.add(subCld);
@@ -663,13 +675,13 @@
}
if (result != null)
- {
+ {
descriptorTable.put(clazz.getName(), result);
}
}
return result;
}
-
+
protected void finalize() throws Throwable
{
LoggerFactory.getDefaultLogger().info("# finalize DescriptorRepository instance #");
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org