1
//$Id: Projections.java 6970 2005-05-31 20:24:41Z oneovthafew $
2
package org.hibernate.criterion;
4
import org.hibernate.type.Type;
7
* The <tt>criterion</tt> package may be used by applications as a framework for building
8
* new kinds of <tt>Projection</tt>. However, it is intended that most applications will
9
* simply use the built-in projection types via the static factory methods of this class.<br/>
11
* The factory methods that take an alias allow the projected value to be referred to by
12
* criterion and order instances.
14
* @see org.hibernate.Criteria
15
* @see Restrictions factory methods for <tt>Criterion</tt> instances
18
public final class Projections {
20
private Projections() {
21
//cannot be instantiated
25
* Create a distinct projection from a projection
27
public static Projection distinct(Projection proj) {
28
return new Distinct(proj);
32
* Create a new projection list
34
public static ProjectionList projectionList() {
35
return new ProjectionList();
39
* The query row count, ie. <tt>count(*)</tt>
41
public static Projection rowCount() {
42
return new RowCountProjection();
46
* A property value count
48
public static CountProjection count(String propertyName) {
49
return new CountProjection(propertyName);
53
* A distinct property value count
55
public static CountProjection countDistinct(String propertyName) {
56
return new CountProjection(propertyName).setDistinct();
60
* A property maximum value
62
public static AggregateProjection max(String propertyName) {
63
return new AggregateProjection("max", propertyName);
67
* A property minimum value
69
public static AggregateProjection min(String propertyName) {
70
return new AggregateProjection("min", propertyName);
74
* A property average value
76
public static AggregateProjection avg(String propertyName) {
77
return new AvgProjection(propertyName);
81
* A property value sum
83
public static AggregateProjection sum(String propertyName) {
84
return new AggregateProjection("sum", propertyName);
88
* A SQL projection, a typed select clause fragment
90
public static Projection sqlProjection(String sql, String[] columnAliases, Type[] types) {
91
return new SQLProjection(sql, columnAliases, types);
95
* A grouping SQL projection, specifying both select clause and group by clause fragments
97
public static Projection sqlGroupProjection(String sql, String groupBy, String[] columnAliases, Type[] types) {
98
return new SQLProjection(sql, groupBy, columnAliases, types);
102
* A grouping property value
104
public static PropertyProjection groupProperty(String propertyName) {
105
return new PropertyProjection(propertyName, true);
109
* A projected property value
111
public static PropertyProjection property(String propertyName) {
112
return new PropertyProjection(propertyName);
116
* A projected identifier value
118
public static IdentifierProjection id() {
119
return new IdentifierProjection();
123
* Assign an alias to a projection, by wrapping it
125
public static Projection alias(Projection projection, String alias) {
126
return new AliasedProjection(projection, alias);