Package org.apache.openjpa.kernel
Class ResultShape<T>
- java.lang.Object
-
- org.apache.openjpa.kernel.ResultShape<T>
-
- All Implemented Interfaces:
java.io.Serializable
public class ResultShape<T> extends java.lang.Object implements java.io.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
Constructors Constructor Description ResultShape(java.lang.Class<T> cls)
Construct a non-primitive shape with ASSIGN or ARRAY fill strategy.ResultShape(java.lang.Class<T> cls, boolean primitive)
Construct a primitive or non-primitive shape with ASSIGN or ARRAY fill strategy.ResultShape(java.lang.Class<T> cls, FillStrategy<T> strategy)
Construct a non-primitive shape with the given fill strategy.ResultShape(java.lang.Class<T> cls, FillStrategy<T> strategy, boolean primitive)
Construct a shape with the given fill strategy.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResultShape<T>
add(java.lang.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.java.lang.String
getAlias()
java.util.List<ResultShape<?>>
getChildren()
Gets all the child shapes.java.util.List<java.lang.Class<?>>
getCompositeTypes()
Gets the list of classes to compose this shape and all its children.java.util.Set<ResultShape<?>>
getParents()
Gets the immediate parents of this shape.FillStrategy<T>
getStrategy()
java.lang.Class<T>
getType()
Gets the type of instance populated by this shape.java.util.List<java.lang.Class<?>>
getTypes()
Gets the list of classes to compose this shape only i.e. without expanding the children's shape.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(java.lang.Class<X> cls, FillStrategy strategy, java.lang.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(java.lang.Object[] values, java.lang.Class<?>[] types, java.lang.String[] aliases)
Fill this shape and its children with the given array element values.ResultShape<T>
setAlias(java.lang.String alias)
java.lang.String
toString()
Gets a human-readable representation of this shape.
-
-
-
Constructor Detail
-
ResultShape
public ResultShape(java.lang.Class<T> cls)
Construct a non-primitive shape with ASSIGN or ARRAY fill strategy.
-
ResultShape
public ResultShape(java.lang.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(java.lang.Class<T> cls, FillStrategy<T> strategy)
Construct a non-primitive shape with the given fill strategy.
-
ResultShape
public ResultShape(java.lang.Class<T> cls, FillStrategy<T> strategy, boolean primitive)
Construct a shape with the given fill strategy.
-
-
Method Detail
-
getType
public java.lang.Class<T> getType()
Gets the type of instance populated by this shape.
-
getStrategy
public FillStrategy<T> getStrategy()
-
setAlias
public ResultShape<T> setAlias(java.lang.String alias)
-
getAlias
public java.lang.String getAlias()
-
getCompositeTypes
public java.util.List<java.lang.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 java.util.List<java.lang.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(java.lang.Class<X> cls, FillStrategy strategy, java.lang.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(java.lang.Class<?>... classes)
Adds the given classes as child shapes of this shape. The child shapes are primitive shapes.
-
getChildren
public java.util.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 java.util.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(java.lang.Object[] values, java.lang.Class<?>[] types, java.lang.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 java.lang.String toString()
Gets a human-readable representation of this shape.- Overrides:
toString
in classjava.lang.Object
-
-