Project

General

Profile

« Previous | Next » 

Revision ba0d4c2f

Added by Cherian Mathew about 9 years ago

httpInvokerServiceClients.xml : set 'CdmServiceRequestExecutor' class as default for all services
ICdmEntitySession, CdmEntitySession, MockCdmEntitySession : added method to update session
ICdmEntitySessionManager, CdmEntitySessionManager, MockCdmEntitySessionManager : added methods to set active session, dispose and update sessions
ProxyUtils : added utility method
EntityCacherDebugResult : corrected method to determine cache corresponding to entity
CdmTransientEntityCacher : corrected put method
CacheLoader : optimised recursive call
CdmServiceCacher : corrected methods to get from cache and load
CdmServiceRequestExecutor : added update result return calls to load

View differences:

eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java
12 12
import eu.etaxonomy.cdm.model.common.CdmBase;
13 13
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
14 14
import eu.etaxonomy.taxeditor.remoting.cache.CacheLoader;
15
import eu.etaxonomy.taxeditor.remoting.cache.CdmEntityCacheKey;
15 16
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
16 17
import eu.etaxonomy.taxeditor.service.TermServiceRequestExecutor;
18
import eu.etaxonomy.taxeditor.session.CdmEntitySession;
19
import eu.etaxonomy.taxeditor.session.CdmEntitySessionManager;
20
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
17 21

  
18 22
/**
19 23
 * Class which uses CDM services to cache cdm entities
......
27 31
 * @param <T>
28 32
 */
29 33
@Component
30
public class CdmServiceCacher extends CdmCacher{
34
public class CdmServiceCacher extends CdmCacher {
31 35

  
32 36
    @Autowired
33 37
    ITermService termService;
34 38

  
39
    @Autowired
40
    private CdmEntitySessionManager cdmEntitySessionManager;
41

  
42
    private CdmTransientEntityCacher cdmTransientEntityCacher;
43

  
35 44
    private CacheLoader cacheLoader;
36 45

  
37 46
    @Override
......
76 85
        return false;
77 86
    }
78 87

  
88
    public void setActiveSession(ICdmEntitySession cdmEntitySession) {
89
        if(cdmEntitySession != null && cdmEntitySession instanceof CdmEntitySession) {
90
            this.cdmTransientEntityCacher = ((CdmEntitySession) cdmEntitySession).getCacher();
91
        } else {
92
            this.cdmTransientEntityCacher = null;
93
        }
94
    }
95

  
96
    @Override
97
    public CdmBase getFromCache(CdmBase cdmBase) {
98
        CdmBase cachedCdmEntity = null;
99
        // first we check in the active session cache if the
100
        if(!isCachable(cdmBase) && cdmTransientEntityCacher != null) {
101
            CdmEntityCacheKey key = CdmTransientEntityCacher.generateKey(cdmBase);
102
            cachedCdmEntity = cdmTransientEntityCacher.getFromCache(key);
103

  
104
        }
105
        if(cachedCdmEntity == null) {
106
            cachedCdmEntity = super.getFromCache(cdmBase);
107
        }
108
        return cachedCdmEntity;
109
    }
110

  
79 111

  
80 112
    /* (non-Javadoc)
81 113
     * @see eu.etaxonomy.cdm.api.cache.CdmCacher#load(eu.etaxonomy.cdm.model.common.CdmBase)
82 114
     */
83 115
    @Override
84 116
    public CdmBase load(CdmBase cdmEntity) {
85
        CdmBase cachedCdmEntity = getFromCache(cdmEntity);
86
        // NOTE : only when no cached cdm entity exists we
87
        // load the entire sub-graph, which means that the
88
        // sub-graph is never updated if the input
89
        // cdm entity graph is newer
90
        if(cachedCdmEntity == null && isCachable(cdmEntity)) {
117
        CdmBase cachedCdmEntity = getFromCache(cdmEntity.getUuid());
118

  
119
        if(isCachable(cdmEntity)) {
91 120
            cachedCdmEntity =  cacheLoader.load(cdmEntity, true, false);
92 121
        }
93 122
        return cachedCdmEntity;

Also available in: Unified diff