KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > criterion > Projections


1 //$Id: Projections.java,v 1.13 2005/05/31 20:24:39 oneovthafew Exp $
2
package org.hibernate.criterion;
3
4 import org.hibernate.type.Type;
5
6 /**
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/>
10  * <br/>
11  * The factory methods that take an alias allow the projected value to be referred to by
12  * criterion and order instances.
13  *
14  * @see org.hibernate.Criteria
15  * @see Restrictions factory methods for <tt>Criterion</tt> instances
16  * @author Gavin King
17  */

18 public final class Projections {
19
20     private Projections() {
21         //cannot be instantiated
22
}
23     
24     /**
25      * Create a distinct projection from a projection
26      */

27     public static Projection distinct(Projection proj) {
28         return new Distinct(proj);
29     }
30     
31     /**
32      * Create a new projection list
33      */

34     public static ProjectionList projectionList() {
35         return new ProjectionList();
36     }
37         
38     /**
39      * The query row count, ie. <tt>count(*)</tt>
40      */

41     public static Projection rowCount() {
42         return new RowCountProjection();
43     }
44     
45     /**
46      * A property value count
47      */

48     public static CountProjection count(String JavaDoc propertyName) {
49         return new CountProjection(propertyName);
50     }
51     
52     /**
53      * A distinct property value count
54      */

55     public static CountProjection countDistinct(String JavaDoc propertyName) {
56         return new CountProjection(propertyName).setDistinct();
57     }
58     
59     /**
60      * A property maximum value
61      */

62     public static AggregateProjection max(String JavaDoc propertyName) {
63         return new AggregateProjection("max", propertyName);
64     }
65     
66     /**
67      * A property minimum value
68      */

69     public static AggregateProjection min(String JavaDoc propertyName) {
70         return new AggregateProjection("min", propertyName);
71     }
72     
73     /**
74      * A property average value
75      */

76     public static AggregateProjection avg(String JavaDoc propertyName) {
77         return new AvgProjection(propertyName);
78     }
79     
80     /**
81      * A property value sum
82      */

83     public static AggregateProjection sum(String JavaDoc propertyName) {
84         return new AggregateProjection("sum", propertyName);
85     }
86     
87     /**
88      * A SQL projection, a typed select clause fragment
89      */

90     public static Projection sqlProjection(String JavaDoc sql, String JavaDoc[] columnAliases, Type[] types) {
91         return new SQLProjection(sql, columnAliases, types);
92     }
93     
94     /**
95      * A grouping SQL projection, specifying both select clause and group by clause fragments
96      */

97     public static Projection sqlGroupProjection(String JavaDoc sql, String JavaDoc groupBy, String JavaDoc[] columnAliases, Type[] types) {
98         return new SQLProjection(sql, groupBy, columnAliases, types);
99     }
100
101     /**
102      * A grouping property value
103      */

104     public static PropertyProjection groupProperty(String JavaDoc propertyName) {
105         return new PropertyProjection(propertyName, true);
106     }
107     
108     /**
109      * A projected property value
110      */

111     public static PropertyProjection property(String JavaDoc propertyName) {
112         return new PropertyProjection(propertyName);
113     }
114     
115     /**
116      * A projected identifier value
117      */

118     public static IdentifierProjection id() {
119         return new IdentifierProjection();
120     }
121     
122     /**
123      * Assign an alias to a projection, by wrapping it
124      */

125     public static Projection alias(Projection projection, String JavaDoc alias) {
126         return new AliasedProjection(projection, alias);
127     }
128 }
129
Popular Tags