1
|
/**
|
2
|
* Copyright (C) 2014 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.persistence.dao.hibernate.molecular;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.hibernate.Query;
|
17
|
import org.hibernate.Session;
|
18
|
import org.hibernate.criterion.Criterion;
|
19
|
import org.springframework.stereotype.Repository;
|
20
|
|
21
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
22
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotatableDaoImpl;
|
23
|
import eu.etaxonomy.cdm.persistence.dao.molecular.IPrimerDao;
|
24
|
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
|
25
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
26
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
27
|
|
28
|
/**
|
29
|
* @author pplitzner
|
30
|
\* @since 11.03.2014
|
31
|
*
|
32
|
*/
|
33
|
@Repository
|
34
|
public class PrimerDaoHibernateImpl extends AnnotatableDaoImpl<Primer> implements IPrimerDao{
|
35
|
|
36
|
@SuppressWarnings("unused")
|
37
|
private static final Logger logger = Logger.getLogger(PrimerDaoHibernateImpl.class);
|
38
|
|
39
|
/**
|
40
|
* @param type
|
41
|
*/
|
42
|
public PrimerDaoHibernateImpl() {
|
43
|
super(Primer.class);
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
public List<UuidAndTitleCache<Primer>> getPrimerUuidAndTitleCache() {
|
48
|
List<UuidAndTitleCache<Primer>> list = new ArrayList<UuidAndTitleCache<Primer>>();
|
49
|
Session session = getSession();
|
50
|
|
51
|
Query query = session.createQuery("select uuid, id, label from Primer");
|
52
|
|
53
|
@SuppressWarnings("unchecked")
|
54
|
List<Object[]> result = query.list();
|
55
|
|
56
|
for(Object[] object : result){
|
57
|
list.add(new UuidAndTitleCache<Primer>(Primer.class, (UUID) object[0], (Integer)object[1], (String) object[2]));
|
58
|
}
|
59
|
|
60
|
return list;
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public long countByTitle(String queryString, MatchMode matchmode, List<Criterion> criteria) {
|
65
|
return countByParam(Primer.class, "label", queryString, matchmode, criteria);
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public List<Primer> findByTitle(String queryString, MatchMode matchmode, List<Criterion> criteria,
|
70
|
Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
71
|
return findByParam(Primer.class, "label", queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
|
72
|
}
|
73
|
|
74
|
/**
|
75
|
* {@inheritDoc}
|
76
|
*/
|
77
|
@Override
|
78
|
public List<UuidAndTitleCache<Primer>> getPrimerUuidAndTitleCache(Integer limitOfInitialElements, String pattern) {
|
79
|
|
80
|
Session session = getSession();
|
81
|
|
82
|
String queryString = "SELECT uuid, id, label FROM Prime ";
|
83
|
|
84
|
if ( pattern != null){
|
85
|
queryString += " WHERE ";
|
86
|
queryString += " label LIKE :pattern";
|
87
|
|
88
|
}
|
89
|
|
90
|
Query query;
|
91
|
query = session.createQuery(queryString);
|
92
|
|
93
|
|
94
|
if (limitOfInitialElements != null){
|
95
|
query.setMaxResults(limitOfInitialElements);
|
96
|
}
|
97
|
if (pattern != null){
|
98
|
pattern = pattern.replace("*", "%");
|
99
|
pattern = pattern.replace("?", "_");
|
100
|
pattern = pattern + "%";
|
101
|
query.setParameter("pattern", pattern);
|
102
|
}
|
103
|
|
104
|
@SuppressWarnings("unchecked")
|
105
|
List<Object[]> result = query.list();
|
106
|
List<UuidAndTitleCache<Primer>> list = new ArrayList<>();
|
107
|
for(Object[] object : result){
|
108
|
list.add(new UuidAndTitleCache<Primer>(Primer.class, (UUID) object[0],(Integer)object[1], (String)object[2]));
|
109
|
}
|
110
|
|
111
|
return list;
|
112
|
}
|
113
|
|
114
|
}
|