01: package org.apache.ojb.broker.accesslayer;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
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: /**
25: * Factory for Relationship Prefetchers
26: *
27: * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
28: * @version $Id: RelationshipPrefetcherFactory.java,v 1.6.2.2 2005/12/21 22:22:58 tomdz Exp $
29: */
30: public class RelationshipPrefetcherFactory {
31: private PersistenceBrokerImpl broker;
32:
33: public RelationshipPrefetcherFactory(
34: final PersistenceBrokerImpl broker) {
35: this .broker = broker;
36: }
37:
38: /**
39: * create either a CollectionPrefetcher or a ReferencePrefetcher
40: */
41: public RelationshipPrefetcher createRelationshipPrefetcher(
42: ObjectReferenceDescriptor ord) {
43: if (ord instanceof CollectionDescriptor) {
44: CollectionDescriptor cds = (CollectionDescriptor) ord;
45: if (cds.isMtoNRelation()) {
46: return new MtoNCollectionPrefetcher(broker, cds);
47: } else {
48: return new CollectionPrefetcher(broker, cds);
49: }
50: } else {
51: return new ReferencePrefetcher(broker, ord);
52: }
53: }
54:
55: /**
56: * create either a CollectionPrefetcher or a ReferencePrefetcher
57: */
58: public RelationshipPrefetcher createRelationshipPrefetcher(
59: ClassDescriptor anOwnerCld, String aRelationshipName) {
60: ObjectReferenceDescriptor ord;
61:
62: ord = anOwnerCld
63: .getCollectionDescriptorByName(aRelationshipName);
64: if (ord == null) {
65: ord = anOwnerCld
66: .getObjectReferenceDescriptorByName(aRelationshipName);
67: if (ord == null) {
68: throw new PersistenceBrokerException(
69: "Relationship named '"
70: + aRelationshipName
71: + "' not found in owner class "
72: + (anOwnerCld != null ? anOwnerCld
73: .getClassNameOfObject() : null));
74: }
75: }
76: return createRelationshipPrefetcher(ord);
77: }
78: }
|