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 CdmCacherBase {
|
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
|
@Override
|
34
|
public boolean isCachable(CdmBase cdmEntity) {
|
35
|
if(cdmEntity != null && cdmEntity instanceof DefinedTermBase) {
|
36
|
return true;
|
37
|
}
|
38
|
return false;
|
39
|
}
|
40
|
|
41
|
@Override
|
42
|
public <T extends CdmBase> T load(T cdmEntity) {
|
43
|
|
44
|
T cachedCdmEntity = getFromCache(cdmEntity);
|
45
|
if(cachedCdmEntity == null && isCachable(cdmEntity)) {
|
46
|
putToCache(cdmEntity);
|
47
|
cachedCdmEntity = cdmEntity;
|
48
|
}
|
49
|
return cachedCdmEntity;
|
50
|
}
|
51
|
}
|