1 package org.apache.ojb.broker.accesslayer; 2 3 17 18 import org.apache.ojb.broker.PersistenceBrokerException; 19 import org.apache.ojb.broker.core.PersistenceBrokerImpl; 20 import org.apache.ojb.broker.metadata.ClassDescriptor; 21 import org.apache.ojb.broker.metadata.CollectionDescriptor; 22 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor; 23 24 30 public class RelationshipPrefetcherFactory 31 { 32 private PersistenceBrokerImpl broker; 33 34 public RelationshipPrefetcherFactory(final PersistenceBrokerImpl broker) 35 { 36 this.broker = broker; 37 } 38 39 42 public RelationshipPrefetcher createRelationshipPrefetcher(ObjectReferenceDescriptor ord) 43 { 44 if (ord instanceof CollectionDescriptor) 45 { 46 CollectionDescriptor cds = (CollectionDescriptor)ord; 47 if (cds.isMtoNRelation()) 48 { 49 return new MtoNCollectionPrefetcher(broker, cds); 50 } 51 else 52 { 53 return new CollectionPrefetcher(broker, cds); 54 } 55 } 56 else 57 { 58 return new ReferencePrefetcher(broker, ord); 59 } 60 } 61 62 65 public RelationshipPrefetcher createRelationshipPrefetcher(ClassDescriptor anOwnerCld, String aRelationshipName) 66 { 67 ObjectReferenceDescriptor ord; 68 69 ord = anOwnerCld.getCollectionDescriptorByName(aRelationshipName); 70 if (ord == null) 71 { 72 ord = anOwnerCld.getObjectReferenceDescriptorByName(aRelationshipName); 73 if (ord == null) 74 { 75 throw new PersistenceBrokerException("Relationship named '" + aRelationshipName 76 + "' not found in owner class " + (anOwnerCld != null ? anOwnerCld.getClassNameOfObject() : null)); 77 } 78 } 79 return createRelationshipPrefetcher(ord); 80 } 81 } 82 | Popular Tags |