Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 10416 invoked from network); 11 Apr 2005 16:21:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Apr 2005 16:21:05 -0000 Received: (qmail 49338 invoked by uid 500); 11 Apr 2005 16:21:04 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 49297 invoked by uid 500); 11 Apr 2005 16:21:04 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 49284 invoked by uid 500); 11 Apr 2005 16:21:03 -0000 Received: (qmail 49281 invoked by uid 99); 11 Apr 2005 16:21:03 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 11 Apr 2005 09:21:03 -0700 Received: (qmail 10401 invoked by uid 1797); 11 Apr 2005 16:21:02 -0000 Date: 11 Apr 2005 16:21:02 -0000 Message-ID: <20050411162102.10400.qmail@minotaur.apache.org> From: tomdz@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer CollectionPrefetcher.java MtoNCollectionPrefetcher.java X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N tomdz 2005/04/11 09:21:01 Modified: src/java/org/apache/ojb/broker/core Tag: OJB_1_0_RELEASE QueryReferenceBroker.java src/java/org/apache/ojb/broker/accesslayer Tag: OJB_1_0_RELEASE CollectionPrefetcher.java MtoNCollectionPrefetcher.java Added: src/java/org/apache/ojb/broker/util/collections Tag: OJB_1_0_RELEASE RemovalAwareSet.java Log: Fix for OJB-19 (issues.apache.org/jira/browse/OJB-19) Revision Changes Path No revision No revision 1.1.2.1 +96 -0 db-ojb/src/java/org/apache/ojb/broker/util/collections/Attic/RemovalAwareSet.java No revision No revision 1.17.2.7 +22 -4 db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java Index: QueryReferenceBroker.java =================================================================== RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/QueryReferenceBroker.java,v retrieving revision 1.17.2.6 retrieving revision 1.17.2.7 diff -u -r1.17.2.6 -r1.17.2.7 --- QueryReferenceBroker.java 15 Mar 2005 06:27:55 -0000 1.17.2.6 +++ QueryReferenceBroker.java 11 Apr 2005 16:21:01 -0000 1.17.2.7 @@ -42,6 +42,7 @@ import org.apache.ojb.broker.metadata.CollectionDescriptor; import org.apache.ojb.broker.metadata.FieldDescriptor; import org.apache.ojb.broker.metadata.FieldHelper; +import org.apache.ojb.broker.metadata.MetadataException; import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; import org.apache.ojb.broker.metadata.fieldaccess.PersistentField; import org.apache.ojb.broker.query.Criteria; @@ -49,7 +50,10 @@ import org.apache.ojb.broker.query.QueryByCriteria; import org.apache.ojb.broker.query.QueryFactory; import org.apache.ojb.broker.util.collections.ManageableArrayList; +import org.apache.ojb.broker.util.collections.ManageableHashSet; import org.apache.ojb.broker.util.collections.RemovalAwareCollection; +import org.apache.ojb.broker.util.collections.RemovalAwareList; +import org.apache.ojb.broker.util.collections.RemovalAwareSet; import org.apache.ojb.broker.util.logging.Logger; import org.apache.ojb.broker.util.logging.LoggerFactory; import org.apache.ojb.broker.util.BrokerHelper; @@ -278,14 +282,28 @@ { // BRJ: do not use RemovalAwareCollection for m:n relationships // see http://db.apache.org/ojb/docu/guides/basic-technique.html#Mapping+m%3An+associations - if (cds.isMtoNRelation()) + + Class fieldType = cds.getPersistentField().getType(); + Class collType = null; + + if (fieldType.isArray() || fieldType.isAssignableFrom(RemovalAwareCollection.class)) + { + collType = cds.isMtoNRelation() ? ManageableArrayList.class : RemovalAwareCollection.class; + } + else if (fieldType.isAssignableFrom(RemovalAwareList.class)) + { + collType = cds.isMtoNRelation() ? ManageableArrayList.class : RemovalAwareList.class; + } + else if (fieldType.isAssignableFrom(RemovalAwareSet.class)) { - return (Collection) getCollectionByQuery(ManageableArrayList.class, query, cds.isLazy()); + collType = cds.isMtoNRelation() ? ManageableHashSet.class : RemovalAwareSet.class; } else { - return (Collection) getCollectionByQuery(RemovalAwareCollection.class, query, cds.isLazy()); + throw new MetadataException("Cannot determine a default collection type for collection "+cds.getAttributeName()+" in type "+cds.getClassDescriptor().getClassNameOfObject()); } + + return (Collection)getCollectionByQuery(collType, query, cds.isLazy()); } /** No revision No revision 1.29.2.2 +32 -10 db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java Index: CollectionPrefetcher.java =================================================================== RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java,v retrieving revision 1.29.2.1 retrieving revision 1.29.2.2 diff -u -r1.29.2.1 -r1.29.2.2 --- CollectionPrefetcher.java 3 Apr 2005 02:22:39 -0000 1.29.2.1 +++ CollectionPrefetcher.java 11 Apr 2005 16:21:01 -0000 1.29.2.2 @@ -34,12 +34,15 @@ import org.apache.ojb.broker.metadata.ClassDescriptor; import org.apache.ojb.broker.metadata.CollectionDescriptor; import org.apache.ojb.broker.metadata.FieldHelper; +import org.apache.ojb.broker.metadata.MetadataException; import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; import org.apache.ojb.broker.metadata.fieldaccess.PersistentField; import org.apache.ojb.broker.query.Query; import org.apache.ojb.broker.query.QueryByCriteria; import org.apache.ojb.broker.util.BrokerHelper; import org.apache.ojb.broker.util.collections.RemovalAwareCollection; +import org.apache.ojb.broker.util.collections.RemovalAwareList; +import org.apache.ojb.broker.util.collections.RemovalAwareSet; /** * Relationship Prefetcher for Collections. @@ -178,7 +181,7 @@ } else { - ManageableCollection col = createCollection(collectionClass); + ManageableCollection col = createCollection(cds, collectionClass); for (Iterator it2 = list.iterator(); it2.hasNext();) { col.ojbAdd(it2.next()); @@ -199,28 +202,47 @@ } /** - * Create a Collection of class collectionClass - * if collectionClass is null return a RemovalAwareCollection - * @param collectionClass - * @return + * Create a collection object of the given collection type. If none has been given, + * OJB uses RemovalAwareList, RemovalAwareSet, or RemovalAwareCollection depending + * on the field type. + * + * @param desc The collection descriptor + * @param collectionClass The collection class specified in the collection-descriptor + * @return The collection object */ - protected ManageableCollection createCollection(Class collectionClass) + protected ManageableCollection createCollection(CollectionDescriptor desc, Class collectionClass) { + Class fieldType = desc.getPersistentField().getType(); ManageableCollection col; if (collectionClass == null) { - col = new RemovalAwareCollection(); + if (fieldType.isAssignableFrom(RemovalAwareCollection.class)) + { + col = new RemovalAwareCollection(); + } + else if (fieldType.isAssignableFrom(RemovalAwareList.class)) + { + col = new RemovalAwareList(); + } + else if (fieldType.isAssignableFrom(RemovalAwareSet.class)) + { + col = new RemovalAwareSet(); + } + else + { + throw new MetadataException("Cannot determine a default collection type for collection "+desc.getAttributeName()+" in type "+desc.getClassDescriptor().getClassNameOfObject()); + } } else { try { - col = (ManageableCollection) collectionClass.newInstance(); + col = (ManageableCollection)collectionClass.newInstance(); } catch (Exception e) { - throw new OJBRuntimeException("Can't create new Collection for owner", e); + throw new OJBRuntimeException("Cannot instantiate the collection class "+collectionClass.getName()+" of collection "+desc.getAttributeName()+" in type "+desc.getClassDescriptor().getClassNameOfObject()); } } return col; 1.12.2.3 +2 -2 db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java Index: MtoNCollectionPrefetcher.java =================================================================== RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/MtoNCollectionPrefetcher.java,v retrieving revision 1.12.2.2 retrieving revision 1.12.2.3 diff -u -r1.12.2.2 -r1.12.2.3 --- MtoNCollectionPrefetcher.java 4 Dec 2004 10:00:43 -0000 1.12.2.2 +++ MtoNCollectionPrefetcher.java 11 Apr 2005 16:21:01 -0000 1.12.2.3 @@ -477,7 +477,7 @@ } else { - ManageableCollection col = createCollection(collectionClass); + ManageableCollection col = createCollection(cds, collectionClass); for (Iterator it2 = list.iterator(); it2.hasNext();) { --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org