Mercurial > hg > openmind
changeset 51:d2833ab25c54
better logging of entity deletion.
author | casties |
---|---|
date | Fri, 28 Oct 2016 19:58:18 +0200 |
parents | 5bf964077567 |
children | 5b2a97d417d5 |
files | src/main/java/org/mpi/openmind/cache/WrapperService.java src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java src/main/java/org/mpi/openmind/scripts/recovery/DomXmlRecovery.java |
diffstat | 3 files changed, 36 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- 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<Entity, Attribute> searchEntityByAttributeFilter0(String term,
--- 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<Entity> 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<Entity> 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<Entity> 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);
--- 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(); }