2 * Copyright (C) 2007 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
.dao
.hibernate
.common
;
12 import java
.util
.Collections
;
13 import java
.util
.Comparator
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
18 import org
.hibernate
.Criteria
;
19 import org
.hibernate
.Session
;
20 import org
.hibernate
.SessionFactory
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
25 public abstract class DaoBase
{
28 private SessionFactory factory
;
30 public void setSessionFactory(SessionFactory sessionFactory
) {
31 this.factory
= sessionFactory
;
34 protected Session
getSession(){
35 Session session
= factory
.getCurrentSession();
43 private class OrderHintComparator
implements Comparator
<OrderHint
> {
45 public int compare(OrderHint o1
, OrderHint o2
) {
46 return o1
.getPropertyName().compareTo(o2
.getPropertyName());
51 protected void addOrder(Criteria criteria
, List
<OrderHint
> orderHints
) {
53 if(orderHints
!= null){
54 Collections
.sort(orderHints
, new OrderHintComparator());
56 Map
<String
,Criteria
> criteriaMap
= new HashMap
<String
,Criteria
>();
57 for(OrderHint orderHint
: orderHints
){
58 orderHint
.add(criteria
,criteriaMap
);