org.apache.openjpa.kernel
Class ResultShape<T>

java.lang.Object
  extended by org.apache.openjpa.kernel.ResultShape<T>
All Implemented Interfaces:
Serializable

public class ResultShape<T>
extends Object
implements Serializable

Describes the shape of a query result.
A shape is described as a Java class by the generic type argument T. A shape may contain zero or more shapes. A shape is categorized as follows:

  • A primitive shape can not have child shapes e.g. Foo or float.
  • A compound shape has zero or more child shapes e.g. Foo{} or Foo{String, int} or Foo{String,Bar{Double},int}.
  • A nesting shape has one or more compound child shape(s). For example, Foo{String,Bar{Double},int}. On the other hand, Foo{String, int} is a compound shape but is not nesting because all its child shapes are primitive.
    A primitive category shape is declared during construction and immutable. The category of a non-primitive shape is mutable.
    Notice that all nested shapes are compound shapes but not all compound shapes are nesting.
    A compound shape can add other primitive shapes or nest other shapes to any arbitrary depth. However, a shape does not allow recursive nesting of shapes.
    Usage: The purpose of a shape is to populate an instance of T from an array of input values where each array element is further specified with a type and an alias. FillStrategy determines how a shape populates an instance of T by consuming the input array element values. The input data is presented as an Object[] with a parallel array of types because the primitive types (short, float etc.) are not preserved in the input array. For certain FillStrategy such as MAP or BEAN, the alias of the input array element are used to identify the Map key or setter methods respectively.

    Since:
    2.0.0
    Author:
    Pinaki Poddar
    See Also:
    Serialized Form

    Constructor Summary
    ResultShape(Class<T> cls)
              Construct a non-primitive shape with ASSIGN or ARRAY fill strategy.
    ResultShape(Class<T> cls, boolean primitive)
              Construct a primitive or non-primitive shape with ASSIGN or ARRAY fill strategy.
    ResultShape(Class<T> cls, FillStrategy<T> strategy)
              Construct a non-primitive shape with the given fill strategy.
    ResultShape(Class<T> cls, FillStrategy<T> strategy, boolean primitive)
              Construct a shape with the given fill strategy.
     
    Method Summary
     ResultShape<T> add(Class<?>... classes)
              Adds the given classes as child shapes of this shape.
     int argLength()
              Total number of arguments required to populate the shape and all its child shapes.
     String getAlias()
               
     List<ResultShape<?>> getChildren()
              Gets all the child shapes.
     List<Class<?>> getCompositeTypes()
              Gets the list of classes to compose this shape and all its children.
     Set<ResultShape<?>> getParents()
              Gets the immediate parents of this shape.
     FillStrategy<T> getStrategy()
               
     Class<T> getType()
              Gets the type of instance populated by this shape.
     List<Class<?>> getTypes()
              Gets the list of classes to compose this shape only i.e.
     boolean isCompound()
              Affirms if this shape can have child shapes.
     boolean isNested()
              Affirms if this shape is nested within other shapes.
     boolean isNesting()
              Affirms if at least one child shape of this shape is a compound shape.
     boolean isParent(ResultShape<?> p)
              Affirms if the given shape is a parent (or grandparent) of this shape.
     boolean isPrimitive()
              Affirms if this shape can not have any child shape.
     int length()
              Number of arguments to populate this shape only.
    <X> ResultShape<X>
    nest(Class<X> cls, FillStrategy strategy, Class<?>... classes)
              Creates a new shape of type X with the given class arguments and nests the new shape within this shape.
     ResultShape<T> nest(ResultShape<?> shape)
              Nest the given shape.
     T pack(Object[] values, Class<?>[] types, String[] aliases)
              Fill this shape and its children with the given array element values.
     ResultShape<T> setAlias(String alias)
               
     String toString()
              Gets a human-readable representation of this shape.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Constructor Detail

    ResultShape

    public ResultShape(Class<T> cls)
    Construct a non-primitive shape with ASSIGN or ARRAY fill strategy.


    ResultShape

    public ResultShape(Class<T> cls,
                       boolean primitive)
    Construct a primitive or non-primitive shape with ASSIGN or ARRAY fill strategy. If the shape is declared as primitive then the given class can not be an array.


    ResultShape

    public ResultShape(Class<T> cls,
                       FillStrategy<T> strategy)
    Construct a non-primitive shape with the given fill strategy.


    ResultShape

    public ResultShape(Class<T> cls,
                       FillStrategy<T> strategy,
                       boolean primitive)
    Construct a shape with the given fill strategy.

    Method Detail

    getType

    public Class<T> getType()
    Gets the type of instance populated by this shape.


    getStrategy

    public FillStrategy<T> getStrategy()

    setAlias

    public ResultShape<T> setAlias(String alias)

    getAlias

    public String getAlias()

    getCompositeTypes

    public List<Class<?>> getCompositeTypes()
    Gets the list of classes to compose this shape and all its children. For example, a shape Foo{String,Bar{int, Date}, Double} will return {String, int, Date, Double}


    getTypes

    public List<Class<?>> getTypes()
    Gets the list of classes to compose this shape only i.e. without expanding the children's shape. For example, a shape Foo{String,Bar{int, Date}, Double} will return {String, Bar, Double}


    nest

    public <X> ResultShape<X> nest(Class<X> cls,
                                   FillStrategy strategy,
                                   Class<?>... classes)
    Creates a new shape of type X with the given class arguments and nests the new shape within this shape.

    Returns:
    newly created nested shape

    nest

    public ResultShape<T> nest(ResultShape<?> shape)
    Nest the given shape.

    Parameters:
    shape - The given shape can not be a parent of this shape to prohibit recursive nesting.
    Returns:
    this shape itself

    add

    public ResultShape<T> add(Class<?>... classes)
    Adds the given classes as child shapes of this shape. The child shapes are primitive shapes.


    getChildren

    public List<ResultShape<?>> getChildren()
    Gets all the child shapes.


    isCompound

    public boolean isCompound()
    Affirms if this shape can have child shapes.


    isPrimitive

    public boolean isPrimitive()
    Affirms if this shape can not have any child shape. A primitive shape uses ASSIGN strategy.


    isNesting

    public boolean isNesting()
    Affirms if at least one child shape of this shape is a compound shape.


    isNested

    public boolean isNested()
    Affirms if this shape is nested within other shapes.


    isParent

    public boolean isParent(ResultShape<?> p)
    Affirms if the given shape is a parent (or grandparent) of this shape.


    getParents

    public Set<ResultShape<?>> getParents()
    Gets the immediate parents of this shape.


    argLength

    public int argLength()
    Total number of arguments required to populate the shape and all its child shapes.


    length

    public int length()
    Number of arguments to populate this shape only.


    pack

    public T pack(Object[] values,
                  Class<?>[] types,
                  String[] aliases)
    Fill this shape and its children with the given array element values. The parallel arrays contain the actual values, the types of these values and aliases. The type and alias information are used for packing Map or invoking constructor. The type can be different from what can be determined from array elements because of boxing of primitive types. The actual constructor argument types are sourced from types[] array.


    toString

    public String toString()
    Gets a human-readable representation of this shape.

    Overrides:
    toString in class Object


    Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.