\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Service;\r
-import org.springframework.transaction.annotation.Propagation;\r
import org.springframework.transaction.annotation.Transactional;\r
\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.api.service.pager.PagerUtils;\r
+import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;\r
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;\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
\r
@Service\r
-@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)\r
+@Transactional(readOnly = true)\r
public class IdentificationKeyServiceImpl implements IIdentificationKeyService {\r
- \r
- IIdentificationKeyDao dao;\r
- \r
- @Autowired\r
- public void setDao(IIdentificationKeyDao dao) {\r
- this.dao = dao;\r
- }\r
-\r
- public Pager<IIdentificationKey> page(Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
- Integer numberOfResults = dao.count();\r
- List<IIdentificationKey> results = new ArrayList<IIdentificationKey>();\r
- pageNumber = pageNumber == null ? 0 : pageNumber;\r
- if(numberOfResults > 0) { // no point checking again\r
- Integer start = pageSize == null ? 0 : pageSize * pageNumber;\r
- results = dao.list(pageSize, start, propertyPaths);\r
- }\r
- return new DefaultPagerImpl<IIdentificationKey>(pageNumber, numberOfResults, pageSize, results);\r
- }\r
+\r
+ IIdentificationKeyDao dao;\r
+\r
+ @Autowired\r
+ public void setDao(IIdentificationKeyDao dao) {\r
+ this.dao = dao;\r
+ }\r
+\r
+ @Override\r
+ public Pager<IIdentificationKey> page(Integer pageSize, Integer pageNumber, List<String> propertyPaths) {\r
+ Integer numberOfResults = dao.count();\r
+ List<IIdentificationKey> results = new ArrayList<IIdentificationKey>();\r
+ if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)\r
+ Integer limit = PagerUtils.limitFor(pageSize);\r
+ Integer start = PagerUtils.startFor(pageSize, pageNumber);\r
+ results = dao.list(limit, start, propertyPaths);\r
+ }\r
+ return new DefaultPagerImpl<IIdentificationKey>(pageNumber, numberOfResults, pageSize, results);\r
+ }\r
+\r
+\r
+ @Override\r
+ public <T extends IIdentificationKey> Pager<T> findKeysConvering(TaxonBase taxon,\r
+ Class<T> type, Integer pageSize,\r
+ Integer pageNumber, List<String> propertyPaths) {\r
+\r
+ Long numberOfResults = dao.countByTaxonomicScope(taxon.getUuid(), 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
+ }\r
+ return new DefaultPagerImpl<T>(pageNumber, numberOfResults.intValue(), pageSize, results);\r
+ }\r
\r
}\r