Project

General

Profile

Revision be3c44be

IDbe3c44beb0325c27eebee004a96d216a75b7f6bb
Parent b8404854
Child 86d726ac

Added by Andreas Müller 7 months ago

cleanup and improve logging in EntityCacherDebugResult

View differences:

cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/EntityCacherDebugResult.java
66 66
    }
67 67

  
68 68
    private void init() {
69
        duplicateCdmEntityMap = new HashMap<CdmEntityInfo, CdmEntityInfo>();
70
        notInCacheList = new ArrayList<CdmEntityInfo>();
71
        rootElements = new ArrayList<CdmEntityInfo>();
69
        duplicateCdmEntityMap = new HashMap<>();
70
        notInCacheList = new ArrayList<>();
71
        rootElements = new ArrayList<>();
72 72
    }
73 73

  
74 74
    private void clear() {
......
108 108
        sb.append("<<< Root Entity " + rootEntity.getUserFriendlyTypeName() + " with id " + rootEntity.getId() + " >>>");
109 109
        sb.append(System.getProperty("line.separator"));
110 110
        if(duplicateCdmEntityMap.isEmpty()) {
111
            sb.append("No Duplicate CDM Entities.");
111
            sb.append("No Duplicate CDM Entities in root graph.");
112 112
        } else {
113
            sb.append("Duplicate CDM Entities,");
113
            sb.append("Duplicate CDM Entities in root graph: ");
114

  
115
            for (Map.Entry<CdmEntityInfo, CdmEntityInfo> entry : duplicateCdmEntityMap.entrySet()){
114 116

  
115
            for (Map.Entry<CdmEntityInfo, CdmEntityInfo> entry : duplicateCdmEntityMap.entrySet())
116
            {
117 117
                sb.append(System.getProperty("line.separator"));
118 118
                CdmEntityInfo cei = entry.getKey();
119 119
                CdmBase cb = (CdmBase) cei.getObject();
120 120

  
121
                sb.append(" - " + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
121
                sb.append(" 1 " + cei.getField().getName() + ":" + cb.getUserFriendlyTypeName() + "/" + cb.getId());
122 122
                if(cei.getParent() != null) {
123 123
                    Object cbParent = cei.getParent().getObject();
124 124
                    sb.append("     in entity " + cbParent.getClass().getCanonicalName());
125 125
                    if(cbParent instanceof CdmBase) {
126

  
127 126
                        sb.append(" with id : " + ((CdmBase)cbParent).getId());
128 127
                    }
129 128
                }
......
139 138
                if(dupCei.getField() != null) {
140 139
                    dupCeiFieldName = dupCei.getField().getName();
141 140
                }
142
                sb.append(" - " + dupCeiFieldName + ":" + dupCb.getUserFriendlyTypeName() + "/" + dupCb.getId());
141
                sb.append(" 2 " + dupCeiFieldName + ":" + dupCb.getUserFriendlyTypeName() + "/" + dupCb.getId());
143 142
                if(dupCei.getParent() != null) {
144 143
                    Object dupCbParent = dupCei.getParent().getObject();
145 144
                    sb.append("      in entity " + dupCbParent.getClass().getCanonicalName());
......
231 230
            return;
232 231
        }
233 232
        logger.info("---- starting recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId());
234
        List<CdmEntityInfo> alreadyVisitedEntities = new ArrayList<CdmEntityInfo>();
233
        List<CdmEntityInfo> alreadyVisitedEntities = new ArrayList<>();
235 234
        CdmEntityInfo cei = new CdmEntityInfo(ProxyUtils.deproxyIfInitialized(cdmEntity));
236
        debugRecursive(cdmEntity, alreadyVisitedEntities, cei);
235
        if(recursive){
236
            debugRecursive(cdmEntity, alreadyVisitedEntities, cei, includeIgnored);
237
        }
237 238
        rootElements.add(cei);
238 239
        alreadyVisitedEntities.clear();
239 240
        logger.info("---- ending recursive debug for cdm entity " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + "\n");
......
306 307

  
307 308
        if(cei.getObject() instanceof CdmBase) {
308 309
           CdmBase cb =  (CdmBase)cei.getObject();
309
           cb = (CdmBase) ProxyUtils.deproxyIfInitialized(cb);
310
           cb = ProxyUtils.deproxyIfInitialized(cb);
310 311
           CdmBase cachedCdmEntityInSubGraph = cacher.getFromCache(cb);
311 312
           if(cachedCdmEntityInSubGraph != cb) {
312 313
               cei.setNotInCacheDetail(cachedCdmEntityInSubGraph == null ? NotInCacheDetail.NOT_FOUND : NotInCacheDetail.COPY_ENTITY);
......
316 317
           }
317 318
        }
318 319

  
319
        // we want to recursive through the cdmEntity (and not the cachedCdmEntity)
320
        // we want to recurse through the cdmEntity (and not the cachedCdmEntity)
320 321
        // since there could be new or deleted objects in the cdmEntity sub-graph
321 322

  
322 323
        // start by getting the fields from the cdm entity
323 324
        String className = cdmEntity.getClass().getName();
324
        CdmModelFieldPropertyFromClass cmgmfc = cacher.getFromCdmlibModelCache(className);
325
        if(cmgmfc != null) {
325
        CdmModelFieldPropertyFromClass classFields = cacher.getFromCdmlibModelCache(className);
326
        if(classFields != null) {
326 327
            alreadyVisitedEntities.add(cei);
327
            List<String> fields = cmgmfc.getFields();
328
            List<String> fields = classFields.getFields();
328 329
            for(String field : fields) {
329
                // retrieve the actual object corresponding to the field.
330
                // this object will be either a CdmBase or a Collection / Map
331
                // with CdmBase as the generic type
332
                CdmEntityInfo childCei = getDebugCdmBaseTypeFieldValue(cdmEntity, field, alreadyVisitedEntities, cei);
333
                if(!childCei.isProxy()) {
334
                    Object object = childCei.getObject();
335
                    if(object != null && object instanceof CdmBase) {
336
                        CdmBase cdmEntityInSubGraph = (CdmBase)object;
337
                        if(!containsIdenticalCdmEntity(alreadyVisitedEntities, cdmEntityInSubGraph)) {
338
                            logger.info("recursive debugging object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId());
339
                            debugRecursive(cdmEntityInSubGraph, alreadyVisitedEntities, childCei);
340
                        } else {
341
                            logger.info("object of type " + cdmEntityInSubGraph.getClass().getName() + " with id " + cdmEntityInSubGraph.getId() + " already visited");
342
                        }
343
                    }
344
                }
330
                debugField(cdmEntity, alreadyVisitedEntities, cei, field, includeIgnored);
345 331
            }
346 332
        } else {
347 333
            throw new CdmClientCacheException("CdmEntity with class " + cdmEntity.getClass().getName() + " is not found in the cdmlib model cache. " +
......
441 427
        private CdmEntityInfo parent;
442 428
        private List<CdmEntityInfo> children;
443 429
        private Field field;
444
        private String label;
445 430
        private boolean isProxy;
446
        private NotInCacheDetail notInCacheDetail = null;
431
        private NotInCacheType notInCacheType = null;
447 432

  
448 433
        public CdmEntityInfo(Object object) {
449 434
            this.object = object;
450 435
            isProxy = false;
451
            children = new ArrayList<CdmEntityInfo>();
436
            children = new ArrayList<>();
452 437
        }
453 438

  
454 439
        public CdmEntityInfo getParent() {
......
518 503
                } else {
519 504
                    label = "[" + className + "] " + fieldName + " : " + object.toString();
520 505
                }
506
                label += " {"+ System.identityHashCode(object) + "}";
521 507
            } else {
522 508
                label = "[NULL] " + fieldName;
523 509
            }
524 510
            return label;
525 511
        }
526 512

  
527
        public void setLabel(String label) {
528
            this.label = label;
529
        }
530

  
531 513
        public Object getObject() {
532 514
            return object;
533 515
        }
......
544 526
            this.isProxy = isProxy;
545 527
        }
546 528

  
547
        public NotInCacheDetail getNotInCacheDetail() {
548
            return notInCacheDetail;
529
        public NotInCacheType getNotInCacheDetail() {
530
            return notInCacheType;
549 531
        }
550
        public void setNotInCacheDetail(NotInCacheDetail notInCacheDetail) {
551
            this.notInCacheDetail = notInCacheDetail;
532
        public void setNotInCacheDetail(NotInCacheType notInCacheType) {
533
            this.notInCacheType = notInCacheType;
552 534
        }
553 535
    }
554 536

  
555
    enum NotInCacheDetail {
537
    enum NotInCacheType {
556 538
        NOT_FOUND("*"),
557 539
        COPY_ENTITY("?");
558 540

  
559 541
        private String label;
560 542

  
561
        private NotInCacheDetail(String label){
543
        private NotInCacheType(String label){
562 544
            this.label = label;
563 545
        }
564 546

  
......
566 548
            return label;
567 549
        }
568 550
    }
569

  
570
}
551
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)