Author: blavenier Date: 2013-02-28 20:20:19 +0100 (Thu, 28 Feb 2013) New Revision: 504 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/504 Log: Add : - some caches - remove HQL on changeSpeciesBatchSpecies (move in 'adagio-core') Fix : - move come cache declaration into Interface Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/BatchPersistenceServiceImpl.java 2013-02-28 19:20:19 UTC (rev 504) @@ -31,6 +31,7 @@ import fr.ifremer.adagio.core.dao.data.batch.CatchBatchExtendDao; import fr.ifremer.adagio.core.dao.data.batch.SortingBatch; import fr.ifremer.adagio.core.dao.data.batch.SortingBatchDao; +import fr.ifremer.adagio.core.dao.data.batch.SortingBatchImpl; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator; import fr.ifremer.adagio.core.dao.data.measure.Measurement; @@ -82,9 +83,6 @@ @Resource(name = "referentialPersistenceService") protected ReferentialPersistenceService referentialService; - @Resource(name = "sortingBatchDao") - protected SortingBatchDao sortingBatchDao; - @Resource(name = "catchBatchDao") protected CatchBatchExtendDao catchBatchDao; @@ -157,10 +155,11 @@ // Benthos SortingBatch benthosBatch = catchBatchDao.getSortingBatch(vracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + if (benthosBatch != null) { + result.setBenthosTotalSampleSortedWeight(benthosBatch.getWeight()); + result.setBenthosTotalSortedWeight(benthosBatch.getWeightBeforeSampling()); + } - result.setBenthosTotalSampleSortedWeight(benthosBatch.getWeight()); - result.setBenthosTotalSortedWeight(benthosBatch.getWeightBeforeSampling()); - // TODO : Plancton... } @@ -173,15 +172,17 @@ // Species SortingBatch speciesBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + if (speciesBatch != null) { + result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); + } - result.setSpeciesTotalUnsortedWeight(speciesBatch.getWeight()); - SortingBatch benthosBatch = catchBatchDao.getSortingBatch(horsVracBatch.getChildBatchs(), "pmfmId", enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + if (benthosBatch == null) { + result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight()); + } - result.setBenthosTotalUnsortedWeight(benthosBatch.getWeight()); - // TODO : Plancton... } } @@ -204,7 +205,7 @@ Preconditions.checkNotNull(catchBatch.getChildBatchs()); for (Batch batch : catchBatch.getChildBatchs()) { - catchBatchDao.removeWithChildren(batch.getId()); + catchBatchDao.removeWithChildren(batch.getId(), catchBatch); } catchBatch.getChildBatchs().clear(); @@ -257,7 +258,6 @@ } @Override - @CacheEvict(value = "batchTree", key = "#bean.fishingOperation.id") public CatchBatch saveCatchBatch(CatchBatch bean) { Preconditions.checkNotNull(bean); @@ -343,7 +343,7 @@ SortingBatch batch = SortingBatch.Factory.newInstance(); beanToEntity(bean, batch, parentBatchId, catchBatch, true); - batch = sortingBatchDao.create(batch); + batch = catchBatchDao.createSortingBatch(batch, catchBatch); bean.setId(String.valueOf(batch.getId())); @@ -369,7 +369,7 @@ parentBatchId = bean.getParentBatch().getId(); } beanToEntity(bean, batch, parentBatchId, catchBatch, true); - sortingBatchDao.update(batch); + catchBatchDao.updateSortingBatch(batch, catchBatch); getCurrentSession().flush(); return bean; @@ -397,14 +397,7 @@ Preconditions.checkNotNull(species); Preconditions.checkNotNull(species.getReferenceTaxonId()); - if (log.isDebugEnabled()) { - log.debug("Changing species for batch id=" + batchId); - } - - int rowUpdated = queryUpdate("updateBatchSpecies", - "batchId", IntegerType.INSTANCE, Integer.valueOf(batchId), - "referenceTaxonId", IntegerType.INSTANCE, species.getReferenceTaxonId()); - Preconditions.checkArgument(rowUpdated == 1, "Unable to update operation, to be linked with catch batch."); + catchBatchDao.setSortingBatchReferenceTaxon(batchId, species.getReferenceTaxonId()); } //------------------------------------------------------------------------// @@ -486,13 +479,13 @@ beanToEntity(source, target, parentBatch, rankOrder, true); // Create the targeted batch, then update the source id - sortingBatchDao.create(target); + catchBatchDao.createSortingBatch(target, catchBatch); source.setId(target.getId().toString()); } // Existing batch else { - target = sortingBatchDao.load(Integer.valueOf(source.getId())); + target = catchBatchDao.loadSortingBatch(Integer.valueOf(source.getId()), catchBatch); // Fill the sorting batch from the source beanToEntity(source, target, parentBatch, rankOrder, true); @@ -506,12 +499,12 @@ // If some batchs need to be update, do it if (batchsToUpdate.size() > 0) { - sortingBatchDao.update(batchsToUpdate); + catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch); } if (notUpdatedChildIds.size() > 0) { for (Integer batchId : notUpdatedChildIds) { - catchBatchDao.removeWithChildren(batchId); + catchBatchDao.removeWithChildren(batchId, catchBatch); } } @@ -585,7 +578,7 @@ SortingBatch batch = SortingBatch.Factory.newInstance(); beanToEntity(bean, batch, parentBatchId, catchBatch, true); - batch = sortingBatchDao.create(batch); + batch = catchBatchDao.createSortingBatch(batch, catchBatch); bean.setId(String.valueOf(batch.getId())); @@ -611,7 +604,7 @@ parentBatchId = bean.getParentBatch().getId(); } beanToEntity(bean, batch, parentBatchId, catchBatch, true); - sortingBatchDao.update(batch); + catchBatchDao.updateSortingBatch(batch, catchBatch); getCurrentSession().flush(); return bean; @@ -727,13 +720,13 @@ beanToEntity(source, target, parentBatch, rankOrder, true); // Create the targeted batch, then update the source id - sortingBatchDao.create(target); + catchBatchDao.createSortingBatch(target, catchBatch); source.setId(target.getId().toString()); } // Existing batch else { - target = sortingBatchDao.load(Integer.valueOf(source.getId())); + target = catchBatchDao.getSortingBatchById(catchBatch, Integer.valueOf(source.getId())); // Fill the sorting batch from the source beanToEntity(source, target, parentBatch, rankOrder, true); @@ -747,12 +740,12 @@ // If some batchs need to be update, do it if (batchsToUpdate.size() > 0) { - sortingBatchDao.update(batchsToUpdate); + catchBatchDao.updateSortingBatch(batchsToUpdate, catchBatch); } if (notUpdatedChildIds.size() > 0) { for (Integer batchId : notUpdatedChildIds) { - catchBatchDao.removeWithChildren(batchId); + catchBatchDao.removeWithChildren(batchId, catchBatch); } } @@ -1257,7 +1250,6 @@ speciesBatch.setRankOrder((short) 1); { - // ----------------------------------------------------------------------------- // Sorted Vrac / Species / Alive not itemized // ----------------------------------------------------------------------------- @@ -1290,8 +1282,25 @@ copyIfNull); inertBatch.setRankOrder((short) 2); } - } - // TODO BL : benthos, plancton, macro déchet... + + // ----------------------------------------------------------------------------- + // Sorted Vrac > Benthos + // ----------------------------------------------------------------------------- + { + SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS); + if (benthosBatch == null) { + benthosBatch = SortingBatch.Factory.newInstance(); + batch.getChildBatchs().add(benthosBatch); + } + beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, + source.getBenthosTotalSampleSortedWeight(), source.getBenthosTotalSortedWeight(), + copyIfNull); + benthosBatch.setRankOrder((short) 2); + } + + // TODO plancton, macro déchet... + } } // ----------------------------------------------------------------------------- @@ -1313,24 +1322,45 @@ { Map<Integer, SortingBatch> batchChilds = getChildsMap(batch, enumeration.PMFM_ID_SORTING_TYPE); - // Species : - SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); - if (speciesBatch == null) { - speciesBatch = SortingBatch.Factory.newInstance(); - if (batch.getChildBatchs() == null) { - batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch)); - } else { - batch.getChildBatchs().add(speciesBatch); - } + // ----------------------------------------------------------------------------- + // Hors Vrac > Species : + // ----------------------------------------------------------------------------- + { + SortingBatch speciesBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + if (speciesBatch == null) { + speciesBatch = SortingBatch.Factory.newInstance(); + if (batch.getChildBatchs() == null) { + batch.setChildBatchs(Lists.newArrayList((Batch) speciesBatch)); + } else { + batch.getChildBatchs().add(speciesBatch); + } + } + beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, + source.getSpeciesTotalUnsortedWeight(), null, + copyIfNull); + speciesBatch.setRankOrder((short) 1); } - beanToEntitySortingBatch(target, batch, speciesBatch, recorderDepartmentId, - enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES, - source.getSpeciesTotalUnsortedWeight(), null, - copyIfNull); - speciesBatch.setRankOrder((short) 1); + + // ----------------------------------------------------------------------------- + // Hors Vrac > Benthos : + // ----------------------------------------------------------------------------- + { + SortingBatch benthosBatch = batchChilds.get(enumeration.QUALITATIVE_ID_SORTING_TYPE_SPECIES); + if (benthosBatch == null) { + benthosBatch = SortingBatch.Factory.newInstance(); + batch.getChildBatchs().add(benthosBatch); + } + beanToEntitySortingBatch(target, batch, benthosBatch, recorderDepartmentId, + enumeration.PMFM_ID_SORTING_TYPE, enumeration.QUALITATIVE_ID_SORTING_TYPE_BENTHOS, + source.getBenthosTotalUnsortedWeight(), null, + copyIfNull); + benthosBatch.setRankOrder((short) 2); + } + + // TODO : plancton, macro déchet... } - // TODO BL : benthos, plancton, macro déchet... } // ----------------------------------------------------------------------------- Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceService.java 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceService.java 2013-02-28 19:20:19 UTC (rev 504) @@ -26,6 +26,9 @@ import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor; import fr.ifremer.tutti.persistence.entities.data.Program; + +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -46,6 +49,7 @@ * * @return the list of programs found in db. */ + @Cacheable(value = "programs") List<Program> getAllProgram(); /** @@ -59,8 +63,10 @@ Program getProgram(String id); @Transactional(readOnly = false) + @CacheEvict(value = {"programs", "programZones"}, allEntries = true) Program createProgram(Program bean); @Transactional(readOnly = false) + @CacheEvict(value = {"programs", "programZones"}, allEntries = true) Program saveProgram(Program bean); } Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceService.java 2013-02-28 19:20:19 UTC (rev 504) @@ -37,6 +37,9 @@ import fr.ifremer.tutti.persistence.entities.referential.Species; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; + +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -60,6 +63,7 @@ * @see Program#setZone(Zone) * @since 0.3 */ + @Cacheable(value = "programZones") List<Zone> getAllProgramZone(); /** @@ -126,6 +130,7 @@ * @see Cruise#setVessel(List) * @since 0.3 */ + @Cacheable(value = "fishingVessels") List<Vessel> getAllFishingVessel(); /** @@ -133,18 +138,21 @@ * @return the vessel * @since 0.3 */ + @Cacheable(value = "vesselByCode", key="#vesselCode") Vessel getVessel(String vesselCode); /** * @return all referent species * @since 0.3 */ + @Cacheable(value = "referentSpecies") List<Species> getAllReferentSpecies(); /** * @return all species * @since 0.3 */ + @Cacheable(value = "species") List<Species> getAllSpecies(); /** @@ -155,12 +163,14 @@ * @see Species#getReferenceTaxonId() * @since 0.3 */ + @Cacheable(value = "referentSpeciesById", key = "#referenceTaxonId", condition = "#referenceTaxonId != null") Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId); /** * @return all caracteristics of the system. * @since 1.0 */ + @Cacheable(value = "pmfms") List<Caracteristic> getAllCaracteristic(); /** @@ -185,12 +195,15 @@ List<Gear> getAllFishingGear(); + @Cacheable(value = "persons") List<Person> getAllPerson(); + @Cacheable(value = "personById", key = "#personId") Person getPerson(Integer personId); Gear getGear(Integer gearId); + @Cacheable(value = "pmfmById", key = "#pmfmId") Caracteristic getCaracteristic(Integer pmfmId); boolean isSortedQualitativeValue(CaracteristicQualitativeValue value); @@ -204,6 +217,7 @@ * @since 1.0 */ @Transactional(readOnly = false) + @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById"}, allEntries = true) List<Species> importTemporarySpecies(List<Species> species); /** @@ -213,6 +227,7 @@ * @since 1.0 */ @Transactional(readOnly = false) + @CacheEvict(value = {"fishingVessels", "vesselByCode"}, allEntries = true) List<Vessel> importTemporaryVessel(List<Vessel> vessels); /** @@ -222,6 +237,7 @@ * @since 1.0 */ @Transactional(readOnly = false) + @CacheEvict(value = {"persons", "personById"}, allEntries = true) List<Person> importTemporaryPerson(List<Person> persons); /** @@ -231,6 +247,7 @@ * @since 1.0 */ @Transactional(readOnly = false) + @CacheEvict(value = "gears", allEntries = true) List<Gear> importTemporaryGear(List<Gear> gears); Modified: trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceImpl.java 2013-02-28 19:20:19 UTC (rev 504) @@ -33,6 +33,7 @@ import fr.ifremer.adagio.core.dao.referential.location.LocationExtendDao; import fr.ifremer.adagio.core.dao.referential.taxon.TaxonNameExtendDao; import fr.ifremer.adagio.core.dao.referential.taxon.TaxonRefTaxVO; +import fr.ifremer.adagio.core.service.technical.CacheService; import fr.ifremer.tutti.persistence.entities.TuttiEntities; import fr.ifremer.tutti.persistence.entities.data.SampleCategoryEnum; import fr.ifremer.tutti.persistence.entities.referential.AbstractTuttiReferentialEntity; @@ -47,15 +48,19 @@ import fr.ifremer.tutti.persistence.entities.referential.Status; import fr.ifremer.tutti.persistence.entities.referential.Vessel; import fr.ifremer.tutti.persistence.entities.referential.Zone; +import net.sf.ehcache.Element; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Query; import org.hibernate.type.DateType; import org.hibernate.type.IntegerType; import org.hibernate.type.StringType; +import org.springframework.cache.Cache; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.support.SimpleValueWrapper; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataRetrievalFailureException; import org.springframework.stereotype.Service; @@ -97,6 +102,12 @@ @Resource(name = "locationDao") protected LocationExtendDao locationDao; + @Resource(name = "cacheService") + protected CacheService cacheService; + + @Resource(name = "referentialPersistenceService") + protected ReferentialPersistenceService thisService; + //------------------------------------------------------------------------// //-- ReferentialPersistenceService implentation --// //------------------------------------------------------------------------// @@ -242,17 +253,19 @@ "vesselTypeId", IntegerType.INSTANCE, enumeration.VESSEL_TYPE_ID_SCIENTIFIC); List<Vessel> result = Lists.newArrayList(); + Cache vesselByCodeCache = cacheService.getCache("vesselByCode"); + while (list.hasNext()) { Object[] source = list.next(); - Vessel target = loadVessel(source, true); - - result.add(target); + Vessel target = loadVessel(source, true); + result.add(target); + // Add to cache + vesselByCodeCache.put(target.getId(), target); } return result; } @Override - @Cacheable(value = "fishingVessels") public List<Vessel> getAllFishingVessel() { Iterator<Object[]> list = queryListWithStatus( "allVessels", @@ -261,11 +274,16 @@ ); List<Vessel> result = Lists.newArrayList(); + Cache vesselByCodeCache = cacheService.getCache("vesselByCode"); + while (list.hasNext()) { Object[] source = list.next(); - Vessel target = loadVessel(source, false); + Vessel target = loadVessel(source, true); target.setScientificVessel(false); - result.add(target); + result.add(target); + + // Add to cache + vesselByCodeCache.put(target.getId(), target); } return result; } @@ -363,37 +381,38 @@ } @Override - @Cacheable(value = "species") public List<Species> getAllSpecies() { TaxonRefTaxVO[] sources = taxonNameDao.getAllTaxonNames(true); List<Species> result = Lists.newArrayListWithCapacity(sources.length); List<Species> referenceTaxonsOnly = Lists.newArrayList(); + Cache referentSpeciesByIdCache = cacheService.getCache("referentSpeciesById"); for (TaxonRefTaxVO source : sources) { Species target = loadSpecies(source); if (target.isReferenceTaxon()) { // Add to cache : - putToSpeciesReferentCache(target.getReferenceTaxonId(), target); + referentSpeciesByIdCache.put(target.getReferenceTaxonId(), target); + referenceTaxonsOnly.add(target); } result.add(target); } // Add to cache : - putToSpeciesReferentCache(referenceTaxonsOnly); + Cache allReferentSpeciesCache = cacheService.getCache("referentSpecies"); + allReferentSpeciesCache.put("", referenceTaxonsOnly); return result; } @Override - @Cacheable(value = "referentSpecies") public List<Species> getAllReferentSpecies() { TaxonRefTaxVO[] sources = taxonNameDao.getAllTaxonNames(false); - List<Species> result = Lists.newArrayListWithCapacity(sources.length); + Cache referentSpeciesByIdCache = cacheService.getCache("referentSpeciesById"); for (TaxonRefTaxVO source : sources) { if (36403 == source.getTaxonNameId() || 34539 == source.getTaxonNameId()) { continue; @@ -401,7 +420,7 @@ Species target = loadSpecies(source); // Add to cache : - putToSpeciesReferentCache(target.getReferenceTaxonId(), target); + referentSpeciesByIdCache.put(target.getReferenceTaxonId(), target); result.add(target); } @@ -409,7 +428,6 @@ } @Override - @Cacheable(value = "referentSpecies", key = "#speciesId") public Species getSpeciesByReferenceTaxonId(Integer speciesId) { Species target; try { @@ -423,26 +441,21 @@ } @Override - @Cacheable(value = "pmfms") public List<Caracteristic> getAllCaracteristic() { Iterator<Object[]> sources = queryListWithStatus( "allPmfm", "unitIdNone", IntegerType.INSTANCE, enumeration.UNIT_ID_NONE); List<Caracteristic> result = Lists.newArrayList(); + Cache pmfmByIdCache = cacheService.getCache("pmfmById"); while (sources.hasNext()) { Object[] source = sources.next(); Integer pmfmId = (Integer) source[0]; + Caracteristic target = loadCaracteristic(source); // Skip some protected PSFM - if (!isProtectedCaracteristic(pmfmId)) { - Caracteristic target = loadCaracteristic(source); - putToCaracteristicCache(pmfmId, target); - + if (!isProtectedCaracteristic(pmfmId)) { result.add(target); } - // If protected, load anyway just for the cache - else { - putToCaracteristicCache(pmfmId, loadCaracteristic(source)); - } + pmfmByIdCache.put(pmfmId, target); } return result; } @@ -476,7 +489,7 @@ @Override public Caracteristic getSortedUnsortedCaracteristic() { Integer pmfmId = enumeration.PMFM_ID_SORTED_UNSORTED; - Caracteristic result = getCaracteristic(pmfmId); + Caracteristic result = thisService.getCaracteristic(pmfmId); // Search the qualitative value to skip for (CaracteristicQualitativeValue qv : result.getQualitativeValue()) { @@ -492,26 +505,25 @@ @Override public Caracteristic getMaturityCaracteristic() { Integer pmfmId = enumeration.PMFM_ID_MATURITY; - Caracteristic result = getCaracteristic(pmfmId); + Caracteristic result = thisService.getCaracteristic(pmfmId); return result; } @Override public Caracteristic getMacroWasteCategoryCaracteristic() { Integer pmfmId = enumeration.PMFM_ID_MARINE_LITTER_TYPE; - Caracteristic result = getCaracteristic(pmfmId); + Caracteristic result = thisService.getCaracteristic(pmfmId); return result; } @Override public Caracteristic getMacroWasteSizeCategoryCaracteristic() { Integer pmfmId = enumeration.PMFM_ID_MARINE_LITTER_SIZE_CATEGORY; - Caracteristic result = getCaracteristic(pmfmId); + Caracteristic result = thisService.getCaracteristic(pmfmId); return result; } @Override - @Cacheable(value = "pmfms", key = "#pmfmId") public Caracteristic getCaracteristic(Integer pmfmId) { Object[] source = queryUniqueWithStatus("pmfmById", "pmfmId", IntegerType.INSTANCE, pmfmId, @@ -521,7 +533,6 @@ } @Override - @CacheEvict(value = {"species", "referentSpecies"}, allEntries = true) public List<Species> importTemporarySpecies(List<Species> species) { List<Species> result = Lists.newArrayList(); for (Species source : species) { @@ -532,7 +543,6 @@ } @Override - @CacheEvict(value = "fishingVessels", allEntries = true) public List<Vessel> importTemporaryVessel(List<Vessel> vessels) { List<Vessel> result = Lists.newArrayList(); @@ -554,7 +564,6 @@ } @Override - @CacheEvict(value = "persons", allEntries = true) public List<Person> importTemporaryPerson(List<Person> persons) { List<Person> result = Lists.newArrayList(); @@ -568,7 +577,6 @@ } @Override - @CacheEvict(value = "gears", allEntries = true) public List<Gear> importTemporaryGear(List<Gear> gears) { List<Gear> result = Lists.newArrayList(); @@ -645,7 +653,8 @@ Species result = loadSpecies(taxonName); // Add to cache - putToSpeciesReferentCache(Integer.valueOf(result.getId()), result); + Cache cache = cacheService.getCache("referentSpeciesById"); + cache.put(Integer.valueOf(result.getId()), result); return result; } @@ -878,22 +887,4 @@ } return sampleCategory; } - - @Cacheable(value = "pmfms", key = "#pmfmId") - protected Caracteristic putToCaracteristicCache(Integer pmfmId, Caracteristic caracteristic) { - return caracteristic; - } - - @CachePut(value = "referentSpecies") - protected List<Species> putToSpeciesReferentCache(List<Species> species) { - - - return species; - } - - @CachePut(value = "referentSpecies", key = "#speciesId") - protected Species putToSpeciesReferentCache(Integer speciesId, Species species) { - return species; - } - } Modified: trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml =================================================================== --- trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/resources/applicationContext-service-tutti.xml 2013-02-28 19:20:19 UTC (rev 504) @@ -52,46 +52,83 @@ <property name="diskPersistent" value="false"/> <property name="diskExpiryThreadIntervalSeconds" value="300"/> </bean> - - <bean id="tuttiBatchTreeCache" parent="tuttiAbstractCache"> - <property name="cacheName" value="batchTree" /> - </bean> - + <!-- Eternal caches : --> <bean id="tuttiAbstractEternalCache" abstract="true" parent="tuttiAbstractCache"> <property name="eternal" value="true"/> <property name="overflowToDisk" value="true"/> + <property name="maxElementsOnDisk" value="5000"/> <property name="diskPersistent" value="true"/> <!-- removed inherited properties --> <property name="timeToLive" value="0"/> <property name="timeToIdle" value="0"/> + <property name="diskExpiryThreadIntervalSeconds" value="0"/> </bean> + <bean id="tuttiProgramsCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="programs" /> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> + </bean> + + <bean id="tuttiProgramZonesCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="programZones" /> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> + </bean> + <bean id="tuttiPmfmsCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="pmfms" /> </bean> + <bean id="tuttiPmfmByIdCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="pmfmById" /> + </bean> <bean id="tuttiFishingVesselsCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="fishingVessels" /> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> </bean> + <bean id="tuttiFishingVesselByCodeCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="vesselByCode" /> + <property name="maxElementsInMemory" value="40000"/> + <property name="maxElementsOnDisk" value="40000"/> + </bean> <bean id="tuttiSpeciesCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="species" /> - <property name="maxElementsInMemory" value="20000"/> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> </bean> <bean id="tuttiReferentSpeciesCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="referentSpecies" /> - <property name="maxElementsInMemory" value="10000"/> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> </bean> + <bean id="tuttiReferentSpeciesByIdCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="referentSpeciesById" /> + <property name="maxElementsInMemory" value="20000"/> + <property name="maxElementsOnDisk" value="20000"/> + </bean> <bean id="tuttiGearsCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="gears" /> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> </bean> <bean id="tuttiPersonsCache" parent="tuttiAbstractEternalCache"> <property name="cacheName" value="persons" /> + <property name="maxElementsInMemory" value="1"/> + <property name="maxElementsOnDisk" value="1"/> </bean> + + <bean id="tuttiPersonByIdCache" parent="tuttiAbstractEternalCache"> + <property name="cacheName" value="personById" /> + <property name="maxElementsInMemory" value="1000"/> + <property name="maxElementsOnDisk" value="1000"/> + </bean> <!-- Example to use to create a new cache area : <bean id="tuttiOtherCache" parent="tuttiPersistenceDefaultCache"> Modified: trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml =================================================================== --- trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/main/resources/queries-override.hbm.xml 2013-02-28 19:20:19 UTC (rev 504) @@ -328,16 +328,6 @@ <query-param name="pmfmIdSortingType" type="java.lang.Integer"/> </query> - <query name="updateBatchSpecies"> - <![CDATA[ - UPDATE SortingBatchImpl b - SET b.referenceTaxon.id=:referenceTaxonId - WHERE - b.id=:batchId - ]]> - <query-param name="referenceTaxonId" type="java.lang.Integer"/> - <query-param name="batchId" type="java.lang.Integer"/> - </query> <query name="allSpeciesBatchFrequency"> <![CDATA[ @@ -566,11 +556,10 @@ WHERE v.vesselType.id = :vesselTypeId AND v.status.code IN (:statusValidCode, :statusTemporaryCode) - AND NOT(coalesce(vrp.endDateTime, '2999-12-31 00:00:00') < coalesce(:refDate,sysdate) - OR vrp.vesselRegistrationPeriodPk.startDateTime > coalesce(:refDate,sysdate) - ) - AND NOT(coalesce(vf.endDateTime, '2999-12-31 00:00:00') < coalesce(:refDate,sysdate) - OR vf.startDateTime > coalesce(:refDate,sysdate) + AND vrp.vesselRegistrationPeriodPk.startDateTime <= :refDate + AND vf.startDateTime <= :refDate + AND coalesce(vrp.endDateTime, :refDate) >= :refDate + AND coalesce(vf.endDateTime, :refDate) >= :refDate ) ]]> <query-param name="vesselTypeId" type="java.lang.Integer"/> Modified: trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java =================================================================== --- trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-02-28 11:59:26 UTC (rev 503) +++ trunk/tutti-persistence/src/test/java/fr/ifremer/tutti/persistence/service/ReferentialPersistenceServiceReadTest.java 2013-02-28 19:20:19 UTC (rev 504) @@ -156,6 +156,7 @@ long delta1 = System.currentTimeMillis() - time; assertResultList(result, fixtures.refNbFishingVessel()); + log.debug("Load fishing vessels (without cache) in: " + delta1 + "ms"); // try again, to check cache is enable time = System.currentTimeMillis(); @@ -163,6 +164,7 @@ assertResultList(result, fixtures.refNbFishingVessel()); long delta2 = System.currentTimeMillis() - time; + log.debug("Load fishing vessels (with cache enable) in: " + delta2 + "ms"); //TODO-tc We should not test cache performance like this, depends to much of the computer usage,... // float reduceFactor = delta2 * 100 / delta1;
participants (1)
-
blavenier@users.forge.codelutin.com