Mercurial > hg > openmind
diff src/main/java/org/mpi/openmind/cache/WrapperService.java @ 33:e52f593f9e0d
new transaction logger "openmind.transactionlog" logging entity save actions and their data.
more comments in code.
author | casties |
---|---|
date | Fri, 26 Aug 2016 11:42:41 +0200 |
parents | ac2fd7a4378d |
children | 1cd9d9a67cad |
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/cache/WrapperService.java Thu Aug 25 11:29:47 2016 +0200 +++ b/src/main/java/org/mpi/openmind/cache/WrapperService.java Fri Aug 26 11:42:41 2016 +0200 @@ -576,15 +576,15 @@ return rel; } - /* - * public Entity saveDefinition(Entity def, String user){ long start = - * System.currentTimeMillis(); def.setObjectClass(Node.TYPE_TBOX); - * def.setUser(user); + /** + * Save the given entity as a separate new entity with a new ID. + * + * Keeps attributes and relations as copies. * - * boolean b = this.searchServ.saveEntity(def); - * this.cache.saveDefinition(def); - * logger.info("saveEntityAsNew - execution time[ms]: " + - * (System.currentTimeMillis() - start)); return (Entity)def.clone(); } + * @param entity + * @param user + * @return + * @throws Exception */ public Entity saveEntityAsNew(Entity entity, String user) throws Exception { long start = System.currentTimeMillis(); @@ -647,6 +647,15 @@ } + /** + * Returns if this entity has wrong relations. + * + * Wrong are source relations whose target doesn't exist. + * Similarly for target relations. + * + * @param ent + * @return + */ private boolean hasWrongRelations(Entity ent) { for (Relation srcRel : ent.getSourceRelations()) { if (getEntityById(srcRel.getTargetId()) == null) { @@ -662,28 +671,33 @@ return false; } - private Entity removeWrongRelations(Entity ent) { - - for (Relation srcRel : new ArrayList<Relation>(ent.getSourceRelations())) { - if (srcRel.getTargetId() == null || getEntityByIdReadOnly(srcRel.getTargetId()) == null) { - ent.getSourceRelations().remove(srcRel); - logger.error( - "Inconsistency detected saving entity [" - + ent.getId() + "] " + srcRel.toString()); - } - } - - for (Relation tarRel : new ArrayList<Relation>(ent.getTargetRelations())) { - if (tarRel.getSourceId() == null || getEntityByIdReadOnly(tarRel.getSourceId()) == null) { - ent.getTargetRelations().remove(tarRel); - logger.error( - "Inconsistency detected saving entity [" - + ent.getId() + "] " + tarRel.toString()); - } - } + /** + * Remove wrong relations from this entity. + * + * Wrong are source relations whose target is null or doesn't exist. + * Similarly for target relations. + * + * @param ent + * @return + */ + private Entity removeWrongRelations(Entity ent) { - return ent; - } + for (Relation srcRel : new ArrayList<Relation>(ent.getSourceRelations())) { + if (srcRel.getTargetId() == null || getEntityByIdReadOnly(srcRel.getTargetId()) == null) { + ent.getSourceRelations().remove(srcRel); + logger.error("Inconsistency detected saving entity [" + ent.getId() + "] " + srcRel.toString()); + } + } + + for (Relation tarRel : new ArrayList<Relation>(ent.getTargetRelations())) { + if (tarRel.getSourceId() == null || getEntityByIdReadOnly(tarRel.getSourceId()) == null) { + ent.getTargetRelations().remove(tarRel); + logger.error("Inconsistency detected saving entity [" + ent.getId() + "] " + tarRel.toString()); + } + } + + return ent; + } public Attribute getDefAttributeByOwnValue(String defOC, String attOW) { for (Attribute att : this.cache.getDefAttributes(defOC)) {