Mercurial > hg > openmind
comparison src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java @ 57:e08f3dd127a5
cleanup of new methods.
author | casties |
---|---|
date | Thu, 08 Dec 2016 15:39:26 +0100 |
parents | 467843399e70 |
children | 153a0232270b |
comparison
equal
deleted
inserted
replaced
56:467843399e70 | 57:e08f3dd127a5 |
---|---|
63 } | 63 } |
64 | 64 |
65 return ownValue; | 65 return ownValue; |
66 } | 66 } |
67 | 67 |
68 /** | 68 /* |
69 * Performs the actual disabling of the Hibernate second-level cache. | 69 * Performs the actual disabling of the Hibernate second-level cache. |
70 */ | 70 */ |
71 /* | 71 /* |
72 protected void disableSecondLevelCache() { | 72 protected void disableSecondLevelCache() { |
73 Map<Object, Cache> cacheRegionsMap = ((SessionFactoryImpl) HibernateUtil | 73 Map<Object, Cache> cacheRegionsMap = ((SessionFactoryImpl) HibernateUtil |
639 * @param idSequence | 639 * @param idSequence |
640 * @throws Exception | 640 * @throws Exception |
641 */ | 641 */ |
642 private void saveCurrentEntity(Session session, Entity entity, Sequence idSequence) throws Exception { | 642 private void saveCurrentEntity(Session session, Entity entity, Sequence idSequence) throws Exception { |
643 Long time = System.currentTimeMillis(); | 643 Long time = System.currentTimeMillis(); |
644 refreshEntity(session, entity); | 644 refreshEntityRelations(session, entity); |
645 entity.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION); | 645 entity.setSystemStatus(Node.SYS_STATUS_CURRENT_VERSION); |
646 entity.resetRowId(); | 646 entity.resetRowId(); |
647 entity.increaseVersion(); | 647 entity.increaseVersion(); |
648 entity.setObjectClass(entity.getObjectClass()); | 648 entity.setObjectClass(entity.getObjectClass()); |
649 entity.setModificationTime(time); | 649 entity.setModificationTime(time); |
654 this.prepareEntity(session, entity, idSequence); | 654 this.prepareEntity(session, entity, idSequence); |
655 this.persistEntity(session, entity); | 655 this.persistEntity(session, entity); |
656 } | 656 } |
657 | 657 |
658 /** | 658 /** |
659 * Updates the endpoints of the relations of this entity. | |
660 * | |
659 * This class must be called, | 661 * This class must be called, |
660 * because sometimes the current entity is related to other entities that | 662 * because sometimes the current entity is related to other entities that |
661 * have been changed in parallel to the edition of this entity. | 663 * have been changed in parallel to the edition of this entity. |
662 * For this reason, some relations of the current entity can have old information of the related entities (like the modification time). | 664 * For this reason, some relations of the current entity can have old information of the related entities (like the modification time). |
663 * This method updates the relations of the current entities getting the actual information of the related entities directly from the DB | 665 * This method updates the relations of the current entities getting the actual information of the related entities directly from the DB. |
666 * | |
667 * @author jurzua | |
668 * | |
664 * @param session | 669 * @param session |
665 * @param entity | 670 * @param entity |
666 * @throws Exception | 671 * @throws Exception |
667 */ | 672 */ |
668 private void refreshEntity(Session session, Entity entity) throws Exception{ | 673 private void refreshEntityRelations(Session session, Entity entity) throws Exception { |
669 for(Relation rel : entity.getSourceRelations()){ | 674 for(Relation rel : entity.getSourceRelations()){ |
670 refreshTarget(session, rel); | 675 refreshRelationTarget(session, rel); |
671 } | 676 } |
672 | 677 |
673 for(Relation rel : entity.getTargetRelations()){ | 678 for(Relation rel : entity.getTargetRelations()){ |
674 refreshSource(session, rel); | 679 refreshRelationSource(session, rel); |
675 } | 680 } |
676 } | 681 } |
677 | 682 |
678 private void refreshTarget(Session session, Relation rel) throws Exception{ | 683 /** |
684 * Update the target of the relation. | |
685 * | |
686 * @author jurzua | |
687 * | |
688 * @param session | |
689 * @param rel | |
690 * @throws Exception | |
691 */ | |
692 private void refreshRelationTarget(Session session, Relation rel) throws Exception { | |
679 long targetModifOld = rel.getTargetModif(); | 693 long targetModifOld = rel.getTargetModif(); |
680 StringBuilder sb = new StringBuilder("refreshTarget\n" + rel.toString() + "\n"); | 694 StringBuilder sb = new StringBuilder("refreshTarget\n" + rel.toString() + "\n"); |
681 sb.append(rel.printTarget() + "\n"); | 695 sb.append(rel.printTarget() + "\n"); |
682 List<Entity> entityList = this.getEntities(session, rel.getTargetId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); | 696 List<Entity> entityList = this.getEntities(session, rel.getTargetId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); |
683 if(entityList.isEmpty()){ | 697 if(entityList.isEmpty()){ |
684 throw new Exception("Saving entity " + rel.getSourceId() + ", the system found a relation without target. " + rel.toString()); | 698 throw new Exception("Saving entity " + rel.getSourceId() + ", the system found a relation without target. " + rel.toString()); |
685 } | 699 } |
686 Entity target = entityList.get(0); | 700 Entity target = entityList.get(0); |
687 rel.setTarget(target); | 701 rel.setTarget(target); |
688 sb.append(rel.printTarget() + "\n"); | 702 sb.append(rel.printTarget() + "\n"); |
689 // the refresh is printed in the standard output only if we detect a difference between the relation and the target entity. | 703 // the refresh is logged only if we detect a difference between the relation and the target entity. |
690 if(targetModifOld != rel.getTargetModif()){ | 704 if(targetModifOld != rel.getTargetModif()){ |
691 logger.info(sb.toString()); | 705 logger.warn(sb.toString()); |
692 } | 706 } |
693 } | 707 } |
694 | 708 |
695 private void refreshSource(Session session, Relation rel) throws Exception{ | 709 /** |
710 * Update the source of the relation. | |
711 * | |
712 * @author jurzua | |
713 * | |
714 * @param session | |
715 * @param rel | |
716 * @throws Exception | |
717 */ | |
718 private void refreshRelationSource(Session session, Relation rel) throws Exception { | |
696 long sourceModifOld = rel.getSourceModif(); | 719 long sourceModifOld = rel.getSourceModif(); |
697 StringBuilder sb = new StringBuilder("refreshSource\n" + rel.toString() + "\n"); | 720 StringBuilder sb = new StringBuilder("refreshSource\n" + rel.toString() + "\n"); |
698 sb.append(rel.printSource() + "\n"); | 721 sb.append(rel.printSource() + "\n"); |
699 List<Entity> entityList = this.getEntities(session, rel.getSourceId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); | 722 List<Entity> entityList = this.getEntities(session, rel.getSourceId(), Node.SYS_STATUS_CURRENT_VERSION, rel.getType(), null, false); |
700 if(entityList.isEmpty()){ | 723 if(entityList.isEmpty()){ |
701 throw new Exception("Saving entity " + rel.getTargetId() + ", the system found a relation without source. " + rel.toString()); | 724 throw new Exception("Saving entity " + rel.getTargetId() + ", the system found a relation without source. " + rel.toString()); |
702 } | 725 } |
703 Entity source = entityList.get(0); | 726 Entity source = entityList.get(0); |
704 rel.setSource(source); | 727 rel.setSource(source); |
705 sb.append(rel.printSource() + "\n"); | 728 sb.append(rel.printSource() + "\n"); |
706 // the refresh is printed in the standard output only if we detect a difference between the relation and the source entity. | 729 // the refresh is logged only if we detect a difference between the relation and the source entity. |
707 if(sourceModifOld != rel.getSourceModif()){ | 730 if(sourceModifOld != rel.getSourceModif()){ |
708 logger.info(sb.toString()); | 731 logger.warn(sb.toString()); |
709 } | 732 } |
710 } | 733 } |
711 | 734 |
712 /** | 735 /** |
713 * Update the entity to prepare it for persistence using the session. | 736 * Update the entity to prepare it for persistence using the session. |