# HG changeset patch # User casties # Date 1477677498 -7200 # Node ID d2833ab25c54d17199fa0c3a3469808fd0cf7068 # Parent 5bf964077567df858c29ba708197eceb19977788 better logging of entity deletion. diff -r 5bf964077567 -r d2833ab25c54 src/main/java/org/mpi/openmind/cache/WrapperService.java --- a/src/main/java/org/mpi/openmind/cache/WrapperService.java Fri Oct 28 18:20:06 2016 +0200 +++ b/src/main/java/org/mpi/openmind/cache/WrapperService.java Fri Oct 28 19:58:18 2016 +0200 @@ -139,11 +139,14 @@ } } - public void removeCurrentVersionEntity(Entity entity) throws Exception { - logger.info("removeCurrentVersionEntity " + entity); + public void removeCurrentVersionEntity(Entity entity, String user) throws Exception { + logger.info("removeCurrentVersionEntity ("+ user + ") " + entity); + txLog.debug("** START remove entity: user="+user+" entity="+entity.toSmallString()); + // delete entity from cache this.cache.deleteEntity(entity.getId(), entity.getObjectClass()); + // delete entity from DB this.getPS().removeEntCurrentVersion(entity.getId(), entity.getType()); - System.gc(); + txLog.debug("** END remove entity: user="+user+" entity="+entity.toSmallString()); } public Map searchEntityByAttributeFilter0(String term, diff -r 5bf964077567 -r d2833ab25c54 src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java --- a/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java Fri Oct 28 18:20:06 2016 +0200 +++ b/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java Fri Oct 28 19:58:18 2016 +0200 @@ -550,34 +550,35 @@ * * @param entity */ - public void removeEntCurrentVersion(Long entId, String type) - throws Exception { - logger.info("Deleting entity [ID=" + entId + ", type=" + type - + "]. But keeping history in DB."); - Session session = HibernateUtil.getSessionFactory().getCurrentSession(); - session.getTransaction().begin(); + public void removeEntCurrentVersion(Long entId, String type) throws Exception { + logger.info("Deleting entity [ID=" + entId + ", type=" + type + "]. But keeping history in DB."); + Session session = HibernateUtil.getSessionFactory().getCurrentSession(); + try { + session.getTransaction().begin(); - if (entId != null) { - //this method get the current version. Related to the relation, the time_modification is not consider, - //because it it producing problems. - List previousEntityList = - this.getEntities(session, entId, - Node.SYS_STATUS_CURRENT_VERSION, - type, null, false); - if (previousEntityList.size() > 0) { - if (previousEntityList.size() > 1) { - System.err - .println("[PersistenceService.saveEntity] found more than one current entities!"); - } - - Entity previousEntity = previousEntityList.get(0); - logger.info("Saving previous entity: " + previousEntity); - this.persistEntityAsPrevious(session, previousEntity); - } - } - session.getTransaction().commit(); - } - + if (entId != null) { + /* + * this method get the current version. Related to the relation, + * the time_modification is not consider, because it it + * producing problems. + */ + List previousEntityList = this.getEntities(session, entId, Node.SYS_STATUS_CURRENT_VERSION, + type, null, false); + if (previousEntityList.size() > 0) { + if (previousEntityList.size() > 1) { + logger.error("Found more than one current entities!"); + } + Entity previousEntity = previousEntityList.get(0); + logger.info("Saving previous entity: " + previousEntity); + this.persistEntityAsPrevious(session, previousEntity); + } + } + } catch (Exception e) { + logger.error(e); + } finally { + session.getTransaction().commit(); + } + } /** * Save the entity to the database. @@ -612,7 +613,7 @@ List previousEntityList = this.getEntities(session, entity.getId(), Node.SYS_STATUS_CURRENT_VERSION, entity.getType(), null, false); if (previousEntityList.size() > 0) { if (previousEntityList.size() > 1) { - logger.error("[PersistenceService.saveEntity] found more than one current entities!"); + logger.error("Found more than one current entities!"); } // set the first current entity as previous Entity previousEntity = previousEntityList.get(0); diff -r 5bf964077567 -r d2833ab25c54 src/main/java/org/mpi/openmind/scripts/recovery/DomXmlRecovery.java --- a/src/main/java/org/mpi/openmind/scripts/recovery/DomXmlRecovery.java Fri Oct 28 18:20:06 2016 +0200 +++ b/src/main/java/org/mpi/openmind/scripts/recovery/DomXmlRecovery.java Fri Oct 28 19:58:18 2016 +0200 @@ -44,7 +44,7 @@ if(!cache.existEnt(dbEnt.getId())){ print("this must be removed from DB=" + dbEnt); try { - ws.removeCurrentVersionEntity(dbEnt); + ws.removeCurrentVersionEntity(dbEnt, "DomXmlRecovery"); } catch (Exception e) { e.printStackTrace(); }