KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > accesslayer > RelationshipPrefetcherFactory


1 package org.apache.ojb.broker.accesslayer;
2
3 /* Copyright 2002-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * 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 {
32     private PersistenceBrokerImpl broker;
33
34     public RelationshipPrefetcherFactory(final PersistenceBrokerImpl broker)
35     {
36         this.broker = broker;
37     }
38
39     /**
40      * create either a CollectionPrefetcher or a ReferencePrefetcher
41      */

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     /**
63      * create either a CollectionPrefetcher or a ReferencePrefetcher
64      */

65     public RelationshipPrefetcher createRelationshipPrefetcher(ClassDescriptor anOwnerCld, String JavaDoc 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