Package org.apache.openjpa.kernel
Class ResultShape<T>
java.lang.Object
org.apache.openjpa.kernel.ResultShape<T>
- All Implemented Interfaces:
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.
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 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:
-
Constructor Summary
ConstructorDescriptionResultShape
(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
Modifier and TypeMethodDescriptionAdds the given classes as child shapes of this shape.int
Total number of arguments required to populate the shape and all its child shapes.getAlias()
List<ResultShape<?>>
Gets all the child shapes.Gets the list of classes to compose this shape and all its children.Set<ResultShape<?>>
Gets the immediate parents of this shape.getType()
Gets the type of instance populated by this shape.getTypes()
Gets the list of classes to compose this shape only i.e. without expanding the children's shape.boolean
Affirms if this shape can have child shapes.boolean
isNested()
Affirms if this shape is nested within other shapes.boolean
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
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.nest
(ResultShape<?> shape) Nest the given shape.Fill this shape and its children with the given array element values.toString()
Gets a human-readable representation of this shape.
-
Constructor Details
-
ResultShape
Construct a non-primitive shape with ASSIGN or ARRAY fill strategy. -
ResultShape
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
Construct a non-primitive shape with the given fill strategy. -
ResultShape
Construct a shape with the given fill strategy.
-
-
Method Details
-
getType
Gets the type of instance populated by this shape. -
getStrategy
-
setAlias
-
getAlias
-
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
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
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
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
Adds the given classes as child shapes of this shape. The child shapes are primitive shapes. -
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
Affirms if the given shape is a parent (or grandparent) of this shape. -
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
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
Gets a human-readable representation of this shape.
-