Project

General

Profile

« Previous | Next » 

Revision 1ec74f53

Added by Andreas Kohlbecker almost 8 years ago

refactoring listByIds to loadByIds

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/common/ICdmEntityDao.java
258 258
     */
259 259
    public T load(int id, List<String> propertyPaths);
260 260

  
261

  
262 261
    /**
263 262
     * @param ids
264
     * @param pageSize
265
     * @param pageNumber
266
     * @param orderHints
267 263
     * @param propertyPaths
268 264
     * @return
269 265
     * @throws DataAccessException
270 266
     */
271
    public List<T> listByIds(Collection<Integer> ids, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws DataAccessException;
267
    public List<T> loadList(Collection<Integer> ids, List<String> propertyPaths) throws DataAccessException;
268

  
272 269
    /**
273 270
     * @param Uuid
274 271
     * @return
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBase.java
360 360

  
361 361
	@Override
362 362
    public T findById(int id) throws DataAccessException {
363
        return (T) getSession().get(type, id);
363
        return getSession().get(type, id);
364 364
    }
365 365

  
366 366

  
......
412 412
    }
413 413

  
414 414
    @Override
415
    public List<T> listByIds(Collection<Integer> ids,  Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) throws DataAccessException {
415
    public List<T> loadList(Collection<Integer> ids,  List<String> propertyPaths) throws DataAccessException {
416 416

  
417 417
        if (ids.isEmpty()) {
418 418
            return new ArrayList<T>(0);
419 419
        }
420 420

  
421
        Criteria criteria = prepareList(ids, pageSize, pageNumber, orderHints, "id");
421
        Criteria criteria = prepareList(ids, null, null, null, "id");
422 422

  
423
        if (logger.isDebugEnabled()){logger.debug(criteria.toString());};
423
        if (logger.isDebugEnabled()){logger.debug(criteria.toString());}
424 424

  
425 425
         @SuppressWarnings("unchecked")
426 426
		List<T> result = criteria.list();
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/CdmEntityDaoBaseTest.java
345 345
    }
346 346

  
347 347
    /**
348
     * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#listByIds(java.util.Collection, Integer, Integer, List, List)}.
348
     * Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.common.CdmEntityDaoBase#loadList(java.util.Collection, List)}.
349 349
     */
350 350
    @Test
351 351
    @DataSet("CdmEntityDaoBaseTest.xml")
......
353 353
        List<OrderHint> orderHints = new ArrayList<OrderHint>();
354 354
        orderHints.add(new RandomOrder());
355 355
        Integer[] ids = new Integer[]{1, 2};
356
        List<TaxonBase> list = cdmEntityDaoBase.listByIds(Arrays.asList(ids), 20, 0, orderHints, null);
356
        List<TaxonBase> list = cdmEntityDaoBase.loadList(Arrays.asList(ids), null);
357 357
        assertNotNull("list() should not return null",list);
358 358
        assertEquals("list() should return a list with two entities in it",list.size(),2);
359 359
    }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IService.java
161 161
     *
162 162
     * @param idSet
163 163
     * @return
164
     * @deprecated use {@link #listByIds(Set, Integer, Integer, List, List)} instead
164
     * @deprecated use {@link #loadByIds(Set, List)} instead
165 165
     */
166 166
    @Deprecated
167 167
    public List<T> findById(Set<Integer> idSet);  //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
......
380 380
    public List<T> merge(List<T> detachedObjects);
381 381

  
382 382
    /**
383
     * Loads a batch of entities referenced by their ids.
384
     *
383 385
     * @param idSet
384
     * @param pageSize
385
     * @param pageNumber
386
     * @param orderHints
387 386
     * @param propertyPaths
388 387
     * @return
389 388
     */
390
    List<T> listByIds(Set<Integer> idSet, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
391
            List<String> propertyPaths);
389
    List<T> loadByIds(List<Integer> idSet, List<String> propertyPaths);
392 390

  
393 391
    /**
394 392
     * This method allows for the possibility of returning the input transient
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
373 373
            }
374 374
        }
375 375
        //dao.listByIds() does the paging of the field units. Passing the field units directly to the Pager would not work
376
        List<SpecimenOrObservationBase> fieldUnits = dao.listByIds(fieldUnitIds, pageSize, pageNumber, orderHints, propertyPaths);
376
        List<SpecimenOrObservationBase> fieldUnits = dao.loadList(fieldUnitIds, propertyPaths);
377 377
        return new DefaultPagerImpl<SpecimenOrObservationBase>(pageNumber, fieldUnitIds.size(), pageSize, fieldUnits);
378 378
    }
379 379

  
......
743 743
                occurrenceIds.add(o.getId());
744 744
            }
745 745
        }
746
        occurrences = (List<T>) dao.listByIds(occurrenceIds, pageSize, pageNumber, orderHints, propertyPaths);
746
        occurrences = (List<T>) dao.loadList(occurrenceIds, propertyPaths);
747 747

  
748 748
        return new DefaultPagerImpl<T>(pageNumber, occurrenceIds.size(), pageSize, occurrences);
749 749

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/ServiceBase.java
117 117
    @Override
118 118
    @Transactional(readOnly = true)
119 119
    public List<T> findById(Set<Integer> idSet) {  //can't be called find(Set<Integer>) as this conflicts with find(Set<UUID)
120
        return dao.listByIds(idSet, null, null, null, null);
120
        return dao.loadList(idSet, null);
121 121
    }
122 122

  
123 123
    @Override
124 124
    @Transactional(readOnly = true)
125
    public List<T> listByIds(Set<Integer> idSet, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
126
        return dao.listByIds(idSet, pageSize, pageNumber, orderHints, propertyPaths);
125
    public List<T> loadByIds(List<Integer> idList, List<String> propertyPaths){
126
        return dao.loadList(idList, propertyPaths);
127 127
    }
128 128

  
129 129
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
944 944

  
945 945
    @Override
946 946
    public List<TaxonBase> findTaxaByID(Set<Integer> listOfIDs) {
947
        return this.dao.listByIds(listOfIDs, null, null, null, null);
947
        return this.dao.loadList(listOfIDs, null);
948 948
    }
949 949

  
950 950
    @Override
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/description/TransmissionEngineDistribution.java
443 443

  
444 444
            // load taxa for this batch
445 445
            List<TaxonBase> taxa = null;
446
            Set<Integer> taxonIds = new HashSet<Integer>(batchSize);
446
            List<Integer> taxonIds = new ArrayList<Integer>(batchSize);
447 447
            while(taxonIdIterator.hasNext() && taxonIds.size() < batchSize ) {
448 448
                taxonIds.add(taxonIdIterator.next());
449 449
            }
450 450

  
451 451
//            logger.debug("accumulateByArea() - taxon " + taxonPager.getFirstRecord() + " to " + taxonPager.getLastRecord() + " of " + taxonPager.getCount() + "]");
452 452

  
453
            taxa = taxonService.listByIds(taxonIds, null, null, emptyOrderHints, TAXONDESCRIPTION_INIT_STRATEGY);
453
            taxa = taxonService.loadByIds(taxonIds, TAXONDESCRIPTION_INIT_STRATEGY);
454 454

  
455 455
            // iterate over the taxa and accumulate areas
456 456
            for(TaxonBase taxonBase : taxa) {
......
576 576
                }
577 577

  
578 578
                // load taxa for this batch
579
                Set<Integer> taxonIds = new HashSet<Integer>(batchSize);
579
                List<Integer> taxonIds = new ArrayList<Integer>(batchSize);
580 580
                while(taxonIdIterator.hasNext() && taxonIds.size() < batchSize ) {
581 581
                    taxonIds.add(taxonIdIterator.next());
582 582
                }
583 583

  
584
                taxa = taxonService.listByIds(taxonIds, null, null, emptyOrderHints, null);
584
                taxa = taxonService.loadByIds(taxonIds, null);
585 585

  
586 586
                if(taxonSubMonitor == null) {
587 587
                    taxonSubMonitor = new SubProgressMonitor(subMonitor, ticksPerRank);
......
609 609
                    // Step through direct taxonomic children for accumulation
610 610
                    Map<NamedArea, StatusAndSources> accumulatedStatusMap = new HashMap<NamedArea, StatusAndSources>();
611 611

  
612
                    Set<Integer> childTaxonIds = classificationLookupDao.getChildTaxonMap().get(taxon.getId());
613
                    if(childTaxonIds != null && !childTaxonIds.isEmpty()) {
614
                        childTaxa = taxonService.listByIds(childTaxonIds, null, null, emptyOrderHints, TAXONDESCRIPTION_INIT_STRATEGY);
612
                    List<Integer> childTaxonIds = new ArrayList<>();
613
                    Set<Integer> childSet = classificationLookupDao.getChildTaxonMap().get(taxon.getId());
614
                    if(childSet != null) {
615
                        childTaxonIds.addAll(childSet);
616
                    }
617
                    if(!childTaxonIds.isEmpty()) {
618
                        childTaxa = taxonService.loadByIds(childTaxonIds, TAXONDESCRIPTION_INIT_STRATEGY);
615 619

  
616 620
                        for (TaxonBase childTaxonBase : childTaxa){
617 621

  

Also available in: Unified diff