Package org.apache.cayenne.exp
Class Property<E>
java.lang.Object
org.apache.cayenne.exp.Property<E>
- Type Parameters:
E
- The type this property returns.
public class Property<E> extends Object
A property in a DataObject
.
Used to construct Expressions quickly and with type-safety, and to construct Orderings.
Instances of this class are immutable.
Must be created via factory methods Property.create(..)
- Since:
- 4.0
- See Also:
create(String, Class)
,create(Expression, Class)
,create(String, Expression, Class)
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Property<E>
abs()
Property<E>
alias(String alias)
Creates alias with different name for this propertyOrdering
asc()
Ordering
ascInsensitive()
Orderings
ascInsensitives()
Orderings
ascs()
Property<E>
avg()
Expression
between(E lower, E upper)
Property<String>
concat(Object... args)
Arguments will be converted as follows: if argument is aProperty
than its expression will be used if argument is aExpression
than it will be used as is all other values will be converted to StringExpression
contains(String substring)
Creates an expression for a database "LIKE" query with the value converted to a pattern matching anywhere in the String.Expression
containsIgnoreCase(String value)
Same ascontains(String)
, only using case-insensitive comparison.Property<Long>
count()
Property<Long>
countDistinct()
static <T> Property<T>
create(String name, Class<? super T> type)
Creates property with name and typestatic <T> Property<T>
create(String name, Expression expression, Class<? super T> type)
Creates property with name, expression and typestatic <T> Property<T>
create(Expression expression, Class<? super T> type)
Creates property with expression and typestatic <T extends Persistent>
Property<T>createSelf(Class<? super T> type)
Creates "self" Property for persistent class.Ordering
desc()
Ordering
descInsensitive()
Orderings
descInsensitives()
Orderings
descs()
PrefetchTreeNode
disjoint()
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "disjoint" prefetch semantics.PrefetchTreeNode
disjointById()
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "disjoint by id" prefetch semantics.Property<Object>
dot(String property)
Constructs a property path by appending the argument to the existing property separated by a dot.<T> Property<T>
dot(Property<T> property)
Constructs a new property path by appending the argument to the existing property separated by a dot.Expression
endsWith(String value)
Creates an expression for a database "LIKE" query with the value converted to a pattern matching the tail of a String.Expression
endsWithIgnoreCase(String value)
Same asendsWith(String)
, only using case-insensitive comparison.Expression
eq(E value)
Expression
eq(Property<?> value)
boolean
equals(Object o)
<T extends Persistent>
Property<T>flat(Class<? super T> tClass)
Create new "flat" property for toMany relationship.String
getAlias()
Expression
getExpression()
This method returns fresh copy of the expression for each call.E
getFrom(Object bean)
Extracts property value from an object using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path.List<E>
getFromAll(Collection<?> beans)
Extracts property value from a collection of objects using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path.String
getName()
Class<? super E>
getType()
Expression
gt(E value)
Expression
gt(Property<?> value)
Expression
gte(E value)
Expression
gte(Property<?> value)
int
hashCode()
Expression
in(E firstValue, E... moreValues)
Expression
in(Collection<E> values)
Expression
isFalse()
Expression
isNotNull()
Expression
isNull()
Expression
isTrue()
PrefetchTreeNode
joint()
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "joint" prefetch semantics.Property<Integer>
length()
Expression
like(String pattern)
Expression
like(String pattern, char escapeChar)
Expression
likeIgnoreCase(String pattern)
Property<Integer>
locate(String string)
Property<Integer>
locate(Property<? extends String> property)
Property<String>
lower()
Expression
lt(E value)
Expression
lt(Property<?> value)
Expression
lte(E value)
Expression
lte(Property<?> value)
Property<E>
max()
Property<E>
min()
Property<E>
mod(Number number)
Expression
ne(E value)
Expression
ne(Property<?> value)
Expression
nin(E firstValue, E... moreValues)
Expression
nin(Collection<E> values)
Expression
nlike(String value)
Expression
nlikeIgnoreCase(String value)
Property<E>
outer()
Returns a version of this property that represents an OUTER join.Expression
path()
Converts this property to a path expression.void
setIn(Object bean, E value)
Sets a property value in 'obj' using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path.void
setInAll(Collection<?> beans, E value)
Sets a property value in a collection of objects using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path.Property<E>
sqrt()
Expression
startsWith(String value)
Creates an expression for a database "LIKE" query with the value converted to a pattern matching the beginning of a String.Expression
startsWithIgnoreCase(String value)
Same asstartsWith(String)
, only using case-insensitive comparison.Property<String>
substring(int offset, int length)
Property<E>
sum()
Property<String>
trim()
Property<String>
upper()
-
Field Details
-
COUNT
Property that can be used in COUNT(*) queries
List<Object[]> result = ObjectSelect .columnQuery(Artist.class, Property.COUNT, Artist.ARTIST_NAME) .having(Property.COUNT.gt(1L)) .select(context);
-
-
Constructor Details
-
Property
Constructs a new property with the given name and type.- Parameters:
name
- of the property (usually it's obj path)type
- of the property- See Also:
create(String, Class)
-
Property
Constructs a new property with the given name and expression- Parameters:
name
- of the property (will be used as alias for the expression)expression
- expression for propertytype
- of the property- See Also:
create(String, Expression, Class)
-
-
Method Details
-
getName
- Returns:
- Name of the property in the object.
-
getAlias
- Returns:
- alias for this property
-
getExpression
This method returns fresh copy of the expression for each call.- Returns:
- expression that represents this Property
-
hashCode
public int hashCode() -
equals
-
dot
Constructs a property path by appending the argument to the existing property separated by a dot.- Returns:
- a newly created Property object.
-
dot
Constructs a new property path by appending the argument to the existing property separated by a dot.- Returns:
- a newly created Property object.
-
outer
Returns a version of this property that represents an OUTER join. It is up to caller to ensure that the property corresponds to a relationship, as "outer" attributes make no sense. -
path
Converts this property to a path expression. This method is equivalent of getExpression() which is preferred as more generic.- Returns:
- a newly created expression.
- See Also:
getExpression()
-
isNull
- Returns:
- An expression representing null.
-
isNotNull
- Returns:
- An expression representing a non-null value.
-
isTrue
- Returns:
- An expression representing equality to TRUE.
-
isFalse
- Returns:
- An expression representing equality to FALSE.
-
eq
- Returns:
- An expression representing equality to a value.
-
eq
- Returns:
- An expression representing equality between two attributes (columns).
-
ne
- Returns:
- An expression representing inequality to a value.
-
ne
- Returns:
- An expression representing inequality between two attributes (columns).
-
like
- Parameters:
pattern
- a pattern matching property value. Pattern may include "_" and "%" wildcard symbols to match any single character or a sequence of characters. To prevent "_" and "%" from being treated as wildcards, they need to be escaped and escape char passed withlike(String, char)
method.- Returns:
- An expression for a Database "LIKE" query.
-
like
- Parameters:
pattern
- a properly escaped pattern matching property value. Pattern may include "_" and "%" wildcard symbols to match any single character or a sequence of characters.escapeChar
- an escape character used in the pattern to escape "%" and "_".- Returns:
- An expression for a Database "LIKE" query.
-
likeIgnoreCase
- Returns:
- An expression for a case insensitive "LIKE" query.
-
nlike
- Returns:
- An expression for a Database "NOT LIKE" query.
-
nlikeIgnoreCase
- Returns:
- An expression for a case insensitive "NOT LIKE" query.
-
contains
Creates an expression for a database "LIKE" query with the value converted to a pattern matching anywhere in the String.- Parameters:
substring
- a String to match against property value. "_" and "%" symbols are NOT treated as wildcards and are escaped when converted to a LIKE expression.- Returns:
- a newly created expression.
-
startsWith
Creates an expression for a database "LIKE" query with the value converted to a pattern matching the beginning of a String.- Parameters:
value
- a String to match against property value. "_" and "%" symbols are NOT treated as wildcards and are escaped when converted to a LIKE expression.- Returns:
- a newly created expression.
-
endsWith
Creates an expression for a database "LIKE" query with the value converted to a pattern matching the tail of a String.- Parameters:
value
- a String to match against property value. "_" and "%" symbols are NOT treated as wildcards and are escaped when converted to a LIKE expression.- Returns:
- a newly created expression.
-
containsIgnoreCase
Same ascontains(String)
, only using case-insensitive comparison. -
startsWithIgnoreCase
Same asstartsWith(String)
, only using case-insensitive comparison. -
endsWithIgnoreCase
Same asendsWith(String)
, only using case-insensitive comparison. -
between
- Parameters:
lower
- The lower bound.upper
- The upper bound.- Returns:
- An expression checking for objects between a lower and upper bound inclusive
-
in
- Returns:
- An expression for finding objects with values in the given set.
-
nin
- Returns:
- An expression for finding objects with values not in the given set.
-
in
- Returns:
- An expression for finding objects with values in the given set.
-
nin
- Returns:
- An expression for finding objects with values not in the given set.
-
gt
- Returns:
- A greater than Expression.
-
gt
- Returns:
- Represents a greater than relationship between two attributes (columns).
-
gte
- Returns:
- A greater than or equal to Expression.
-
gte
- Returns:
- Represents a greater than or equal relationship between two attributes (columns).
-
lt
- Returns:
- A less than Expression.
-
lt
- Returns:
- Represents a less than relationship between two attributes (columns).
-
lte
- Returns:
- A less than or equal to Expression.
-
lte
- Returns:
- Represents a less than or equal relationship between two attributes (columns).
-
asc
- Returns:
- Ascending sort orderings on this property.
-
ascs
- Returns:
- Ascending sort orderings on this property.
-
ascInsensitive
- Returns:
- Ascending case insensitive sort orderings on this property.
-
ascInsensitives
- Returns:
- Ascending case insensitive sort orderings on this property.
-
desc
- Returns:
- Descending sort orderings on this property.
-
descs
- Returns:
- Descending sort orderings on this property.
-
descInsensitive
- Returns:
- Descending case insensitive sort orderings on this property.
-
descInsensitives
- Returns:
- Descending case insensitive sort orderings on this property.
-
joint
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "joint" prefetch semantics. -
disjoint
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "disjoint" prefetch semantics. -
disjointById
Returns a prefetch tree that follows this property path, potentially spanning a number of phantom nodes, and having a single leaf with "disjoint by id" prefetch semantics. -
getFrom
Extracts property value from an object using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path. -
getFromAll
Extracts property value from a collection of objects using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path. -
setIn
Sets a property value in 'obj' using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path. -
setInAll
Sets a property value in a collection of objects using JavaBean-compatible introspection with one addition - a property can be a dot-separated property name path. -
count
-
countDistinct
- Since:
- 4.1
- See Also:
FunctionExpressionFactory.countDistinctExp(Expression)
-
max
-
min
-
avg
-
sum
-
mod
-
abs
-
sqrt
-
length
-
locate
-
locate
-
trim
-
upper
-
lower
-
concat
Arguments will be converted as follows:
- if argument is a
Property
than its expression will be used - if argument is a
Expression
than it will be used as is - all other values will be converted to String
Usage:
Property<String> fullName = Artist.FIRST_NAME.concat(" ", Artist.SECOND_NAME);
- if argument is a
-
substring
-
alias
Creates alias with different name for this property -
flat
Create new "flat" property for toMany relationship.
Example:
List<Object[]> result = ObjectSelect .columnQuery(Artist.class, Artist.ARTIST_NAME, Artist.PAINTING_ARRAY.flat(Painting.class)) .select(context);
-
getType
-
create
Creates property with name and type -
create
Creates property with expression and type -
create
Creates property with name, expression and type- See Also:
create(String, Class)
,create(Expression, Class)
-
createSelf
Creates "self" Property for persistent class. This property can be used to select full object along with some of it properties (or properties that can be resolved against query root)
Here is sample code, that will select all Artists and count of their Paintings:
Property<Artist> artistFull = Property.createSelf(Artist.class); List<Object[]> result = ObjectSelect .columnQuery(Artist.class, artistFull, Artist.PAINTING_ARRAY.count()) .select(context);
-