Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
2d846a15
Commit
2d846a15
authored
Jan 02, 2015
by
Matija Obreza
Browse files
CropService is @Cached
parent
fdac8c30
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/impl/CropServiceImpl.java
View file @
2d846a15
...
@@ -40,6 +40,8 @@ import org.genesys2.server.persistence.domain.Taxonomy2Repository;
...
@@ -40,6 +40,8 @@ import org.genesys2.server.persistence.domain.Taxonomy2Repository;
import
org.genesys2.server.service.CropService
;
import
org.genesys2.server.service.CropService
;
import
org.genesys2.server.service.HtmlSanitizer
;
import
org.genesys2.server.service.HtmlSanitizer
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
@@ -51,6 +53,8 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -51,6 +53,8 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional
(
readOnly
=
true
)
@Transactional
(
readOnly
=
true
)
public
class
CropServiceImpl
implements
CropService
{
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
);
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
CropServiceImpl
.
class
);
@Autowired
@Autowired
...
@@ -100,6 +104,7 @@ public class CropServiceImpl implements CropService {
...
@@ -100,6 +104,7 @@ public class CropServiceImpl implements CropService {
}
}
@Override
@Override
@Cacheable
(
value
=
CACHE_CROP_TAXONOMYCROPS
,
key
=
"#taxonomy2.id"
)
public
List
<
Crop
>
getCrops
(
Taxonomy2
taxonomy2
)
{
public
List
<
Crop
>
getCrops
(
Taxonomy2
taxonomy2
)
{
return
cropTaxonomyRepository
.
findCropsByTaxonomy
(
taxonomy2
);
return
cropTaxonomyRepository
.
findCropsByTaxonomy
(
taxonomy2
);
}
}
...
@@ -107,6 +112,7 @@ public class CropServiceImpl implements CropService {
...
@@ -107,6 +112,7 @@ public class CropServiceImpl implements CropService {
@Override
@Override
@Transactional
(
readOnly
=
false
,
propagation
=
Propagation
.
REQUIRES_NEW
)
@Transactional
(
readOnly
=
false
,
propagation
=
Propagation
.
REQUIRES_NEW
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@CacheEvict
(
value
=
CACHE_CROP_TAXONOMYCROPS
,
allEntries
=
true
)
public
void
rebuildTaxonomies
()
{
public
void
rebuildTaxonomies
()
{
LOG
.
warn
(
"REBUILDING ALL CROP TAXONOMIES!"
);
LOG
.
warn
(
"REBUILDING ALL CROP TAXONOMIES!"
);
...
@@ -120,6 +126,7 @@ public class CropServiceImpl implements CropService {
...
@@ -120,6 +126,7 @@ public class CropServiceImpl implements CropService {
@Override
@Override
@Transactional
(
readOnly
=
false
)
@Transactional
(
readOnly
=
false
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@CacheEvict
(
value
=
CACHE_CROP_TAXONOMYCROPS
,
allEntries
=
true
)
public
void
rebuildTaxonomies
(
Crop
crop
)
{
public
void
rebuildTaxonomies
(
Crop
crop
)
{
LOG
.
info
(
"Rebuilding crop taxonomy for: "
+
crop
.
getName
());
LOG
.
info
(
"Rebuilding crop taxonomy for: "
+
crop
.
getName
());
// for all rules
// for all rules
...
@@ -166,7 +173,7 @@ public class CropServiceImpl implements CropService {
...
@@ -166,7 +173,7 @@ public class CropServiceImpl implements CropService {
// To check
// To check
final
List
<
CropTaxonomy
>
existing
=
cropTaxonomyRepository
.
findByCrop
(
crop
);
final
List
<
CropTaxonomy
>
existing
=
cropTaxonomyRepository
.
findByCrop
(
crop
);
{
{
final
List
<
CropTaxonomy
>
toRemove
=
new
ArrayList
<
CropTaxonomy
>();
final
List
<
CropTaxonomy
>
toRemove
=
new
ArrayList
<
CropTaxonomy
>();
...
@@ -308,6 +315,7 @@ public class CropServiceImpl implements CropService {
...
@@ -308,6 +315,7 @@ public class CropServiceImpl implements CropService {
@Override
@Override
@Transactional
(
readOnly
=
false
)
@Transactional
(
readOnly
=
false
)
@CacheEvict
(
value
=
CACHE_CROP_TAXONOMYCROPS
,
key
=
"#taxonomy.id"
)
public
void
updateCropTaxonomyLists
(
Taxonomy2
taxonomy
)
{
public
void
updateCropTaxonomyLists
(
Taxonomy2
taxonomy
)
{
// Load all rules
// Load all rules
List
<
CropRule
>
cropRules
=
cropRuleRepository
.
findAll
();
List
<
CropRule
>
cropRules
=
cropRuleRepository
.
findAll
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment