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.model.java.JavaType;
20  import org.apache.jdo.model.jdo.JDORelationship;
21  import org.apache.jdo.impl.model.jdo.JDOMapImplDynamic;
22  
23  /***
24   * An instance of this class represents the JDO relationship metadata 
25   * (the treatment of keys and values) of a map relationship field.  
26   * This caching implementation caches any calulated value to avoid
27   * re-calculating it if it is requested again. 
28   *
29   * @author Michael Bouschen
30   * @since 1.1
31   * @version 2.0
32   */
33  public class JDOMapImplCaching extends JDOMapImplDynamic {
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 keys of the map should be stored if possible as 
64       * part of the instance instead of as their own instances in the datastore.
65       * @return <code>true</code> if the keys are stored as part of this instance;
66       * <code>false</code> otherwise
67       */
68      public boolean isEmbeddedKey() {
69          if (embeddedKey == null) {
70              embeddedKey =
71                  super.isEmbeddedKey() ? Boolean.TRUE : Boolean.FALSE;
72          }
73          return embeddedKey.booleanValue();
74      }
75      
76      /***
77       * Get the type representation of the keys for this JDOMap.
78       * @return the type of the keys of this JDOMap  
79       */
80      public JavaType getKeyType() {
81          if (keyType == null) {
82              keyType = super.getKeyType();
83          }
84          return keyType;
85      }
86  
87      /***
88       * Determines whether the values of the map should be stored if possible as 
89       * part of the instance instead of as their own instances in the datastore.
90       * @return <code>true</code> if the values are stored as part of this 
91       * instance; <code>false</code> otherwise
92       */
93      public boolean isEmbeddedValue() {
94          if (embeddedValue == null) {
95              embeddedValue = 
96                  super.isEmbeddedValue() ? Boolean.TRUE : Boolean.FALSE;
97          }
98          return embeddedValue.booleanValue();
99      }
100     
101     /***
102      * Get the type representation of the values for this JDOMap.
103      * @return the type of the values of this JDOMap  
104      */
105     public JavaType getValueType() {
106         if (valueType == null) {
107             valueType = super.getValueType();
108         }
109         return valueType;
110     }
111 
112 }