Commit 2d846a15 authored by Matija Obreza's avatar Matija Obreza
Browse files

CropService is @Cached

parent fdac8c30
......@@ -40,6 +40,8 @@ import org.genesys2.server.persistence.domain.Taxonomy2Repository;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.HtmlSanitizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -51,6 +53,8 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional(readOnly = true)
public class CropServiceImpl implements CropService {
private static final String CACHE_CROP_TAXONOMYCROPS = "hibernate.org.genesys2.server.model.impl.Crop.taxonomyCrops";
public static final Log LOG = LogFactory.getLog(CropServiceImpl.class);
@Autowired
......@@ -100,6 +104,7 @@ public class CropServiceImpl implements CropService {
}
@Override
@Cacheable(value = CACHE_CROP_TAXONOMYCROPS, key = "#taxonomy2.id")
public List<Crop> getCrops(Taxonomy2 taxonomy2) {
return cropTaxonomyRepository.findCropsByTaxonomy(taxonomy2);
}
......@@ -107,6 +112,7 @@ public class CropServiceImpl implements CropService {
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, allEntries = true)
public void rebuildTaxonomies() {
LOG.warn("REBUILDING ALL CROP TAXONOMIES!");
......@@ -120,6 +126,7 @@ public class CropServiceImpl implements CropService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, allEntries = true)
public void rebuildTaxonomies(Crop crop) {
LOG.info("Rebuilding crop taxonomy for: " + crop.getName());
// for all rules
......@@ -166,7 +173,7 @@ public class CropServiceImpl implements CropService {
// To check
final List<CropTaxonomy> existing = cropTaxonomyRepository.findByCrop(crop);
{
final List<CropTaxonomy> toRemove = new ArrayList<CropTaxonomy>();
......@@ -308,6 +315,7 @@ public class CropServiceImpl implements CropService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = CACHE_CROP_TAXONOMYCROPS, key="#taxonomy.id")
public void updateCropTaxonomyLists(Taxonomy2 taxonomy) {
// Load all rules
List<CropRule> cropRules = cropRuleRepository.findAll();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment