diff 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
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/gazetteer/utils/DBService.java	Mon Dec 07 17:06:57 2015 +0100
+++ b/src/main/java/de/mpiwg/gazetteer/utils/DBService.java	Thu Dec 17 13:44:08 2015 +0100
@@ -20,6 +20,8 @@
 import de.mpiwg.gazetteer.bo.LGBranch;
 import de.mpiwg.gazetteer.bo.LGFile;
 import de.mpiwg.gazetteer.bo.LGFullTextSearchFile;
+import de.mpiwg.gazetteer.bo.LGTopic;
+import de.mpiwg.gazetteer.bo.LGTopicSectionRelation;
 import de.mpiwg.gazetteer.db.DBBook;
 import de.mpiwg.gazetteer.db.DBContents;
 import de.mpiwg.gazetteer.db.DBCoordinatesBook;
@@ -88,7 +90,7 @@
 		try {
 			this.loadBookMap();
 		} catch (SQLException e) {
-			// TODO Auto-generated catch block
+			
 			e.printStackTrace();
 		}
 		
@@ -789,7 +791,9 @@
 		return list;
 	}
 	
-	protected static  List<LGBranch> getAllLGBranchFromDB(){
+	
+	
+	protected static List<LGBranch> getAllLGBranchFromDB(){
 		List<LGBranch> list = null;
 		
 		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
@@ -932,4 +936,80 @@
 				
 	}
 	 */
+	
+	
+	
+
+	/* --- topic --- */
+	protected static List<LGTopic> getAllLGTopicFromDB(){
+		List<LGTopic> list = null;
+		
+		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+		session.getTransaction().begin();
+		Query query = session.createQuery("from LGTopic");
+		list = query.list();
+		session.getTransaction().commit();
+
+		return list;
+	}
+	
+	protected static int deleteTopicFromDB(Long topicId){
+		logger.info("Deleting topic by topicId=" + topicId);
+		
+		int modifiedTopic;
+		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+		session.getTransaction().begin();
+		
+		Query query = session.createQuery("delete LGTopic where id = :id");
+		query.setLong("id", topicId);
+		modifiedTopic = query.executeUpdate();
+		
+		
+		// delete records in TopicSectionRelation table
+		Query query0 = session.createQuery("delete LGTopicSectionRelation where topicId = :topicId");
+		query0.setLong("topicId", topicId);
+		modifiedTopic += query0.executeUpdate();
+		
+		session.getTransaction().commit();
+		
+		return modifiedTopic;
+	}
+	
+	
+	protected static List<LGTopicSectionRelation> getAllLGTopicSectionRelationFromDB(){
+		List<LGTopicSectionRelation> list = null;
+		
+		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+		session.getTransaction().begin();
+		Query query = session.createQuery("from LGTopicSectionRelation");
+		list = query.list();
+		session.getTransaction().commit();
+
+		return list;
+	}
+	
+	protected static int deleteTopicSectionRelationFromDB(Long relationId){
+		
+		int modifiedRelation;
+		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
+		session.getTransaction().begin();
+		
+		
+		Query query0 = session.createQuery("delete LGTopicSectionRelation where id = :relationId");
+		query0.setLong("relationId", relationId);
+		modifiedRelation = query0.executeUpdate();
+		
+		session.getTransaction().commit();
+		
+		return modifiedRelation;
+		
+	}
+
+	
+	
+	
+	/* --- end topic --- */
+
+	
+	
 }