Project

General

Profile

Download (1.95 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 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
package eu.etaxonomy.cdm.database;
10

    
11
import java.util.List;
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15
import org.hibernate.Criteria;
16
import org.hibernate.Session;
17
import org.hibernate.SessionFactory;
18
import org.hibernate.criterion.Order;
19
import org.hibernate.criterion.Restrictions;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.dao.DataAccessException;
22
import org.springframework.stereotype.Repository;
23

    
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25

    
26
/**
27
 * @author a.mueller
28
 \* @since 05.11.2015
29
 *
30
 */
31
@Repository
32
public class TestingTermVocabularyDao {
33
    private static final Logger logger = Logger.getLogger(TestingTermVocabularyDao.class);
34

    
35

    
36
    @Autowired
37
    private SessionFactory factory;
38

    
39
    protected TermVocabulary<?> findByUuid(UUID uuid) throws DataAccessException{
40
        Session session = getSession();
41
        Criteria crit = session.createCriteria(TermVocabulary.class);
42
        crit.add(Restrictions.eq("uuid", uuid));
43
        crit.addOrder(Order.desc("created"));
44
        @SuppressWarnings("unchecked")
45
        List<TermVocabulary<?>> results = crit.list();
46
        if (results.isEmpty()){
47
            return null;
48
        }else{
49
            if(results.size() > 1){
50
                logger.error("findByUuid() delivers more than one result for UUID: " + uuid);
51
            }
52
            return results.get(0);
53
        }
54
    }
55

    
56

    
57
    public void setSessionFactory(SessionFactory sessionFactory) {
58
        this.factory = sessionFactory;
59
    }
60
    public SessionFactory getSessionFactory() {
61
        return factory;
62
    }
63
    protected Session getSession(){
64
        Session session = factory.getCurrentSession();
65
        return session;
66
    }
67

    
68
}
(4-4/4)