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.common.DefinedTermBase;
|
11
|
|
12
|
/**
|
13
|
* CDM Entity Cacher class which handles the caching of Defined Terms.
|
14
|
*
|
15
|
* @author cmathew
|
16
|
*
|
17
|
* @param <T>
|
18
|
*/
|
19
|
@Component
|
20
|
public class CdmTermCacher extends CdmCacher {
|
21
|
|
22
|
@Autowired
|
23
|
ITermService termService;
|
24
|
|
25
|
@Override
|
26
|
protected void setup() {
|
27
|
DefinedTermBase.setCacher(this);
|
28
|
}
|
29
|
|
30
|
@Override
|
31
|
protected CdmBase findByUuid(UUID uuid) {
|
32
|
return termService.findWithoutFlush(uuid);
|
33
|
}
|
34
|
|
35
|
|
36
|
@Override
|
37
|
public boolean isCachable(CdmBase cdmEntity) {
|
38
|
if(cdmEntity != null && cdmEntity instanceof DefinedTermBase) {
|
39
|
return true;
|
40
|
}
|
41
|
return false;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public <T extends CdmBase> T load(T cdmEntity) {
|
46
|
|
47
|
T cachedCdmEntity = getFromCache(cdmEntity);
|
48
|
if(cachedCdmEntity == null && isCachable(cdmEntity)) {
|
49
|
put(cdmEntity);
|
50
|
cachedCdmEntity = cdmEntity;
|
51
|
}
|
52
|
return cachedCdmEntity;
|
53
|
|
54
|
}
|
55
|
}
|