View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package org.apache.jdo.impl.model.jdo.caching;
18  
19  import org.apache.jdo.impl.model.jdo.JDOCollectionImplDynamic;
20  import org.apache.jdo.model.jdo.JDORelationship;
21  import org.apache.jdo.model.java.JavaType;
22  
23  /***
24   * An instance of this class represents the JDO relationship metadata 
25   * of a collection relationship field. This caching implementation
26   * caches any calulated value to avoid re-calculating it if it is
27   * requested again. 
28   *
29   * @author Michael Bouschen
30   * @since 1.1
31   * @version 2.0
32   */
33  public class JDOCollectionImplCaching extends JDOCollectionImplDynamic {
34  
35      /*** 
36       * Get the mappedBy relationship. If there is no mappedBy relationship
37       * set, the method checks the mappedBy name as specified in the declaring
38       * field and resolves the relationship. The method returns
39       * <code>null</code> if there is no mappedBy relationship set and there
40       * is no mappedBy name specified on the declaring field.
41       * @return the mappedBy relationship if available; <code>null</code>
42       * otherwise.
43       */
44      public JDORelationship getMappedBy() {
45          if (mappedBy == null) {
46              mappedBy = super.getMappedBy();
47          }
48          return mappedBy;
49      }
50  
51      /***
52       * Get the inverse JDORelationship in the case of a two-way relationship.
53       * @return the inverse relationship
54       */
55      public JDORelationship getInverseRelationship() {
56          if (inverse == null) {
57              inverse = super.getInverseRelationship();
58          }
59          return inverse;
60      }
61  
62      /***
63       * Determines whether the values of the elements should be stored if 
64       * possible as part of the instance instead of as their own instances 
65       * in the datastore.
66       * @return <code>true</code> if the elements should be stored as part of 
67       * the instance; <code>false</code> otherwise
68       */
69      public boolean isEmbeddedElement() {
70          if (embeddedElement == null) {
71              embeddedElement = 
72                  super.isEmbeddedElement() ? Boolean.TRUE : Boolean.FALSE;
73          }
74          return (embeddedElement == null) ? false : 
75              embeddedElement.booleanValue();
76      }
77      
78      /*** 
79       * Get the type representation of the collection elements. 
80       * @return the element type
81       */
82      public JavaType getElementType()
83      {
84          if (elementType == null) {
85              elementType = super.getElementType();
86          }
87          return elementType;
88      }
89  
90  }