Revision 113347bb
Added by Andreas Müller about 5 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/IOriginalSourceDao.java | ||
---|---|---|
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.common; |
|
11 |
|
|
12 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
13 |
import eu.etaxonomy.cdm.model.reference.ISourceable; |
|
14 |
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase; |
|
15 |
|
|
16 |
import java.util.List; |
|
17 |
import java.util.Map; |
|
18 |
import java.util.Set; |
|
19 |
|
|
20 |
|
|
21 |
public interface IOriginalSourceDao extends ICdmEntityDao<OriginalSourceBase>{ |
|
22 |
|
|
23 |
|
|
24 |
/** |
|
25 |
* Returns a map of identifiable entities of class <code>clazz</code> which have an original source of |
|
26 |
* with namespace <code>idNamespace</code> and with an idInSource in <code>idInSourceList</code> <BR> |
|
27 |
* The key of the map is the idInSource. If there are multiple objects that have the same id an arbitrary one is chosen. |
|
28 |
* @param clazz |
|
29 |
* @param idInSourceList |
|
30 |
* @param idNamespace |
|
31 |
* @return |
|
32 |
*/ |
|
33 |
public Map<String, ISourceable> findOriginalSourcesByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace); |
|
34 |
|
|
35 |
|
|
36 |
/** |
|
37 |
* Returns a list of identifiable entities according to their class, idInSource and idNamespace |
|
38 |
* @param clazz |
|
39 |
* @param idInSource |
|
40 |
* @param idNamespace |
|
41 |
* @return |
|
42 |
*/ |
|
43 |
public List<IdentifiableEntity> findOriginalSourceByIdInSource(Class clazz, String idInSource, String idNamespace); |
|
44 |
|
|
45 |
/** |
|
46 |
* Returns the first OriginalSource with according idInSource and idNamespace |
|
47 |
* @param idInSource |
|
48 |
* @param idNamespace |
|
49 |
* @return |
|
50 |
*/ |
|
51 |
public List<OriginalSourceBase> findOriginalSourceByIdInSource(String idInSource, String idNamespace); |
|
52 |
|
|
53 |
|
|
54 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/OriginalSourceDaoImpl.java | ||
---|---|---|
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 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/reference/OriginalSourceDaoImpl.java | ||
---|---|---|
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.reference; |
|
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.hibernate.common.CdmEntityDaoBase; |
|
30 |
import eu.etaxonomy.cdm.persistence.dao.reference.IOriginalSourceDao; |
|
31 |
|
|
32 |
/** |
|
33 |
* @author a.mueller |
|
34 |
* @since 17.07.2008 |
|
35 |
*/ |
|
36 |
@Repository |
|
37 |
public class OriginalSourceDaoImpl extends CdmEntityDaoBase<OriginalSourceBase> implements IOriginalSourceDao { |
|
38 |
@SuppressWarnings("unused") |
|
39 |
private static final Logger logger = Logger.getLogger(OriginalSourceDaoImpl.class); |
|
40 |
|
|
41 |
public OriginalSourceDaoImpl() { |
|
42 |
super(OriginalSourceBase.class); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
public Map<String, ISourceable> findOriginalSourcesByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace) { |
|
47 |
Session session = getSession(); |
|
48 |
String idInSourceString = ""; |
|
49 |
for (String idInSource : idInSourceSet){ |
|
50 |
idInSourceString = CdmUtils.concat("','", idInSourceString, idInSource); |
|
51 |
} |
|
52 |
idInSourceString = "'"+ idInSourceString + "'"; |
|
53 |
|
|
54 |
Query q = session.createQuery( |
|
55 |
"SELECT source.idInSource, c FROM " + clazz.getSimpleName() + " AS c " + |
|
56 |
"INNER JOIN c.sources AS source " + |
|
57 |
"WHERE source.idInSource IN ( " + idInSourceString + " )" + |
|
58 |
" AND source.idNamespace = :idNamespace" |
|
59 |
); |
|
60 |
q.setString("idNamespace", idNamespace); |
|
61 |
//TODO integrate reference in where |
|
62 |
|
|
63 |
Map<String, ISourceable> result = new HashMap<>(); |
|
64 |
|
|
65 |
List<Object[]> list = q.list(); |
|
66 |
for (Object[] pair : list){ |
|
67 |
result.put((String)pair[0], (ISourceable)pair[1]); |
|
68 |
} |
|
69 |
|
|
70 |
return result; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public List<IdentifiableEntity> findOriginalSourceByIdInSource(Class clazz, String idInSource, String idNamespace) { |
|
75 |
Session session = getSession(); |
|
76 |
Query q = session.createQuery( |
|
77 |
"Select c from " + clazz.getSimpleName() + " as c " + |
|
78 |
"inner join c.sources as source " + |
|
79 |
"where source.idInSource = :idInSource " + |
|
80 |
" AND source.idNamespace = :idNamespace" |
|
81 |
); |
|
82 |
q.setString("idInSource", idInSource); |
|
83 |
q.setString("idNamespace", idNamespace); |
|
84 |
//TODO integrate reference in where |
|
85 |
List<IdentifiableEntity> results = q.list(); |
|
86 |
|
|
87 |
return results; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public List<OriginalSourceBase> findOriginalSourceByIdInSource(String idInSource, String idNamespace) { |
|
92 |
Session session = getSession(); |
|
93 |
Criteria crit = session.createCriteria(type); |
|
94 |
crit.add(Restrictions.eq("idInSource", idInSource)); |
|
95 |
if (idNamespace == null){ |
|
96 |
crit.add(Restrictions.isNull("idNamespace")); |
|
97 |
}else{ |
|
98 |
crit.add(Restrictions.eq("idNamespace", idNamespace)); |
|
99 |
} |
|
100 |
crit.addOrder(Order.desc("created")); |
|
101 |
List<OriginalSourceBase> results = crit.list(); |
|
102 |
|
|
103 |
return results; |
|
104 |
} |
|
105 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/reference/IOriginalSourceDao.java | ||
---|---|---|
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.reference; |
|
11 |
|
|
12 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
|
13 |
import eu.etaxonomy.cdm.model.reference.ISourceable; |
|
14 |
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase; |
|
15 |
import eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao; |
|
16 |
|
|
17 |
import java.util.List; |
|
18 |
import java.util.Map; |
|
19 |
import java.util.Set; |
|
20 |
|
|
21 |
|
|
22 |
public interface IOriginalSourceDao extends ICdmEntityDao<OriginalSourceBase>{ |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Returns a map of identifiable entities of class <code>clazz</code> which have an original source of |
|
27 |
* with namespace <code>idNamespace</code> and with an idInSource in <code>idInSourceList</code> <BR> |
|
28 |
* The key of the map is the idInSource. If there are multiple objects that have the same id an arbitrary one is chosen. |
|
29 |
* @param clazz |
|
30 |
* @param idInSourceList |
|
31 |
* @param idNamespace |
|
32 |
* @return |
|
33 |
*/ |
|
34 |
public Map<String, ISourceable> findOriginalSourcesByIdInSource(Class clazz, Set<String> idInSourceSet, String idNamespace); |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Returns a list of identifiable entities according to their class, idInSource and idNamespace |
|
39 |
* @param clazz |
|
40 |
* @param idInSource |
|
41 |
* @param idNamespace |
|
42 |
* @return |
|
43 |
*/ |
|
44 |
public List<IdentifiableEntity> findOriginalSourceByIdInSource(Class clazz, String idInSource, String idNamespace); |
|
45 |
|
|
46 |
/** |
|
47 |
* Returns the first OriginalSource with according idInSource and idNamespace |
|
48 |
* @param idInSource |
|
49 |
* @param idNamespace |
|
50 |
* @return |
|
51 |
*/ |
|
52 |
public List<OriginalSourceBase> findOriginalSourceByIdInSource(String idInSource, String idNamespace); |
|
53 |
|
|
54 |
|
|
55 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/CommonServiceImpl.java | ||
---|---|---|
28 | 28 |
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName; |
29 | 29 |
import eu.etaxonomy.cdm.model.reference.ISourceable; |
30 | 30 |
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao; |
31 |
import eu.etaxonomy.cdm.persistence.dao.common.IOriginalSourceDao;
|
|
31 |
import eu.etaxonomy.cdm.persistence.dao.reference.IOriginalSourceDao;
|
|
32 | 32 |
import eu.etaxonomy.cdm.persistence.query.OrderHint; |
33 | 33 |
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy; |
34 | 34 |
import eu.etaxonomy.cdm.strategy.match.IMatchStrategyEqual; |
Also available in: Unified diff
ref #8162 move OriginalSourceXXX to reference package