net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion
Class Restrictions

java.lang.Object
  extended by net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions

public final class Restrictions
extends Object

The criterion package may be used by applications as a framework for building new kinds of Criterion. However, it is intended that most applications will simply use the built-in criterion types via the static factory methods of this class.

Version:
$Id: Restrictions.java 2923 2010-08-29 08:58:29Z fgiust $
Author:
fgiust, Federico Grilli

Method Summary
static LogicalExpression and(Criterion lhs, Criterion rhs)
          Return the conjuction of two expressions
static Criterion between(String nodeName, Object lo, Object hi)
          Apply a "between" constraint to the named node
static Criterion betweenDates(String nodeName, Calendar lo, Calendar hi)
          Adds a date contraint: the input date must be included in the given dates (between 00:00 of the first date to 23:59 of the last date)
static Conjunction conjunction()
          Group expressions together in a single conjunction (A and B and C...)
static JCRFunctionExpression contains(String nodeName, Object value)
          Apply a "contains" constraint to the named node.
static JCRFunctionExpression contains(String nodeName, Object value, boolean escape)
          Apply a "contains" constraint to the named node.
static Disjunction disjunction()
          Group expressions together in a single disjunction (A or B or C...)
static SimpleExpression eq(String nodeName, Object value)
          Apply an "equal" constraint to the named node
static Criterion eqDate(String nodeName, Calendar value)
          Adds a date contraint: the input date must be included in the given date, excluding time (between 00:00 and 23:59 of the given date)
static SimpleExpression ge(String nodeName, Object value)
          Apply a "greater than or equal" constraint to the named node
static SimpleExpression gt(String nodeName, Object value)
          Apply a "greater than" constraint to the named node
static Criterion in(String nodeName, Collection<String> values)
          Apply an "in" constraint to the named node
static Criterion in(String nodeName, String[] values)
          Apply an "in" constraint to the named node
static Criterion isNotNull(String nodeName)
          Apply an "is not null" constraint to the named node
static Criterion isNull(String nodeName)
          Apply an "is null" constraint to the named node
static SimpleExpression le(String nodeName, Object value)
          Apply a "less than or equal" constraint to the named node
static JCRFunctionExpression like(String nodeName, Object value)
          Apply a "like" constraint of type MatchMode.ANYWHERE to the named node

Be warned when using jcr:like function, as it can be very slow.

The following account of why it is so, was taken from users@jackrabbit.apache.org mailing list
Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete.
static JCRFunctionExpression like(String nodeName, Object value, MatchMode matchMode)
          Apply a "like" constraint to the named node

Be warned when using jcr:like function, as it can be very slow.

The following account of why it is so, was taken from users@jackrabbit.apache.org mailing list
Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete.
static SimpleExpression lt(String nodeName, Object value)
          Apply a "less than" constraint to the named node
static SimpleExpression ne(String nodeName, Object value)
          Apply a "not equal" constraint to the named node
static Criterion not(Criterion expression)
          Return the negation of an expression
static LogicalExpression or(Criterion lhs, Criterion rhs)
          Return the disjuction of two expressions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

eq

public static SimpleExpression eq(String nodeName,
                                  Object value)
Apply an "equal" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

ne

public static SimpleExpression ne(String nodeName,
                                  Object value)
Apply a "not equal" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

like

public static JCRFunctionExpression like(String nodeName,
                                         Object value)
Apply a "like" constraint of type MatchMode.ANYWHERE to the named node

Be warned when using jcr:like function, as it can be very slow.

The following account of why it is so, was taken from users@jackrabbit.apache.org mailing list
  • Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete.
  • Answer: a jcr:like with % will be translated to a WildcardQuery lucene query. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?. So this is not a Jackrabbit implementation detail, but a general Lucene (and I think inverted indexes in general) issue [1]
  • Conclusion: Avoid % prefixes in jcr:like. Use jcr:contains when searching for a specific word. If jcr:contains is not suitable, you can work around the problem by creating a custom lucene analyzer for the specific propery (see IndexingConfiguration [2] at Index Analyzers).

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number.
Returns:
Criterion

like

public static JCRFunctionExpression like(String nodeName,
                                         Object value,
                                         MatchMode matchMode)
Apply a "like" constraint to the named node

Be warned when using jcr:like function, as it can be very slow.

The following account of why it is so, was taken from users@jackrabbit.apache.org mailing list
  • Question: My xpath is '//*[jcr:like(@propertyName, '%somevalue%')]' and it takes minutes to complete.
  • Answer: a jcr:like with % will be translated to a WildcardQuery lucene query. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards * or ?. So this is not a Jackrabbit implementation detail, but a general Lucene (and I think inverted indexes in general) issue [1]
  • Conclusion: Avoid % prefixes in jcr:like. Use jcr:contains when searching for a specific word. If jcr:contains is not suitable, you can work around the problem by creating a custom lucene analyzer for the specific propery (see IndexingConfiguration [2] at Index Analyzers).

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number.
matchMode - - one of MatchMode.START or MatchMode.END or MatchMode.ANYWHERE
Returns:
Criterion

contains

public static JCRFunctionExpression contains(String nodeName,
                                             Object value)
Apply a "contains" constraint to the named node. The value parameter will be escaped.

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number.
Returns:
Criterion

contains

public static JCRFunctionExpression contains(String nodeName,
                                             Object value,
                                             boolean escape)
Apply a "contains" constraint to the named node. Use this override with escape set to false if you want to keep the search-engine syntax enabled (you are sure that the search-expression is always syntactically correct).

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number.
escape - - if true, value will be escaped, avoiding JCRQueryException on query execution
Returns:
Criterion

gt

public static SimpleExpression gt(String nodeName,
                                  Object value)
Apply a "greater than" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

lt

public static SimpleExpression lt(String nodeName,
                                  Object value)
Apply a "less than" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

le

public static SimpleExpression le(String nodeName,
                                  Object value)
Apply a "less than or equal" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

ge

public static SimpleExpression ge(String nodeName,
                                  Object value)
Apply a "greater than or equal" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - - must be an instance of either String or Number or Calendar.
Returns:
Criterion

between

public static Criterion between(String nodeName,
                                Object lo,
                                Object hi)
Apply a "between" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
lo - value - must be an instance of either String or Number or Calendar.
hi - value - must be an instance of either String or Number or Calendar.
Returns:
Criterion

eqDate

public static Criterion eqDate(String nodeName,
                               Calendar value)
Adds a date contraint: the input date must be included in the given date, excluding time (between 00:00 and 23:59 of the given date)

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
value - date (time will be ignored)
Returns:
Criterion

betweenDates

public static Criterion betweenDates(String nodeName,
                                     Calendar lo,
                                     Calendar hi)
Adds a date contraint: the input date must be included in the given dates (between 00:00 of the first date to 23:59 of the last date)

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
lo - lower date
hi - higher date
Returns:
Criterion

in

public static Criterion in(String nodeName,
                           String[] values)
Apply an "in" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
values - - a String[]
Returns:
Criterion

in

public static Criterion in(String nodeName,
                           Collection<String> values)
Apply an "in" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
values - - a collection of String
Returns:
Criterion

isNull

public static Criterion isNull(String nodeName)
Apply an "is null" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
Returns:
Criterion

isNotNull

public static Criterion isNotNull(String nodeName)
Apply an "is not null" constraint to the named node

Parameters:
nodeName - - String a qualified (eg. nt:somenode) or unqualified (eg. somenode) node name. When a node is an attribute it must be preceded by the '@'character (eg. @nt:somenode)
Returns:
Criterion

and

public static LogicalExpression and(Criterion lhs,
                                    Criterion rhs)
Return the conjuction of two expressions

Parameters:
lhs - left expression
rhs - right expression
Returns:
Criterion

or

public static LogicalExpression or(Criterion lhs,
                                   Criterion rhs)
Return the disjuction of two expressions

Parameters:
lhs - left expression
rhs - right expression
Returns:
Criterion

not

public static Criterion not(Criterion expression)
Return the negation of an expression

Parameters:
expression - to be negated
Returns:
Criterion

conjunction

public static Conjunction conjunction()
Group expressions together in a single conjunction (A and B and C...)

Returns:
Conjunction

disjunction

public static Disjunction disjunction()
Group expressions together in a single disjunction (A or B or C...)

Returns:
Conjunction


Copyright © 2009-2010 Openmind. All Rights Reserved.