to.etc.webapp.query
Class QSelection<T>

java.lang.Object
  extended by to.etc.webapp.query.QRestrictor<T>
      extended by to.etc.webapp.query.QCriteriaQueryBase<T>
          extended by to.etc.webapp.query.QSelection<T>

public class QSelection<T>
extends QCriteriaQueryBase<T>

Represents a selection of data elements from a database. This differs from a QCriteria in that it collects not one persistent class instance per row but multiple items per row, and each item can either be a persistent class or some property or calculated value (max, min, count et al).

Even though this type has a generic type parameter representing the base object being queried, the list() method for this object will return a List always.

QSelection queries return an array of items for each row, and each element of the array is typed depending on it's source. In addition, QSelection queries expose the ability to handle grouping. QSelection criteria behave as and should be seen as SQL queries in an OO wrapping.

Author:
Frits Jalvingh Created on Jul 14, 2009

Method Summary
 QSelection<T> add(QOperatorNode r)
          
 QSelection<T> add(QOrder r)
          Add an order clause to the list of sort items.
 void addColumn(QSelectionItem item, java.lang.String alias)
          Add a column selector to the selection list.
 void addPropertySelection(QSelectionFunction f, java.lang.String prop, java.lang.String alias)
          Add a simple property selector to the list.
 QSelection<T> ascending(java.lang.String property)
          Add a property to do an ascending sort on.
 QSelection<T> avg(java.lang.String property)
          Select the average value of a property in the set.
 QSelection<T> avg(java.lang.String property, java.lang.String alias)
          Select the average value of a property in the set.
 QSelection<T> between(java.lang.String property, java.lang.Object a, java.lang.Object b)
          Compare the value of a property with two literal bounds.
 QSelection<T> count(java.lang.String property)
          Select a count over the result set.
 QSelection<T> count(java.lang.String property, java.lang.String alias)
          Select a count over the result set.
 QSelection<T> countDistinct(java.lang.String property)
          Select a count of the distinct values over the result set.
 QSelection<T> countDistinct(java.lang.String property, java.lang.String alias)
          Select a count of the distinct values over the result set.
static
<T> QSelection<T>
create(java.lang.Class<T> root)
          Create a selection query based on the specified persistent class (public API).
 QSelection<T> descending(java.lang.String property)
          Add a property to do a descending sort on.
 QSelection<T> eq(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> eq(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> eq(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> ge(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> ge(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> ge(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> gt(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> gt(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> gt(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> ilike(java.lang.String property, java.lang.Object value)
          Do a case-independent 'like' comparison.
 QSelection<T> isnotnull(java.lang.String property)
          Add the restriction that the property specified must be not-null.
 QSelection<T> isnull(java.lang.String property)
          Add the restriction that the property specified must be null.
 QSelection<T> le(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> le(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> le(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> like(java.lang.String property, java.lang.Object value)
          Do a 'like' comparison.
 QSelection<T> lt(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> lt(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> lt(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> max(java.lang.String property)
          Select the max of a property in the set.
 QSelection<T> max(java.lang.String property, java.lang.String alias)
          Select the max of a property in the set.
 QSelection<T> min(java.lang.String property)
          Select the minimal value of a property in the set.
 QSelection<T> min(java.lang.String property, java.lang.String alias)
          Select the minimal value of a property in the set.
 QSelection<T> ne(java.lang.String property, double value)
          Compare a property with some literal object value.
 QSelection<T> ne(java.lang.String property, long value)
          Compare a property with some literal object value.
 QSelection<T> ne(java.lang.String property, java.lang.Object value)
          Compare a property with some literal object value.
 QSelection<T> or(QOperatorNode a1, QOperatorNode a2, QOperatorNode... a)
          Deprecated. 
 QSelection<T> selectProperty(java.lang.String property)
          Select a property value from the base property in the result set.
 QSelection<T> selectProperty(java.lang.String property, java.lang.String alias)
          Select a property value from the base property in the result set.
 QSelection<T> sqlCondition(java.lang.String sql)
          Add a restriction specified in bare SQL.
 QSelection<T> sum(java.lang.String property)
          Select the sum of a property in the set.
 QSelection<T> sum(java.lang.String property, java.lang.String alias)
          Select the sum of a property in the set.
 java.lang.String toString()
           
 void visit(QNodeVisitor v)
           
 
Methods inherited from class to.etc.webapp.query.QCriteriaQueryBase
getColumnList, getLimit, getOption, getOrder, getRestrictions, getStart, hasOption, limit, setOption, setRestrictions, start
 
Methods inherited from class to.etc.webapp.query.QRestrictor
and, exists, getBaseClass, getMetaTable, getReturnClass, hasRestrictions, internalAdd, or
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static <T> QSelection<T> create(java.lang.Class<T> root)
Create a selection query based on the specified persistent class (public API).

Type Parameters:
T - The base type being queried
Parameters:
root - The class representing the base type being queried, thanks to the brilliant Java Generics implementation.
Returns:

visit

public void visit(QNodeVisitor v)
           throws java.lang.Exception
Throws:
java.lang.Exception

addColumn

public void addColumn(QSelectionItem item,
                      java.lang.String alias)
Add a column selector to the selection list.

Overrides:
addColumn in class QCriteriaQueryBase<T>

addPropertySelection

public void addPropertySelection(QSelectionFunction f,
                                 java.lang.String prop,
                                 java.lang.String alias)
Add a simple property selector to the list.

Overrides:
addPropertySelection in class QCriteriaQueryBase<T>

avg

public QSelection<T> avg(java.lang.String property,
                         java.lang.String alias)
Select the average value of a property in the set. This will cause a group by.

Overrides:
avg in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

avg

public QSelection<T> avg(java.lang.String property)
Select the average value of a property in the set. This will cause a group by.

Overrides:
avg in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

count

public QSelection<T> count(java.lang.String property,
                           java.lang.String alias)
Select a count over the result set.

Overrides:
count in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

count

public QSelection<T> count(java.lang.String property)
Select a count over the result set.

Overrides:
count in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

countDistinct

public QSelection<T> countDistinct(java.lang.String property,
                                   java.lang.String alias)
Select a count of the distinct values over the result set.

Overrides:
countDistinct in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

countDistinct

public QSelection<T> countDistinct(java.lang.String property)
Select a count of the distinct values over the result set.

Overrides:
countDistinct in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

max

public QSelection<T> max(java.lang.String property,
                         java.lang.String alias)
Select the max of a property in the set. This will cause a group by.

Overrides:
max in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

max

public QSelection<T> max(java.lang.String property)
Select the max of a property in the set. This will cause a group by.

Overrides:
max in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

min

public QSelection<T> min(java.lang.String property,
                         java.lang.String alias)
Select the minimal value of a property in the set. This will cause a group by.

Overrides:
min in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

min

public QSelection<T> min(java.lang.String property)
Select the minimal value of a property in the set. This will cause a group by.

Overrides:
min in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

selectProperty

public QSelection<T> selectProperty(java.lang.String property,
                                    java.lang.String alias)
Select a property value from the base property in the result set.

Overrides:
selectProperty in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

selectProperty

public QSelection<T> selectProperty(java.lang.String property)
Select a property value from the base property in the result set.

Overrides:
selectProperty in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

sum

public QSelection<T> sum(java.lang.String property,
                         java.lang.String alias)
Select the sum of a property in the set. This will cause a group by.

Overrides:
sum in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
alias - The alias for using the property in the restrictions clause.
Returns:

sum

public QSelection<T> sum(java.lang.String property)
Select the sum of a property in the set. This will cause a group by.

Overrides:
sum in class QCriteriaQueryBase<T>
Parameters:
property - The property whose literal value is to be selected
Returns:

add

public QSelection<T> add(QOperatorNode r)

Overrides:
add in class QRestrictor<T>
See Also:
QRestrictor.add(to.etc.webapp.query.QOperatorNode)

add

public QSelection<T> add(QOrder r)
Add an order clause to the list of sort items.

Overrides:
add in class QCriteriaQueryBase<T>
Returns:
See Also:
QCriteriaQueryBase.add(to.etc.webapp.query.QOrder)

ascending

public QSelection<T> ascending(java.lang.String property)
Add a property to do an ascending sort on.

Overrides:
ascending in class QCriteriaQueryBase<T>
Returns:
See Also:
QCriteriaQueryBase.ascending(java.lang.String)

between

public QSelection<T> between(java.lang.String property,
                             java.lang.Object a,
                             java.lang.Object b)
Compare the value of a property with two literal bounds.

Overrides:
between in class QRestrictor<T>
Returns:
See Also:
QRestrictor.between(java.lang.String, java.lang.Object, java.lang.Object)

descending

public QSelection<T> descending(java.lang.String property)
Add a property to do a descending sort on.

Overrides:
descending in class QCriteriaQueryBase<T>
Returns:
See Also:
QCriteriaQueryBase.descending(java.lang.String)

eq

public QSelection<T> eq(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
eq in class QRestrictor<T>
Returns:
See Also:
QRestrictor.eq(java.lang.String, double)

eq

public QSelection<T> eq(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
eq in class QRestrictor<T>
Returns:
See Also:
QRestrictor.eq(java.lang.String, long)

eq

public QSelection<T> eq(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
eq in class QRestrictor<T>
Returns:
See Also:
QRestrictor.eq(java.lang.String, java.lang.Object)

ge

public QSelection<T> ge(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
ge in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ge(java.lang.String, double)

ge

public QSelection<T> ge(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
ge in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ge(java.lang.String, long)

ge

public QSelection<T> ge(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
ge in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ge(java.lang.String, java.lang.Object)

gt

public QSelection<T> gt(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
gt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.gt(java.lang.String, double)

gt

public QSelection<T> gt(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
gt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.gt(java.lang.String, long)

gt

public QSelection<T> gt(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
gt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.gt(java.lang.String, java.lang.Object)

ilike

public QSelection<T> ilike(java.lang.String property,
                           java.lang.Object value)
Do a case-independent 'like' comparison. The wildcard marks here are always %; a literal % is to be presented as \%. The comparison is case-independent.

Overrides:
ilike in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ilike(java.lang.String, java.lang.Object)

isnotnull

public QSelection<T> isnotnull(java.lang.String property)
Add the restriction that the property specified must be not-null.

Overrides:
isnotnull in class QRestrictor<T>
Returns:
See Also:
QRestrictor.isnotnull(java.lang.String)

isnull

public QSelection<T> isnull(java.lang.String property)
Add the restriction that the property specified must be null.

Overrides:
isnull in class QRestrictor<T>
Returns:
See Also:
QRestrictor.isnull(java.lang.String)

le

public QSelection<T> le(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
le in class QRestrictor<T>
Returns:
See Also:
QRestrictor.le(java.lang.String, double)

le

public QSelection<T> le(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
le in class QRestrictor<T>
Returns:
See Also:
QRestrictor.le(java.lang.String, long)

le

public QSelection<T> le(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
le in class QRestrictor<T>
Returns:
See Also:
QRestrictor.le(java.lang.String, java.lang.Object)

like

public QSelection<T> like(java.lang.String property,
                          java.lang.Object value)
Do a 'like' comparison. The wildcard marks here are always %; a literal % is to be presented as \%. The comparison is case-dependent.

Overrides:
like in class QRestrictor<T>
Returns:
See Also:
QRestrictor.like(java.lang.String, java.lang.Object)

lt

public QSelection<T> lt(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
lt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.lt(java.lang.String, double)

lt

public QSelection<T> lt(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
lt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.lt(java.lang.String, long)

lt

public QSelection<T> lt(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
lt in class QRestrictor<T>
Returns:
See Also:
QRestrictor.lt(java.lang.String, java.lang.Object)

ne

public QSelection<T> ne(java.lang.String property,
                        double value)
Compare a property with some literal object value.

Overrides:
ne in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ne(java.lang.String, double)

ne

public QSelection<T> ne(java.lang.String property,
                        long value)
Compare a property with some literal object value.

Overrides:
ne in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ne(java.lang.String, long)

ne

public QSelection<T> ne(java.lang.String property,
                        java.lang.Object value)
Compare a property with some literal object value.

Overrides:
ne in class QRestrictor<T>
Returns:
See Also:
QRestrictor.ne(java.lang.String, java.lang.Object)

or

@Deprecated
public QSelection<T> or(QOperatorNode a1,
                                   QOperatorNode a2,
                                   QOperatorNode... a)
Deprecated. 

Add a set of OR nodes to the set.

Overrides:
or in class QRestrictor<T>
Returns:
See Also:
to.etc.webapp.query.QCriteriaQueryBase#or(to.etc.webapp.query.QOperatorNode[])

sqlCondition

public QSelection<T> sqlCondition(java.lang.String sql)
Add a restriction specified in bare SQL. This is implementation-dependent.

Overrides:
sqlCondition in class QRestrictor<T>
Returns:
See Also:
QRestrictor.sqlCondition(java.lang.String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object