Revert "#5288 - avoiding unncessary entitiy loading, using uuid instead in dao method...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 28 Sep 2015 12:14:34 +0000 (14:14 +0200)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Mon, 28 Sep 2015 12:14:34 +0000 (14:14 +0200)
This reverts commit 2693f7105470815383cdf485355e7fc5ad81ed68.

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/description/IIdentificationKeyDao.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoImpl.java
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/description/IdentificationKeyDaoHibernateImplTest.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IdentificationKeyServiceImpl.java
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/PolytomousKeyServiceImpl.java

index 92945374686ef13bfa0decdd7ff596e52e853052..8f8108acaa50b133976b1ba067f1a99ca41700ac 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * 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
@@ -23,13 +23,13 @@ import eu.etaxonomy.cdm.model.description.IIdentificationKey;
  * @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)
@@ -44,10 +44,10 @@ public interface IIdentificationKeyDao {
         * @return
         */
        public int count();
-
+       
        /**
         * Finds IdentificationKeys which cover the Taxon given as parameter
-        *
+        * 
         * @param taxon
         *            The Taxon to search IdentificationKeys for
         * @param type
@@ -65,16 +65,16 @@ public interface IIdentificationKeyDao {
         * @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);
+} 
index 2d3465941850a972300dbc385caf098d5a578032..2ccac0f331dd119ba304ef7a418ba11112ef81bb 100644 (file)
@@ -1,7 +1,6 @@
 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
@@ -9,6 +8,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 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
@@ -55,11 +55,11 @@ public class IdentificationKeyDaoImpl extends DaoBase implements IIdentification
         */\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
@@ -69,10 +69,10 @@ public class IdentificationKeyDaoImpl extends DaoBase implements IIdentification
         * @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
index 2a9988f997d06764f9621488aa56699be627693b..21cfcc575cc2b11bdb3674910d8e58d43daa4ff0 100644 (file)
@@ -22,7 +22,9 @@ import org.unitils.spring.annotation.SpringBeanByType;
 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
@@ -30,7 +32,8 @@ public class IdentificationKeyDaoHibernateImplTest extends CdmIntegrationTest {
 
        @SpringBeanByType
        IIdentificationKeyDao identificationKeyDao;
-
+       @SpringBeanByType
+       ITaxonDao taxonDao;
        UUID taxonUuid = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
 
        @Before
@@ -45,19 +48,21 @@ public class IdentificationKeyDaoHibernateImplTest extends CdmIntegrationTest {
 
        @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);
        }
 
index fef7761c7259b0466b82e4c02adb0910f489329c..b141ee912c60f60687e3eb857c6078f354f27684 100644 (file)
@@ -44,10 +44,10 @@ public class IdentificationKeyServiceImpl implements IIdentificationKeyService {
             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
index e1cd6dd5be6622f0093bea3e014340962538c40a..f74e10afe7eba6dfe3c07c64f8bb64381532f12e 100644 (file)
@@ -119,9 +119,10 @@ public class PolytomousKeyServiceImpl extends IdentifiableServiceBase<Polytomous
                        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