# HG changeset patch # User casties # Date 1476279236 -7200 # Node ID 3485498af8c396b5a7bf8153133405ef113ccac6 # Parent 63fe33172397502a45bd733da8be64cba740c0ac small comments and refactoring. diff -r 63fe33172397 -r 3485498af8c3 src/main/java/org/mpi/openmind/cache/AbstractCacheService.java --- a/src/main/java/org/mpi/openmind/cache/AbstractCacheService.java Tue Oct 11 20:55:36 2016 +0200 +++ b/src/main/java/org/mpi/openmind/cache/AbstractCacheService.java Wed Oct 12 15:33:56 2016 +0200 @@ -60,6 +60,12 @@ this.entMap.put(ent.getKey(), ent); } + /** + * Returns (a clone of a read-only) entity by id. + * + * @param id + * @return + */ public Entity getEntityById(Long id){ Entity ent = getEntityByIdReadOnly(id); if(ent != null){ @@ -69,21 +75,21 @@ } public Entity getEntityByIdReadOnly(Long id){ - if(id == null){ + if (id == null) { try { throw new Exception("Id of entity can not be null."); } catch (Exception e) { logger.error(e.getMessage(), e); } - }else{ + } else { Entity ent = this.entMap.getValuesByOwnKey(id); - if(ent == null){ + if (ent == null) { logger.debug("Entity no found in cache ID=" + id); List list = getPs().getLightweightEntities(Node.SYS_STATUS_CURRENT_VERSION, id, Node.TYPE_ABOX, null, null, true, 1); if (list.size() > 0) { ent = list.get(0); - getEntitiesByDef(ent.getObjectClass()); + loadEntitiesByDef(ent.getObjectClass()); } } return ent; @@ -91,12 +97,18 @@ return null; } - public List getEntitiesByDef(String oc){ + /** + * Load all entities of the given object class into the cache. + * + * @param oc + * @return + */ + public List loadEntitiesByDef(String oc){ logger.debug("[" + Thread.currentThread().getId() + "]\tgetEntitiesByDef=" + oc + "\nHashCode=" + this.hashCode()); - if(entLoadedByOC.get(oc) == null || entLoadedByOC.get(oc) == false){ - + + if (entLoadedByOC.get(oc) == null || entLoadedByOC.get(oc) == false) { synchronized (entMap) { - if(entLoadedByOC.get(oc) == null){ + if (entLoadedByOC.get(oc) == null) { long start = System.currentTimeMillis(); logger.debug("[" + Thread.currentThread().getId() + diff -r 63fe33172397 -r 3485498af8c3 src/main/java/org/mpi/openmind/cache/CacheService.java --- a/src/main/java/org/mpi/openmind/cache/CacheService.java Tue Oct 11 20:55:36 2016 +0200 +++ b/src/main/java/org/mpi/openmind/cache/CacheService.java Wed Oct 12 15:33:56 2016 +0200 @@ -149,7 +149,7 @@ } public int getEntitiesCount(String def){ - return this.getEntitiesByDef(def).size(); + return this.loadEntitiesByDef(def).size(); } diff -r 63fe33172397 -r 3485498af8c3 src/main/java/org/mpi/openmind/cache/WrapperService.java --- a/src/main/java/org/mpi/openmind/cache/WrapperService.java Tue Oct 11 20:55:36 2016 +0200 +++ b/src/main/java/org/mpi/openmind/cache/WrapperService.java Wed Oct 12 15:33:56 2016 +0200 @@ -74,7 +74,7 @@ if(StringUtils.isEmpty(term)) return rs; - List entList = this.cache.getEntitiesByDef(oc); + List entList = this.cache.loadEntitiesByDef(oc); term = NormalizerUtils.normalize(term); for(Entity ent : entList){ @@ -204,7 +204,7 @@ } public List getEntitiesByDef(String def) { - List list = this.cache.getEntitiesByDef(def); + List list = this.cache.loadEntitiesByDef(def); return list; } @@ -212,7 +212,7 @@ int maxResults) { List result = new ArrayList(); if (StringUtils.isNotEmpty(ow)) { - List list = this.cache.getEntitiesByDef(def); + List list = this.cache.loadEntitiesByDef(def); int count = 0; ow = NormalizerUtils.normalize(ow);