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.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.hibernate.Criteria;
|
19
|
import org.hibernate.Query;
|
20
|
import org.hibernate.Session;
|
21
|
import org.hibernate.criterion.Order;
|
22
|
import org.hibernate.criterion.Restrictions;
|
23
|
import org.springframework.stereotype.Repository;
|
24
|
|
25
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
26
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
27
|
import eu.etaxonomy.cdm.model.reference.ISourceable;
|
28
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
29
|
import eu.etaxonomy.cdm.persistence.dao.common.IOriginalSourceDao;
|
30
|
|
31
|
/**
|
32
|
* @author a.mueller
|
33
|
* @since 17.07.2008
|
34
|
*/
|
35
|
@Repository
|
36
|
public class OriginalSourceDaoImpl extends CdmEntityDaoBase<OriginalSourceBase> implements IOriginalSourceDao {
|
37
|
@SuppressWarnings("unused")
|
38
|
private static final Logger logger = Logger.getLogger(OriginalSourceDaoImpl.class);
|
39
|
|
40
|
public OriginalSourceDaoImpl() {
|
41
|
super(OriginalSourceBase.class);
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public Map<String, ISourceable> findOriginalSourcesByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace) {
|
46
|
Session session = getSession();
|
47
|
String idInSourceString = "";
|
48
|
for (String idInSource : idInSourceSet){
|
49
|
idInSourceString = CdmUtils.concat("','", idInSourceString, idInSource);
|
50
|
}
|
51
|
idInSourceString = "'"+ idInSourceString + "'";
|
52
|
|
53
|
Query q = session.createQuery(
|
54
|
"SELECT source.idInSource, c FROM " + clazz.getSimpleName() + " AS c " +
|
55
|
"INNER JOIN c.sources AS source " +
|
56
|
"WHERE source.idInSource IN ( " + idInSourceString + " )" +
|
57
|
" AND source.idNamespace = :idNamespace"
|
58
|
);
|
59
|
q.setString("idNamespace", idNamespace);
|
60
|
//TODO integrate reference in where
|
61
|
|
62
|
Map<String, ISourceable> result = new HashMap<>();
|
63
|
|
64
|
List<Object[]> list = q.list();
|
65
|
for (Object[] pair : list){
|
66
|
result.put((String)pair[0], (ISourceable)pair[1]);
|
67
|
}
|
68
|
|
69
|
return result;
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public List<IdentifiableEntity> findOriginalSourceByIdInSource(Class clazz, String idInSource, String idNamespace) {
|
74
|
Session session = getSession();
|
75
|
Query q = session.createQuery(
|
76
|
"Select c from " + clazz.getSimpleName() + " as c " +
|
77
|
"inner join c.sources as source " +
|
78
|
"where source.idInSource = :idInSource " +
|
79
|
" AND source.idNamespace = :idNamespace"
|
80
|
);
|
81
|
q.setString("idInSource", idInSource);
|
82
|
q.setString("idNamespace", idNamespace);
|
83
|
//TODO integrate reference in where
|
84
|
List<IdentifiableEntity> results = q.list();
|
85
|
|
86
|
return results;
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
public List<OriginalSourceBase> findOriginalSourceByIdInSource(String idInSource, String idNamespace) {
|
91
|
Session session = getSession();
|
92
|
Criteria crit = session.createCriteria(type);
|
93
|
crit.add(Restrictions.eq("idInSource", idInSource));
|
94
|
if (idNamespace == null){
|
95
|
crit.add(Restrictions.isNull("idNamespace"));
|
96
|
}else{
|
97
|
crit.add(Restrictions.eq("idNamespace", idNamespace));
|
98
|
}
|
99
|
crit.addOrder(Order.desc("created"));
|
100
|
List<OriginalSourceBase> results = crit.list();
|
101
|
|
102
|
return results;
|
103
|
}
|
104
|
}
|