Save This Page
Home » jdo2-model-2.3-ea-src » org.apache.jdo.impl.model.jdo » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.jdo.impl.model.jdo;
   19   
   20   import org.apache.jdo.impl.model.jdo.util.TypeSupport;
   21   import org.apache.jdo.model.java.JavaType;
   22   import org.apache.jdo.model.jdo.JDOArray;
   23   import org.apache.jdo.model.jdo.JDOField;
   24   
   25   /**
   26    * An instance of this class represents the JDO relationship metadata 
   27    * of a array relationship field. This dynamic implementation only
   28    * stores property values explicitly set by setter method. 
   29    *
   30    * @author Michael Bouschen
   31    * @since 1.1
   32    * @version 2.0
   33    */
   34   public class JDOArrayImplDynamic extends JDORelationshipImpl 
   35       implements JDOArray {
   36       
   37       /** Property embeddedElement. */
   38       protected Boolean embeddedElement;
   39   
   40       /**
   41        * Determines whether the values of the elements should be stored 
   42        * if possible as part of the instance instead of as their own instances 
   43        * in the datastore.
   44        * @return <code>true</code> if the elements should be stored as part of 
   45        * the instance; <code>false</code> otherwise
   46        */
   47       public boolean isEmbeddedElement() {
   48           if (embeddedElement != null) {
   49               // return embeddedElement, if explicitly set by the setter
   50               return embeddedElement.booleanValue();
   51           }
   52           
   53           // not set => calculate
   54           JavaType elementType = getElementType();
   55           return (elementType != null) ? 
   56               TypeSupport.isEmbeddedElementType(elementType) : false;
   57       }
   58       
   59       /**
   60        * Set whether the values of the elements should be stored 
   61        * if possible as part of the instance instead of as their own instances 
   62        * in the datastore.
   63        * @param embeddedElement flag indicating whether the elements should be 
   64        * stored as part of the instance
   65        */
   66       public void setEmbeddedElement(boolean embeddedElement) {
   67           this.embeddedElement = (embeddedElement ? Boolean.TRUE : Boolean.FALSE);
   68       }
   69   
   70       /** 
   71        * Get the type representation of the array component type. 
   72        * @return the array component type
   73        */
   74       public JavaType getElementType() {
   75           JDOField jdoField = getDeclaringField();
   76           JavaType fieldType = jdoField.getType();
   77           return (fieldType != null) ? fieldType.getArrayComponentType() : null;
   78       }
   79   
   80       /**
   81        * Determines whether this JDORelationship represents an array
   82        * relationship or not. A return of <code>true</code> means this
   83        * JDORelationship is a JDOArray instance.
   84        * @return <code>true</code> if this JDORelationship represents an 
   85        * array relationship; <code>false</code> otherwise.
   86        */
   87       public boolean isJDOArray() {
   88           return true;
   89       }
   90   
   91       //========= Internal helper methods ==========
   92   
   93       /** 
   94        * Get the type representation of the relationship. This will be 
   95        * the JavaType for references, the element type for collections
   96        * and arrays, and the value type for maps.
   97        * @return the relationship type
   98        */
   99       public JavaType getRelatedJavaType() {
  100           return getElementType();
  101       }
  102   
  103   }

Save This Page
Home » jdo2-model-2.3-ea-src » org.apache.jdo.impl.model.jdo » [javadoc | source]