Mercurial > hg > openmind
diff src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java @ 51:d2833ab25c54
better logging of entity deletion.
author | casties |
---|---|
date | Fri, 28 Oct 2016 19:58:18 +0200 |
parents | c181cb6f1761 |
children | 467843399e70 |
line wrap: on
line diff
--- 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);