2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.query
;
13 import org
.hibernate
.Criteria
;
14 import org
.hibernate
.criterion
.Order
;
15 import org
.hibernate
.criterion
.Projection
;
16 import org
.hibernate
.criterion
.ProjectionList
;
17 import org
.hibernate
.criterion
.Property
;
19 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
21 public class Grouping
{
22 private String associatedObject
;
23 private String associatedObjectAlias
;
24 private String propertyName
;
25 protected String name
;
26 private SortOrder order
;
28 public Grouping(String propertyPath
, String name
, String associatedObjectAlias
, SortOrder order
) {
30 if((pos
= propertyPath
.indexOf('.', 0)) >= 0){
31 this.associatedObject
= propertyPath
.substring(0, pos
);
32 this.propertyName
= propertyPath
.substring(pos
+ 1);
34 this.propertyName
= propertyPath
;
38 this.associatedObjectAlias
= associatedObjectAlias
;
41 protected void setPropertyName(String propertyName
) {
42 this.propertyName
= propertyName
;
45 public String
getPropertyName() {
49 public String
getAssociatedObj() {
50 return associatedObject
;
53 public String
getAssociatedObjectAlias() {
54 return associatedObjectAlias
;
57 public String
getName() {
61 protected SortOrder
getOrder() {
65 public void addOrder(Criteria criteria
) {
67 if(order
.equals(SortOrder
.ASCENDING
)) {
68 criteria
.addOrder(Order
.asc(this.name
));
70 criteria
.addOrder(Order
.desc(this.name
));
75 public void addProjection(ProjectionList projectionList
) {
76 if(associatedObjectAlias
!= null) {
77 projectionList
.add(Property
.forName(associatedObjectAlias
+ "." + propertyName
).group(),name
);
79 projectionList
.add(Property
.forName(propertyName
).group(),name
);