Mercurial > hg > openmind
changeset 37:3485498af8c3
small comments and refactoring.
author | casties |
---|---|
date | Wed, 12 Oct 2016 15:33:56 +0200 |
parents | 63fe33172397 |
children | cb25e343e317 |
files | src/main/java/org/mpi/openmind/cache/AbstractCacheService.java src/main/java/org/mpi/openmind/cache/CacheService.java src/main/java/org/mpi/openmind/cache/WrapperService.java |
diffstat | 3 files changed, 24 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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<Entity> 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<Entity> getEntitiesByDef(String oc){ + /** + * Load all entities of the given object class into the cache. + * + * @param oc + * @return + */ + public List<Entity> 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() +
--- 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(); }
--- 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<Entity> entList = this.cache.getEntitiesByDef(oc); + List<Entity> entList = this.cache.loadEntitiesByDef(oc); term = NormalizerUtils.normalize(term); for(Entity ent : entList){ @@ -204,7 +204,7 @@ } public List<Entity> getEntitiesByDef(String def) { - List<Entity> list = this.cache.getEntitiesByDef(def); + List<Entity> list = this.cache.loadEntitiesByDef(def); return list; } @@ -212,7 +212,7 @@ int maxResults) { List<Entity> result = new ArrayList<Entity>(); if (StringUtils.isNotEmpty(ow)) { - List<Entity> list = this.cache.getEntitiesByDef(def); + List<Entity> list = this.cache.loadEntitiesByDef(def); int count = 0; ow = NormalizerUtils.normalize(ow);