Project

General

Profile

« Previous | Next » 

Revision 18efc5a7

Added by Andreas Müller over 3 years ago

rename deproxy to deproxyIfInitialized

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CacheLoader.java
265 265
     */
266 266
    protected <T extends CdmBase> T putToCache(T cdmEntity) {
267 267
        if (logger.isDebugEnabled()){logger.debug("put object of type " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + " to cache ");}
268
        cdmCacher.putToCache(ProxyUtils.deproxy(cdmEntity));
268
        cdmCacher.putToCache(ProxyUtils.deproxyIfInitialized(cdmEntity));
269 269
        return cdmCacher.getFromCache(cdmEntity);
270 270
    }
271 271

  
......
388 388
            field.setAccessible(true);
389 389
            Object obj = field.get(cdmEntity);
390 390
            // resetting the value in cdm entity to the deproxied object
391
            obj = ProxyUtils.deproxy(obj);
391
            obj = ProxyUtils.deproxyIfInitialized(obj);
392 392
            field.set(cdmEntity, obj);
393 393
            Object cachedObj = field.get(cachedCdmEntity);
394 394
            CdmBase cdmEntityInSubGraph = null;
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmTransientEntityCacher.java
288 288
        if (!cdmBase.isPersited()){
289 289
            return (T)volatileEntitiesMap.get(cdmBase.getUuid());
290 290
        }else{
291
            CdmEntityCacheKey<T> cacheId = generateKey(ProxyUtils.deproxy(cdmBase));
291
            CdmEntityCacheKey<T> cacheId = generateKey(ProxyUtils.deproxyIfInitialized(cdmBase));
292 292
            // first try this cache
293 293
            T  cachedCdmEntity = getFromCache(cacheId);
294 294

  
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/EntityCacherDebugResult.java
232 232
        }
233 233
        logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
234 234
        List<CdmEntityInfo> alreadyVisitedEntities = new ArrayList<CdmEntityInfo>();
235
        CdmEntityInfo cei = new CdmEntityInfo(ProxyUtils.deproxy(cdmEntity));
235
        CdmEntityInfo cei = new CdmEntityInfo(ProxyUtils.deproxyIfInitialized(cdmEntity));
236 236
        debugRecursive(cdmEntity, alreadyVisitedEntities, cei);
237 237
        rootElements.add(cei);
238 238
        alreadyVisitedEntities.clear();
......
268 268
            CdmEntityInfo childCei = new CdmEntityInfo(e);
269 269
            cei.addChild(childCei);
270 270

  
271
            CdmEntityInfo keyCei = new CdmEntityInfo(ProxyUtils.deproxy(e.getKey()));
271
            CdmEntityInfo keyCei = new CdmEntityInfo(ProxyUtils.deproxyIfInitialized(e.getKey()));
272 272
            childCei.addChild(keyCei);
273
            CdmEntityInfo valueCei = new CdmEntityInfo(ProxyUtils.deproxy(e.getValue()));
273
            CdmEntityInfo valueCei = new CdmEntityInfo(ProxyUtils.deproxyIfInitialized(e.getValue()));
274 274
            childCei.addChild(valueCei);
275 275

  
276 276
            debugRecursive(e.getKey(), alreadyVisitedEntities, keyCei);
......
293 293
                }
294 294
            }
295 295
            if(!alreadyVisited){
296
                CdmEntityInfo childCei = new CdmEntityInfo(ProxyUtils.deproxy(obj));
296
                CdmEntityInfo childCei = new CdmEntityInfo(ProxyUtils.deproxyIfInitialized(obj));
297 297
                cei.addChild(childCei);
298 298
                debugRecursive(obj, alreadyVisitedEntities, childCei);
299 299
            }
......
306 306

  
307 307
        if(cei.getObject() instanceof CdmBase) {
308 308
           CdmBase cb =  (CdmBase)cei.getObject();
309
           cb = (CdmBase) ProxyUtils.deproxy(cb);
309
           cb = (CdmBase) ProxyUtils.deproxyIfInitialized(cb);
310 310
           CdmBase cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
311 311
           if(cachedCdmEntityInSubGraph != cb) {
312 312
               cei.setNotInCacheDetail(cachedCdmEntityInSubGraph == null ? NotInCacheDetail.NOT_FOUND : NotInCacheDetail.COPY_ENTITY);
......
369 369
            }
370 370
            field.setAccessible(true);
371 371
            Object o = field.get(cdmEntity);
372
            o = ProxyUtils.deproxy(o);
372
            o = ProxyUtils.deproxyIfInitialized(o);
373 373
            CdmBase cdmEntityInSubGraph = null;
374 374

  
375 375
            childCei = new CdmEntityInfo(o);
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/ProxyUtils.java
134 134
     * de-proxies the passed object <code>o</code> if it is an initialized proxy object,
135 135
     * otherwise <code>o</code> is returned.
136 136
     */
137
    public static <T extends Object> T deproxy(T o) {
137
    public static <T extends Object> T deproxyIfInitialized(T o) {
138 138
        if(o != null && o instanceof HibernateProxy) {
139 139
            LazyInitializer hli = ((HibernateProxy)o).getHibernateLazyInitializer();
140 140
            if(!hli.isUninitialized()) {
141
                return (T)hli.getImplementation();
141
                @SuppressWarnings("unchecked")
142
                T result = (T)hli.getImplementation();
143
                return result;
142 144
            }
143 145
        }
144 146

  
145 147
        if(o != null && o instanceof PersistentCollection) {
146 148
            PersistentCollection pc = ((PersistentCollection)o);
147 149
            if(pc.wasInitialized()) {
148
                return (T)ProxyUtils.getObject(pc);
150
                @SuppressWarnings("unchecked")
151
                T result = (T)ProxyUtils.getObject(pc);
152
                return result;
149 153
            }
150 154
        }
151 155
        return o;

Also available in: Unified diff