~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to src/org/hibernate/criterion/Projections.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//$Id: Projections.java 6970 2005-05-31 20:24:41Z oneovthafew $
 
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 propertyName) {
 
49
                return new CountProjection(propertyName);
 
50
        }
 
51
        
 
52
        /**
 
53
         * A distinct property value count
 
54
         */
 
55
        public static CountProjection countDistinct(String propertyName) {
 
56
                return new CountProjection(propertyName).setDistinct();
 
57
        }
 
58
        
 
59
        /**
 
60
         * A property maximum value
 
61
         */
 
62
        public static AggregateProjection max(String propertyName) {
 
63
                return new AggregateProjection("max", propertyName);
 
64
        }
 
65
        
 
66
        /**
 
67
         * A property minimum value
 
68
         */
 
69
        public static AggregateProjection min(String propertyName) {
 
70
                return new AggregateProjection("min", propertyName);
 
71
        }
 
72
        
 
73
        /**
 
74
         * A property average value
 
75
         */
 
76
        public static AggregateProjection avg(String propertyName) {
 
77
                return new AvgProjection(propertyName);
 
78
        }
 
79
        
 
80
        /**
 
81
         * A property value sum
 
82
         */
 
83
        public static AggregateProjection sum(String 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 sql, String[] 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 sql, String groupBy, String[] 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 propertyName) {
 
105
                return new PropertyProjection(propertyName, true);
 
106
        }
 
107
        
 
108
        /**
 
109
         * A projected property value
 
110
         */
 
111
        public static PropertyProjection property(String 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 alias) {
 
126
                return new AliasedProjection(projection, alias);
 
127
        }
 
128
}