cleanup
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / cache / CdmTermCacher.java
1 /**
2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.api.cache;
10
11 import java.util.UUID;
12
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.stereotype.Component;
15
16 import eu.etaxonomy.cdm.api.service.ITermService;
17 import eu.etaxonomy.cdm.model.common.CdmBase;
18 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
19
20 /**
21 * CDM Entity Cacher class which handles the caching of Defined Terms.
22 *
23 * @author cmathew
24 */
25 @Component
26 public class CdmTermCacher extends CdmCacherBase {
27
28 @Autowired
29 private ITermService termService;
30
31 @Override
32 protected void setup() {
33 DefinedTermBase.setCacher(this);
34 }
35
36 @Override
37 protected CdmBase findByUuid(UUID uuid) {
38 return termService.findWithoutFlush(uuid);
39 }
40
41 @Override
42 public boolean isCachable(CdmBase cdmEntity) {
43 if(cdmEntity != null && cdmEntity instanceof DefinedTermBase) {
44 return true;
45 }
46 return false;
47 }
48
49 @Override
50 public <T extends CdmBase> T load(T cdmEntity) {
51
52 T cachedCdmEntity = getFromCache(cdmEntity);
53 if(cachedCdmEntity == null && isCachable(cdmEntity)) {
54 putToCache(cdmEntity);
55 cachedCdmEntity = cdmEntity;
56 }
57 return cachedCdmEntity;
58 }
59 }