Project

General

Profile

Revision b8404854

IDb8404854837408c72df002d4c901e2084107b98d
Parent cf186d49
Child be3c44be

Added by Andreas Müller 7 months ago

improve logging in CacheLoader

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CacheLoader.java
249 249

  
250 250
        if(cachedCdmEntity != null) {
251 251
            // if cdm entity was found in cache then
252
            if (logger.isDebugEnabled()){logger.debug(" - object of type " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + " already exists");}
252
            if (logger.isDebugEnabled()){logger.debug(" - object " + cdmEntity.getClass().getSimpleName() + "[" + cdmEntity.getId() + "|" + cdmEntity.getUuid() + "] already exists. ("+ System.identityHashCode(cdmEntity) +") already exists");}
253 253
            // .. return if the cached and input objects are identical, else (this is a newly loaded object so) continue
254 254
            if(cachedCdmEntity == cdmEntity) {
255 255
                return cachedCdmEntity;
......
258 258

  
259 259
        T loadedCdmBase;
260 260
        if(isRecursiveEnabled && recursive) {
261
            if (logger.isDebugEnabled()){logger.debug("---- starting recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId());}
261
            if (logger.isDebugEnabled()){logger.debug("---- starting recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")");}
262 262
            List<Object> alreadyVisitedEntities = new ArrayList<>();
263 263
            T cb = loadRecursive(cdmEntity, alreadyVisitedEntities, update);
264 264
            alreadyVisitedEntities.clear();
265
            if (logger.isDebugEnabled()){logger.debug("---- ending recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "\n");}
265
            if (logger.isDebugEnabled()){logger.debug("---- ending recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")\n");}
266 266
            loadedCdmBase =  cb;
267 267
        } else {
268 268
            loadedCdmBase = putToCache(cdmEntity);
......
270 270
        return loadedCdmBase;
271 271

  
272 272
//        if(isRecursiveEnabled && recursive) {
273
//            if (logger.isDebugEnabled()){logger.debug("---- starting recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId());}
273
//            if (logger.isDebugEnabled()){logger.debug("---- starting recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")" );}
274 274
//            List<Object> alreadyVisitedEntities = new ArrayList<>();
275 275
//            loadedCdmBase = loadRecursive(cdmEntity, alreadyVisitedEntities, update);
276 276
//            alreadyVisitedEntities.clear();
277
//            if (logger.isDebugEnabled()){logger.debug("---- ending recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "\n");}
277
//            if (logger.isDebugEnabled()){logger.debug("---- ending recursive load for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")" + "\n");}
278 278
//        } else if (update){
279
//            if (logger.isDebugEnabled()){logger.debug("---- update cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId());}
279
//            if (logger.isDebugEnabled()){logger.debug("---- update cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")" );}
280 280
//            loadedCdmBase = loadRecursive(cdmEntity, null, update);
281
//            if (logger.isDebugEnabled()){logger.debug("---- ending update for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "\n");}
281
//            if (logger.isDebugEnabled()){logger.debug("---- ending update for cdm entity " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + + "("+ System.identityHashCode(cdmEntity) +")\n");}
282 282
//        } else {
283 283
//            loadedCdmBase = putToCache(cdmEntity);
284 284
//        }
......
290 290
     * Puts the entity to the cache if it does not yet exist and returns the cached entity.
291 291
     */
292 292
    protected <T extends CdmBase> T putToCache(T cdmEntity) {
293
        if (logger.isDebugEnabled()){logger.debug("put object of type " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + " to cache ");}
293
        if (logger.isDebugEnabled()){logger.debug("put object of type " + cdmEntity.getClass().getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +") to cache ");}
294 294
        cdmCacher.putToCache(ProxyUtils.deproxyIfInitialized(cdmEntity));
295 295
        return cdmCacher.getFromCache(cdmEntity);
296 296
    }
......
316 316
     */
317 317
    private <T extends CdmBase> T loadRecursive(T cdmEntity,  List<Object> alreadyVisitedEntities, boolean update) {
318 318
        if (cdmCacher.ignoreRecursiveLoad(cdmEntity)){
319
            if (logger.isDebugEnabled()){logger.debug("recursive load for " + cdmEntity.getClass() + "#" + cdmEntity.getId() + " which is usually ignored by the cache");}
319
            if (logger.isDebugEnabled()){logger.debug("recursive load for " + cdmEntity.getClass() + "#" + cdmEntity.getId()+ "("+ System.identityHashCode(cdmEntity) +") which is usually ignored by the cache");}
320 320
        }
321 321
        T cachedCdmEntity = putToCache(cdmEntity);
322 322

  
......
326 326
        // start by getting the fields from the cdm entity
327 327
        T deproxiedEntity = ProxyUtils.deproxyOrNull(cdmEntity);
328 328
        if(deproxiedEntity == null){
329
            if (logger.isDebugEnabled()){logger.debug("ignoring uninitlialized proxy " + cdmEntity.getClass() + "#" + cdmEntity.getId());}
329
            if (logger.isDebugEnabled()){logger.debug("ignoring uninitlialized proxy " + cdmEntity.getClass() + "#" + cdmEntity.getId()+ "("+ System.identityHashCode(cdmEntity) +")" );}
330 330
        }else{
331 331
            String className = deproxiedEntity.getClass().getName();
332 332
            CdmModelFieldPropertyFromClass classFields = getFromCdmlibModelCache(className);
......
362 362
            CdmBase cdmEntityInSubGraph = (CdmBase)fieldValue;
363 363
            if(!entityAlreadyVisisted(alreadyVisitedEntities, cdmEntityInSubGraph) ) {
364 364
                if(cdmCacher.ignoreRecursiveLoad(cdmEntityInSubGraph)){
365
                    if (logger.isDebugEnabled()){logger.debug("recursive load of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId() + " ignored");}
365
                    if (logger.isDebugEnabled()){logger.debug("recursive load of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId() + "("+ System.identityHashCode(cdmEntityInSubGraph) +") ignored");}
366 366
                }else{
367
                    if (logger.isDebugEnabled()){logger.debug("recursive loading object of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId());}
367
                    if (logger.isDebugEnabled()){logger.debug("recursive loading object of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId() + "("+ System.identityHashCode(cdmEntityInSubGraph) +")" );}
368 368
                    loadRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, update);
369 369
                }
370 370
            } else {
371
                if (logger.isDebugEnabled()){logger.debug("object of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId() + " already visited");}
371
                if (logger.isDebugEnabled()){logger.debug("object of type " + cdmEntityInSubGraph.getClass().getSimpleName() + " with id " + cdmEntityInSubGraph.getId() + "("+ System.identityHashCode(cdmEntityInSubGraph) +") already visited");}
372 372
            }
373 373
//        } else if (fieldValue != null){
374 374
//            throw new IllegalArgumentException("Unhandled field value of type " + fieldValue.getClass().getName() + " for field " + field);
......
443 443

  
444 444
            if(obj != null && !ProxyUtils.isUninitializedProxy(obj)) {
445 445
                if(CdmBase.class.isAssignableFrom(obj.getClass())) {
446
                    if (logger.isDebugEnabled()){logger.debug("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getSimpleName() + " with id " + cdmEntity.getId());}
446
                    if (logger.isDebugEnabled()){logger.debug("found initialised cdm entity '" + fieldName + "' in object of type " + clazz.getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")" );}
447 447

  
448 448
                    cdmEntityInSubGraph = (CdmBase)obj;
449 449
                    CdmBase cachedCdmEntityInSubGraph = cdmCacher.getFromCache(cdmEntityInSubGraph);
......
454 454
                            // the field has been already initialized, cached and
455 455
                            // is not the same as the one in the cache, in which case we set the value
456 456
                            // of the field to the one found in the cache
457
                            if (logger.isDebugEnabled()){logger.debug("setting cached + real value to '" + fieldName + "' in object of type " + clazz.getSimpleName() + " with id " + cdmEntity.getId());}
457
                            if (logger.isDebugEnabled()){logger.debug("setting cached + real value to '" + fieldName + "' in object of type " + clazz.getSimpleName() + " with id " + cdmEntity.getId() + "("+ System.identityHashCode(cdmEntity) +")" );}
458 458
                            field.set(cachedCdmEntity, cachedCdmEntityInSubGraph);
459 459
                            field.set(cdmEntity, cachedCdmEntityInSubGraph);
460 460
                        } else {

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)