1
|
package eu.etaxonomy.cdm.api.cache;
|
2
|
|
3
|
import java.util.UUID;
|
4
|
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
import org.springframework.stereotype.Component;
|
7
|
|
8
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
9
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
10
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
11
|
|
12
|
/**
|
13
|
* CDM Entity Cacher class which handles the caching of Defined Terms.
|
14
|
*
|
15
|
* @author cmathew
|
16
|
*/
|
17
|
@Component
|
18
|
public class CdmTermCacher extends CdmCacher {
|
19
|
|
20
|
@Autowired
|
21
|
ITermService termService;
|
22
|
|
23
|
@Override
|
24
|
protected void setup() {
|
25
|
DefinedTermBase.setCacher(this);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
protected CdmBase findByUuid(UUID uuid) {
|
30
|
return termService.findWithoutFlush(uuid);
|
31
|
}
|
32
|
|
33
|
|
34
|
@Override
|
35
|
public boolean isCachable(CdmBase cdmEntity) {
|
36
|
if(cdmEntity != null && cdmEntity instanceof DefinedTermBase) {
|
37
|
return true;
|
38
|
}
|
39
|
return false;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public <T extends CdmBase> T load(T cdmEntity) {
|
44
|
|
45
|
T cachedCdmEntity = getFromCache(cdmEntity);
|
46
|
if(cachedCdmEntity == null && isCachable(cdmEntity)) {
|
47
|
put(cdmEntity);
|
48
|
cachedCdmEntity = cdmEntity;
|
49
|
}
|
50
|
return cachedCdmEntity;
|
51
|
|
52
|
}
|
53
|
}
|