Mercurial > hg > LGServices
comparison src/main/java/de/mpiwg/gazetteer/utils/DBService.java @ 41:ba9515f22897
new: topic management and adding sections from searching result into topic
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Thu, 17 Dec 2015 13:44:08 +0100 |
parents | 35ed4e650a53 |
children | 9dbbbfd474f4 |
comparison
equal
deleted
inserted
replaced
40:35ed4e650a53 | 41:ba9515f22897 |
---|---|
18 | 18 |
19 import de.mpiwg.gazetteer.bo.DBEntry; | 19 import de.mpiwg.gazetteer.bo.DBEntry; |
20 import de.mpiwg.gazetteer.bo.LGBranch; | 20 import de.mpiwg.gazetteer.bo.LGBranch; |
21 import de.mpiwg.gazetteer.bo.LGFile; | 21 import de.mpiwg.gazetteer.bo.LGFile; |
22 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; | 22 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile; |
23 import de.mpiwg.gazetteer.bo.LGTopic; | |
24 import de.mpiwg.gazetteer.bo.LGTopicSectionRelation; | |
23 import de.mpiwg.gazetteer.db.DBBook; | 25 import de.mpiwg.gazetteer.db.DBBook; |
24 import de.mpiwg.gazetteer.db.DBContents; | 26 import de.mpiwg.gazetteer.db.DBContents; |
25 import de.mpiwg.gazetteer.db.DBCoordinatesBook; | 27 import de.mpiwg.gazetteer.db.DBCoordinatesBook; |
26 import de.mpiwg.gazetteer.db.DBSection; | 28 import de.mpiwg.gazetteer.db.DBSection; |
27 import de.mpiwg.gazetteer.db.DBSectionVersion; | 29 import de.mpiwg.gazetteer.db.DBSectionVersion; |
86 | 88 |
87 public List<DBBook> getBooks(){ | 89 public List<DBBook> getBooks(){ |
88 try { | 90 try { |
89 this.loadBookMap(); | 91 this.loadBookMap(); |
90 } catch (SQLException e) { | 92 } catch (SQLException e) { |
91 // TODO Auto-generated catch block | 93 |
92 e.printStackTrace(); | 94 e.printStackTrace(); |
93 } | 95 } |
94 | 96 |
95 // getBookMap().values() returns a Collection. In this way, we can use List. | 97 // getBookMap().values() returns a Collection. In this way, we can use List. |
96 return new ArrayList<DBBook>(getBookMap().values()); | 98 return new ArrayList<DBBook>(getBookMap().values()); |
787 session.getTransaction().commit(); | 789 session.getTransaction().commit(); |
788 | 790 |
789 return list; | 791 return list; |
790 } | 792 } |
791 | 793 |
792 protected static List<LGBranch> getAllLGBranchFromDB(){ | 794 |
795 | |
796 protected static List<LGBranch> getAllLGBranchFromDB(){ | |
793 List<LGBranch> list = null; | 797 List<LGBranch> list = null; |
794 | 798 |
795 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); | 799 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
796 session.getTransaction().begin(); | 800 session.getTransaction().begin(); |
797 Query query = session.createQuery("from LGBranch"); | 801 Query query = session.createQuery("from LGBranch"); |
930 return null; | 934 return null; |
931 } | 935 } |
932 | 936 |
933 } | 937 } |
934 */ | 938 */ |
939 | |
940 | |
941 | |
942 | |
943 /* --- topic --- */ | |
944 protected static List<LGTopic> getAllLGTopicFromDB(){ | |
945 List<LGTopic> list = null; | |
946 | |
947 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); | |
948 session.getTransaction().begin(); | |
949 Query query = session.createQuery("from LGTopic"); | |
950 list = query.list(); | |
951 session.getTransaction().commit(); | |
952 | |
953 return list; | |
954 } | |
955 | |
956 protected static int deleteTopicFromDB(Long topicId){ | |
957 logger.info("Deleting topic by topicId=" + topicId); | |
958 | |
959 int modifiedTopic; | |
960 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); | |
961 session.getTransaction().begin(); | |
962 | |
963 Query query = session.createQuery("delete LGTopic where id = :id"); | |
964 query.setLong("id", topicId); | |
965 modifiedTopic = query.executeUpdate(); | |
966 | |
967 | |
968 // delete records in TopicSectionRelation table | |
969 Query query0 = session.createQuery("delete LGTopicSectionRelation where topicId = :topicId"); | |
970 query0.setLong("topicId", topicId); | |
971 modifiedTopic += query0.executeUpdate(); | |
972 | |
973 session.getTransaction().commit(); | |
974 | |
975 return modifiedTopic; | |
976 } | |
977 | |
978 | |
979 protected static List<LGTopicSectionRelation> getAllLGTopicSectionRelationFromDB(){ | |
980 List<LGTopicSectionRelation> list = null; | |
981 | |
982 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); | |
983 session.getTransaction().begin(); | |
984 Query query = session.createQuery("from LGTopicSectionRelation"); | |
985 list = query.list(); | |
986 session.getTransaction().commit(); | |
987 | |
988 return list; | |
989 } | |
990 | |
991 protected static int deleteTopicSectionRelationFromDB(Long relationId){ | |
992 | |
993 int modifiedRelation; | |
994 Session session = HibernateUtil.getSessionFactory().getCurrentSession(); | |
995 session.getTransaction().begin(); | |
996 | |
997 | |
998 Query query0 = session.createQuery("delete LGTopicSectionRelation where id = :relationId"); | |
999 query0.setLong("relationId", relationId); | |
1000 modifiedRelation = query0.executeUpdate(); | |
1001 | |
1002 session.getTransaction().commit(); | |
1003 | |
1004 return modifiedRelation; | |
1005 | |
1006 } | |
1007 | |
1008 | |
1009 | |
1010 | |
1011 /* --- end topic --- */ | |
1012 | |
1013 | |
1014 | |
935 } | 1015 } |