Revision 2693f710
Added by Andreas Kohlbecker almost 9 years ago
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IIdentificationKeyDao.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
10 | 10 |
package eu.etaxonomy.cdm.persistence.dao.description; |
11 | 11 |
|
12 | 12 |
import java.util.List; |
13 |
import java.util.UUID; |
|
13 | 14 |
|
14 | 15 |
import org.springframework.dao.DataAccessException; |
15 | 16 |
|
16 | 17 |
import eu.etaxonomy.cdm.model.description.IIdentificationKey; |
17 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
18 | 18 |
|
19 | 19 |
/** |
20 | 20 |
* A read-only interface to allow querying across all IIdentificationKey instances, regardless of type |
... | ... | |
23 | 23 |
* @created 21-Dec-2009 13:48:10 |
24 | 24 |
*/ |
25 | 25 |
public interface IIdentificationKeyDao { |
26 |
|
|
26 |
|
|
27 | 27 |
|
28 | 28 |
/** |
29 | 29 |
* Returns a sublist of IIdentificationKey instances stored in the database. A maximum |
30 | 30 |
* of 'limit' objects are returned, starting at object with index 'start'. |
31 |
*
|
|
32 |
* @param type
|
|
31 |
* |
|
32 |
* @param type |
|
33 | 33 |
* @param limit |
34 | 34 |
* the maximum number of entities returned (can be null to return |
35 | 35 |
* all entities) |
... | ... | |
44 | 44 |
* @return |
45 | 45 |
*/ |
46 | 46 |
public int count(); |
47 |
|
|
47 |
|
|
48 | 48 |
/** |
49 | 49 |
* Finds IdentificationKeys which cover the Taxon given as parameter |
50 |
*
|
|
50 |
* |
|
51 | 51 |
* @param taxon |
52 | 52 |
* The Taxon to search IdentificationKeys for |
53 | 53 |
* @param type |
... | ... | |
65 | 65 |
* @return a List of IdentificationKeys |
66 | 66 |
*/ |
67 | 67 |
public <T extends IIdentificationKey> List<T> findByTaxonomicScope( |
68 |
TaxonBase taxon, Class<T> type, Integer pageSize,
|
|
68 |
UUID taxonUuid, Class<T> type, Integer pageSize,
|
|
69 | 69 |
Integer pageNumber, List<String> propertyPaths); |
70 | 70 |
|
71 | 71 |
/** |
72 | 72 |
* Counts IdentificationKeys which cover the Taxon given as parameter |
73 |
*
|
|
73 |
* |
|
74 | 74 |
* @param taxon The Taxon to search IdentificationKeys for |
75 | 75 |
* @param type may restrict the type to a specific implementation of |
76 | 76 |
* IIdentificationKey |
77 |
* @return
|
|
77 |
* @return |
|
78 | 78 |
*/ |
79 |
public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type); |
|
80 |
} |
|
79 |
public <T extends IIdentificationKey> Long countByTaxonomicScope(UUID taxonUuid, Class<T> type); |
|
80 |
} |
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoImpl.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.cdm.persistence.dao.hibernate.description; |
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 |
import java.util.UUID; |
|
4 | 5 |
|
5 | 6 |
import org.hibernate.Query; |
6 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
8 | 9 |
import org.springframework.stereotype.Repository; |
9 | 10 |
|
10 | 11 |
import eu.etaxonomy.cdm.model.description.IIdentificationKey; |
11 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
12 | 12 |
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao; |
13 | 13 |
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase; |
14 | 14 |
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer; |
... | ... | |
55 | 55 |
*/ |
56 | 56 |
@Override |
57 | 57 |
public <T extends IIdentificationKey> List<T> findByTaxonomicScope( |
58 |
TaxonBase taxon, Class<T> type, Integer pageSize,
|
|
58 |
UUID taxonUuid, Class<T> type, Integer pageSize,
|
|
59 | 59 |
Integer pageNumber, List<String> propertyPaths) { |
60 | 60 |
|
61 |
Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
|
|
62 |
query.setParameter("taxon", taxon);
|
|
61 |
Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");
|
|
62 |
query.setParameter("taxon_uuid", taxonUuid);
|
|
63 | 63 |
List<T> results = query.list(); |
64 | 64 |
defaultBeanInitializer.initializeAll(results, propertyPaths); |
65 | 65 |
return results; |
... | ... | |
69 | 69 |
* @see eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao#findKeysConvering(eu.etaxonomy.cdm.model.taxon.TaxonBase, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List) |
70 | 70 |
*/ |
71 | 71 |
@Override |
72 |
public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type) {
|
|
72 |
public <T extends IIdentificationKey> Long countByTaxonomicScope(UUID taxonUuid, Class<T> type) {
|
|
73 | 73 |
|
74 |
Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");
|
|
75 |
query.setParameter("taxon", taxon);
|
|
74 |
Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");
|
|
75 |
query.setParameter("taxon_uuid", taxonUuid);
|
|
76 | 76 |
List<Long> list = query.list(); |
77 | 77 |
Long count = 0l; |
78 | 78 |
for(Long perTypeCount : list){ |
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoHibernateImplTest.java | ||
---|---|---|
22 | 22 |
import eu.etaxonomy.cdm.model.description.IIdentificationKey; |
23 | 23 |
import eu.etaxonomy.cdm.model.description.MediaKey; |
24 | 24 |
import eu.etaxonomy.cdm.model.description.PolytomousKey; |
25 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
26 | 25 |
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao; |
27 |
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao; |
|
28 | 26 |
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest; |
29 | 27 |
|
30 | 28 |
@DataSet |
... | ... | |
32 | 30 |
|
33 | 31 |
@SpringBeanByType |
34 | 32 |
IIdentificationKeyDao identificationKeyDao; |
35 |
@SpringBeanByType |
|
36 |
ITaxonDao taxonDao; |
|
33 |
|
|
37 | 34 |
UUID taxonUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9"); |
38 | 35 |
|
39 | 36 |
@Before |
... | ... | |
48 | 45 |
|
49 | 46 |
@Test |
50 | 47 |
public void testFindByTaxonomicScope() { |
51 |
TaxonBase taxon = taxonDao.findByUuid(taxonUuid); |
|
52 |
|
|
53 |
Long count1 = identificationKeyDao.countByTaxonomicScope(taxon, IIdentificationKey.class); |
|
48 |
Long count1 = identificationKeyDao.countByTaxonomicScope(taxonUuid, IIdentificationKey.class); |
|
54 | 49 |
Assert.assertTrue(count1.equals(2l)); |
55 |
List<IIdentificationKey> list1 = identificationKeyDao.findByTaxonomicScope(taxon, IIdentificationKey.class, null, null, null); |
|
50 |
List<IIdentificationKey> list1 = identificationKeyDao.findByTaxonomicScope(taxonUuid, IIdentificationKey.class, null, null, null);
|
|
56 | 51 |
Assert.assertEquals(list1.size(), 2); |
57 | 52 |
|
58 |
Long count2 = identificationKeyDao.countByTaxonomicScope(taxon, MediaKey.class); |
|
53 |
Long count2 = identificationKeyDao.countByTaxonomicScope(taxonUuid, MediaKey.class);
|
|
59 | 54 |
Assert.assertTrue(count2.equals(2l)); |
60 |
List<MediaKey> list2 = identificationKeyDao.findByTaxonomicScope(taxon, MediaKey.class, null, null, null); |
|
55 |
List<MediaKey> list2 = identificationKeyDao.findByTaxonomicScope(taxonUuid, MediaKey.class, null, null, null);
|
|
61 | 56 |
Assert.assertEquals(list2.size(), 2); |
62 | 57 |
|
63 |
Long count3 = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class); |
|
58 |
Long count3 = identificationKeyDao.countByTaxonomicScope(taxonUuid, PolytomousKey.class);
|
|
64 | 59 |
Assert.assertTrue(count3.equals(0l)); |
65 |
List<PolytomousKey> list3 = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, null, null, null); |
|
60 |
List<PolytomousKey> list3 = identificationKeyDao.findByTaxonomicScope(taxonUuid, PolytomousKey.class, null, null, null);
|
|
66 | 61 |
Assert.assertEquals(list3.size(), 0); |
67 | 62 |
} |
68 | 63 |
|
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentificationKeyServiceImpl.java | ||
---|---|---|
44 | 44 |
Class<T> type, Integer pageSize, |
45 | 45 |
Integer pageNumber, List<String> propertyPaths) { |
46 | 46 |
|
47 |
Long numberOfResults = dao.countByTaxonomicScope(taxon, type); |
|
47 |
Long numberOfResults = dao.countByTaxonomicScope(taxon.getUuid(), type);
|
|
48 | 48 |
List<T> results = new ArrayList<T>(); |
49 | 49 |
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){ |
50 |
results = dao.findByTaxonomicScope(taxon, type, pageSize, pageNumber, propertyPaths); |
|
50 |
results = dao.findByTaxonomicScope(taxon.getUuid(), type, pageSize, pageNumber, propertyPaths);
|
|
51 | 51 |
} |
52 | 52 |
return new DefaultPagerImpl<T>(pageNumber, numberOfResults.intValue(), pageSize, results); |
53 | 53 |
} |
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyServiceImpl.java | ||
---|---|---|
119 | 119 |
Integer pageNumber, List<String> propertyPaths, List<String> nodePaths) { |
120 | 120 |
|
121 | 121 |
List<PolytomousKey> list = new ArrayList<PolytomousKey>(); |
122 |
taxon = taxonDao.findById(taxon.getId()); |
|
123 |
Long numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class); |
|
122 |
Long numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon.getUuid(), PolytomousKey.class); |
|
124 | 123 |
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){ |
125 |
list = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, pageSize, pageNumber, propertyPaths); |
|
124 |
list = identificationKeyDao.findByTaxonomicScope(taxon.getUuid(), PolytomousKey.class, pageSize, pageNumber, propertyPaths);
|
|
126 | 125 |
} |
127 | 126 |
if (nodePaths != null) { |
128 | 127 |
for (PolytomousKey polytomousKey : list) { |
Also available in: Unified diff
#5288 - avoiding unncessary entitiy loading, using uuid instead in dao methods