Project

General

Profile

Download (2.07 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/ 
9

    
10
package eu.etaxonomy.cdm.persistence.query;
11

    
12

    
13
import org.hibernate.Criteria;
14
import org.hibernate.criterion.Order;
15
import org.hibernate.criterion.ProjectionList;
16
import org.hibernate.criterion.Property;
17

    
18
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
19

    
20
public class Grouping {
21
	private String associatedObject;
22
	private String associatedObjectAlias;
23
	private String propertyName;
24
	protected String name;
25
	private SortOrder order;
26
	
27
	public Grouping(String propertyPath, String name,  String associatedObjectAlias, SortOrder order) {
28
        int pos;
29
        if((pos = propertyPath.indexOf('.', 0)) >= 0){
30
    	    this.associatedObject = propertyPath.substring(0, pos);
31
            this.propertyName = propertyPath.substring(pos + 1);
32
        } else {
33
            this.propertyName = propertyPath;
34
        }
35
        this.name = name;
36
        this.order = order;
37
        this.associatedObjectAlias = associatedObjectAlias;
38
	}
39
	
40
	protected void setPropertyName(String propertyName) {
41
		this.propertyName = propertyName;
42
	}
43

    
44
	public String getPropertyName() {
45
		return propertyName;
46
	}
47

    
48
	public String getAssociatedObj() {
49
		return associatedObject;
50
	}
51
	
52
	public String getAssociatedObjectAlias() {
53
		return associatedObjectAlias;
54
	}
55

    
56
	public String getName() {
57
		return name;
58
	}
59
	
60
	protected SortOrder getOrder() {
61
		return order;
62
	}
63

    
64
	public void addOrder(Criteria criteria) {
65
		if(order != null) {
66
			if(order.equals(SortOrder.ASCENDING)) {
67
				criteria.addOrder(Order.asc(this.name));
68
			} else {
69
				criteria.addOrder(Order.desc(this.name));
70
			}
71
		}
72
	}
73

    
74
	public void addProjection(ProjectionList projectionList) {
75
		if(associatedObjectAlias != null) {
76
		    projectionList.add(Property.forName(associatedObjectAlias + "." + propertyName).group(),name);
77
		} else {
78
			projectionList.add(Property.forName(propertyName).group(),name);
79
		}
80
	}
81

    
82
}
(4-4/10)