Project

General

Profile

Revision b486d565

IDb486d565b50194856bedf6654d86aa700aa5a44b
Parent 8991d6e9
Child def46519

Added by Andreas Müller 4 months ago

ref #7709 rename newEntity to volatileEntity

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmTransientEntityCacher.java
35 35

  
36 36
/**
37 37
 * This cache handles transient (id>0) and volatile (id=0) CdmBase objects.
38
 * Volatile objects need to be added via {@link #putNewEntity(CdmBase)}
38
 * Volatile objects need to be added via {@link #putVolatitleEntity(CdmBase)}
39 39
 * and their id is updated as soon as a transient object with the same
40 40
 * uuid is added to the cacher.
41 41
 *
......
65 65
    private final CacheLoader cacheLoader;
66 66

  
67 67
    //map for volatile entities (id=0)
68
    private final Map<UUID, CdmBase> newEntitiesMap = new HashMap<>();
68
    private final Map<UUID, CdmBase> volatileEntitiesMap = new HashMap<>();
69 69

  
70 70
    private static volatile boolean managementBeansConfigured = false;
71 71

  
......
201 201
        return cacheLoader.getFromCdmlibModelCache(className);
202 202
    }
203 203

  
204
    private void putNewEntity(CdmBase newEntity) {
205
        if(newEntity != null && newEntity.getId() == 0 && newEntity.getUuid() != null) {
206
            CdmBase cachedEntity = newEntitiesMap.get(newEntity.getUuid());
204
    private void putVolatitleEntity(CdmBase volatileEntity) {
205
        if(volatileEntity != null && volatileEntity.getId() == 0 && volatileEntity.getUuid() != null) {
206
            CdmBase cachedEntity = volatileEntitiesMap.get(volatileEntity.getUuid());
207 207
            if (cachedEntity == null){
208
                newEntitiesMap.put(newEntity.getUuid(), newEntity);
208
                volatileEntitiesMap.put(volatileEntity.getUuid(), volatileEntity);
209 209
            }
210 210
        }
211 211
    }
......
222 222
        if (cdmEntity == null){
223 223
            return;
224 224
        }else if (!cdmEntity.isPersited()){
225
            putNewEntity(cdmEntity);
225
            putVolatitleEntity(cdmEntity);
226 226
        }else{
227 227
            CdmBase cachedCdmEntity = permanentCache.load(cdmEntity);
228 228
            if(cachedCdmEntity != null) {
......
234 234
            cachedCdmEntity = getFromCache(key);
235 235
            if(cachedCdmEntity == null) {
236 236
                CdmBase cdmEntityToCache = cdmEntity;
237
                CdmBase newInMapEntity = newEntitiesMap.get(cdmEntity.getUuid());
238
                if(newInMapEntity != null) {
239
                    newInMapEntity.setId(cdmEntity.getId());
240
                    cdmEntityToCache = newInMapEntity;
237
                CdmBase cachedVolatileEntity = volatileEntitiesMap.get(cdmEntity.getUuid());
238
                if(cachedVolatileEntity != null) {
239
                    cachedVolatileEntity.setId(cdmEntity.getId());
240
                    cdmEntityToCache = cachedVolatileEntity;
241 241
                }
242 242
                putToTransientCache(key, cdmEntityToCache);
243 243
                cdmEntityToCache.initListener();
244
                newEntitiesMap.remove(cdmEntity.getUuid());
244
                volatileEntitiesMap.remove(cdmEntity.getUuid());
245 245
                if (logger.isDebugEnabled()){logger.debug(" - object of type " + cdmEntityToCache.getClass().getName() + " with id " + cdmEntityToCache.getId() + " put in cache");}
246 246
                return;
247 247
            }else{
......
285 285
    @Override
286 286
    public <T extends CdmBase> T getFromCache(T cdmBase) {
287 287
        if (!cdmBase.isPersited()){
288
            return (T)newEntitiesMap.get(cdmBase.getUuid());
288
            return (T)volatileEntitiesMap.get(cdmBase.getUuid());
289 289
        }else{
290 290
            CdmEntityCacheKey<T> cacheId = generateKey(ProxyUtils.deproxy(cdmBase));
291 291
            // first try this cache
......
320 320

  
321 321
    public void clear() {
322 322
        cache.removeAll();
323
        newEntitiesMap.clear();
323
        volatileEntitiesMap.clear();
324 324
    }
325 325

  
326 326
    @Override
327 327
    public void dispose() {
328 328
        getCacheManager().removeCache(cache.getName());
329 329
        cache.dispose();
330
        newEntitiesMap.clear();
330
        volatileEntitiesMap.clear();
331 331
    }
332 332

  
333 333
    @Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)