Project

General

Profile

Download (1.57 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.dao.hibernate.common;
11

    
12
import java.util.Collections;
13
import java.util.Comparator;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17

    
18
import org.hibernate.Criteria;
19
import org.hibernate.Session;
20
import org.hibernate.SessionFactory;
21
import org.springframework.beans.factory.annotation.Autowired;
22

    
23
import eu.etaxonomy.cdm.persistence.query.OrderHint;
24

    
25
public abstract class DaoBase {
26
	
27
	@Autowired
28
	private SessionFactory factory;
29
	
30
	public void setSessionFactory(SessionFactory sessionFactory) {
31
		this.factory = sessionFactory;
32
	}
33
	public SessionFactory getSessionFactory() {
34
		return factory;
35
	}
36
	protected Session getSession(){
37
		Session session = factory.getCurrentSession();
38
		return session;
39
	}
40
	
41
	public void flush(){
42
		getSession().flush();
43
	}
44
	
45
	private class OrderHintComparator implements Comparator<OrderHint> {
46

    
47
		public int compare(OrderHint o1, OrderHint o2) {
48
			return o1.getPropertyName().compareTo(o2.getPropertyName());
49
		}
50
		
51
	}
52
	
53
	protected void addOrder(Criteria criteria, List<OrderHint> orderHints) {
54
		
55
		if(orderHints != null){
56
			Collections.sort(orderHints, new OrderHintComparator());
57
			
58
			Map<String,Criteria> criteriaMap = new HashMap<String,Criteria>();
59
			for(OrderHint orderHint : orderHints){
60
				orderHint.add(criteria,criteriaMap);
61
			}
62
		}
63
	}
64

    
65
}
(5-5/20)