/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.cdm.persistence.dao.description;
import java.util.List;
-import java.util.UUID;
import org.springframework.dao.DataAccessException;
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
/**
* A read-only interface to allow querying across all IIdentificationKey instances, regardless of type
* @created 21-Dec-2009 13:48:10
*/
public interface IIdentificationKeyDao {
-
+
/**
* Returns a sublist of IIdentificationKey instances stored in the database. A maximum
* of 'limit' objects are returned, starting at object with index 'start'.
- *
- * @param type
+ *
+ * @param type
* @param limit
* the maximum number of entities returned (can be null to return
* all entities)
* @return
*/
public int count();
-
+
/**
* Finds IdentificationKeys which cover the Taxon given as parameter
- *
+ *
* @param taxon
* The Taxon to search IdentificationKeys for
* @param type
* @return a List of IdentificationKeys
*/
public <T extends IIdentificationKey> List<T> findByTaxonomicScope(
- UUID taxonUuid, Class<T> type, Integer pageSize,
+ TaxonBase taxon, Class<T> type, Integer pageSize,
Integer pageNumber, List<String> propertyPaths);
/**
* Counts IdentificationKeys which cover the Taxon given as parameter
- *
+ *
* @param taxon The Taxon to search IdentificationKeys for
* @param type may restrict the type to a specific implementation of
* IIdentificationKey
- * @return
+ * @return
*/
- public <T extends IIdentificationKey> Long countByTaxonomicScope(UUID taxonUuid, Class<T> type);
-}
+ public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type);
+}
package eu.etaxonomy.cdm.persistence.dao.hibernate.description;\r
\r
import java.util.List;\r
-import java.util.UUID;\r
\r
import org.hibernate.Query;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Repository;\r
\r
import eu.etaxonomy.cdm.model.description.IIdentificationKey;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;\r
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.DaoBase;\r
import eu.etaxonomy.cdm.persistence.dao.initializer.IBeanInitializer;\r
*/\r
@Override\r
public <T extends IIdentificationKey> List<T> findByTaxonomicScope(\r
- UUID taxonUuid, Class<T> type, Integer pageSize,\r
+ TaxonBase taxon, Class<T> type, Integer pageSize,\r
Integer pageNumber, List<String> propertyPaths) {\r
\r
- Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");\r
- query.setParameter("taxon_uuid", taxonUuid);\r
+ Query query = getSession().createQuery("select key from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");\r
+ query.setParameter("taxon", taxon);\r
List<T> results = query.list();\r
defaultBeanInitializer.initializeAll(results, propertyPaths);\r
return results;\r
* @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)\r
*/\r
@Override\r
- public <T extends IIdentificationKey> Long countByTaxonomicScope(UUID taxonUuid, Class<T> type) {\r
+ public <T extends IIdentificationKey> Long countByTaxonomicScope(TaxonBase taxon, Class<T> type) {\r
\r
- Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts.uuid = (:taxon_uuid)");\r
- query.setParameter("taxon_uuid", taxonUuid);\r
+ Query query = getSession().createQuery("select count(key) from " + type.getCanonicalName() +" key join key.taxonomicScope ts where ts = (:taxon)");\r
+ query.setParameter("taxon", taxon);\r
List<Long> list = query.list();\r
Long count = 0l;\r
for(Long perTypeCount : list){\r
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
import eu.etaxonomy.cdm.model.description.MediaKey;
import eu.etaxonomy.cdm.model.description.PolytomousKey;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.persistence.dao.description.IIdentificationKeyDao;
+import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
import eu.etaxonomy.cdm.test.integration.CdmIntegrationTest;
@DataSet
@SpringBeanByType
IIdentificationKeyDao identificationKeyDao;
-
+ @SpringBeanByType
+ ITaxonDao taxonDao;
UUID taxonUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
@Before
@Test
public void testFindByTaxonomicScope() {
- Long count1 = identificationKeyDao.countByTaxonomicScope(taxonUuid, IIdentificationKey.class);
+ TaxonBase taxon = taxonDao.findByUuid(taxonUuid);
+
+ Long count1 = identificationKeyDao.countByTaxonomicScope(taxon, IIdentificationKey.class);
Assert.assertTrue(count1.equals(2l));
- List<IIdentificationKey> list1 = identificationKeyDao.findByTaxonomicScope(taxonUuid, IIdentificationKey.class, null, null, null);
+ List<IIdentificationKey> list1 = identificationKeyDao.findByTaxonomicScope(taxon, IIdentificationKey.class, null, null, null);
Assert.assertEquals(list1.size(), 2);
- Long count2 = identificationKeyDao.countByTaxonomicScope(taxonUuid, MediaKey.class);
+ Long count2 = identificationKeyDao.countByTaxonomicScope(taxon, MediaKey.class);
Assert.assertTrue(count2.equals(2l));
- List<MediaKey> list2 = identificationKeyDao.findByTaxonomicScope(taxonUuid, MediaKey.class, null, null, null);
+ List<MediaKey> list2 = identificationKeyDao.findByTaxonomicScope(taxon, MediaKey.class, null, null, null);
Assert.assertEquals(list2.size(), 2);
- Long count3 = identificationKeyDao.countByTaxonomicScope(taxonUuid, PolytomousKey.class);
+ Long count3 = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class);
Assert.assertTrue(count3.equals(0l));
- List<PolytomousKey> list3 = identificationKeyDao.findByTaxonomicScope(taxonUuid, PolytomousKey.class, null, null, null);
+ List<PolytomousKey> list3 = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, null, null, null);
Assert.assertEquals(list3.size(), 0);
}
Class<T> type, Integer pageSize,\r
Integer pageNumber, List<String> propertyPaths) {\r
\r
- Long numberOfResults = dao.countByTaxonomicScope(taxon.getUuid(), type);\r
+ Long numberOfResults = dao.countByTaxonomicScope(taxon, type);\r
List<T> results = new ArrayList<T>();\r
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){\r
- results = dao.findByTaxonomicScope(taxon.getUuid(), type, pageSize, pageNumber, propertyPaths);\r
+ results = dao.findByTaxonomicScope(taxon, type, pageSize, pageNumber, propertyPaths);\r
}\r
return new DefaultPagerImpl<T>(pageNumber, numberOfResults.intValue(), pageSize, results);\r
}\r
Integer pageNumber, List<String> propertyPaths, List<String> nodePaths) {\r
\r
List<PolytomousKey> list = new ArrayList<PolytomousKey>();\r
- Long numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon.getUuid(), PolytomousKey.class);\r
+ taxon = taxonDao.findById(taxon.getId());\r
+ Long numberOfResults = identificationKeyDao.countByTaxonomicScope(taxon, PolytomousKey.class);\r
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)){\r
- list = identificationKeyDao.findByTaxonomicScope(taxon.getUuid(), PolytomousKey.class, pageSize, pageNumber, propertyPaths);\r
+ list = identificationKeyDao.findByTaxonomicScope(taxon, PolytomousKey.class, pageSize, pageNumber, propertyPaths);\r
}\r
if (nodePaths != null) {\r
for (PolytomousKey polytomousKey : list) {\r