001    package org.apache.ojb.broker.accesslayer;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import org.apache.ojb.broker.core.PersistenceBrokerImpl;
019    import org.apache.ojb.broker.metadata.ClassDescriptor;
020    import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
021    
022    /**
023     * Abstract Relationship Prefetchers.
024     * Each Prefetcher handles a single Relationship (1:1 or 1:n)
025     *
026     * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
027     * @version $Id: RelationshipPrefetcherImpl.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
028     */
029    public abstract class RelationshipPrefetcherImpl extends BasePrefetcher
030    {
031        private ObjectReferenceDescriptor objectReferenceDescriptor;
032        private boolean cascadeRetrieve;
033    
034        /**
035         * Constructor for RelationshipPrefetcherImpl.
036         */
037        public RelationshipPrefetcherImpl(PersistenceBrokerImpl aBroker, ObjectReferenceDescriptor anOrd)
038        {
039            super(aBroker, anOrd.getItemClass());
040            objectReferenceDescriptor = anOrd;
041        }
042    
043        /**
044         * @see org.apache.ojb.broker.accesslayer.RelationshipPrefetcher#prepareRelationshipSettings()
045         */
046        public void prepareRelationshipSettings()
047        {
048            setCascadeRetrieve(getObjectReferenceDescriptor().getCascadeRetrieve());
049            
050            // BRJ: do not modify reference-descriptor
051            // getObjectReferenceDescriptor().setCascadeRetrieve(false);
052        }
053    
054        /**
055         * Returns the ClassDescriptor of the owner Class
056         * @return ClassDescriptor
057         */
058        protected ClassDescriptor getOwnerClassDescriptor()
059        {
060            return getObjectReferenceDescriptor().getClassDescriptor();
061        }
062    
063        /**
064         * @see org.apache.ojb.broker.accesslayer.RelationshipPrefetcher#restoreRelationshipSettings()
065         */
066        public void restoreRelationshipSettings()
067        {
068            // BRJ: do not modify reference-descriptor
069            // getObjectReferenceDescriptor().setCascadeRetrieve(isCascadeRetrieve());
070        }
071    
072        /**
073         * Returns the objectReferenceDescriptor.
074         * @return ObjectReferenceDescriptor
075         */
076        protected ObjectReferenceDescriptor getObjectReferenceDescriptor()
077        {
078            return objectReferenceDescriptor;
079        }
080    
081        /**
082         * Sets the objectReferenceDescriptor.
083         * @param objectReferenceDescriptor The objectReferenceDescriptor to set
084         */
085        protected void setObjectReferenceDescriptor(ObjectReferenceDescriptor objectReferenceDescriptor)
086        {
087            this.objectReferenceDescriptor = objectReferenceDescriptor;
088        }
089    
090        /**
091         * Returns the cascadeRetrieve.
092         * @return boolean
093         */
094        protected boolean isCascadeRetrieve()
095        {
096            return cascadeRetrieve;
097        }
098    
099        /**
100         * Sets the cascadeRetrieve.
101         * @param cascadeRetrieve The cascadeRetrieve to set
102         */
103        protected void setCascadeRetrieve(boolean cascadeRetrieve)
104        {
105            this.cascadeRetrieve = cascadeRetrieve;
106        }
107    }