List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:smile.weixin.jdquanyi.database.Database.java
public List<SW_ShiWu> GetShiWuInfs() { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();// ww w .j a v a 2 s. c om s.beginTransaction(); Query q = s.createQuery("from SW_ShiWu"); List<SW_ShiWu> sw = q.list(); s.getTransaction().commit(); sf.close(); //System.out.println("Query OK!"); return sw; }
From source file:smile.weixin.jdquanyi.database.Database.java
public int getGYS_Id(String fromUserName) { int id = 0;// w ww . j a v a2 s .c o m SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession(); s.beginTransaction(); Query q = s.createQuery("from GYS_GongYiSan"); List<GYS_GongYiSan> gys_list = q.list(); s.getTransaction().commit(); sf.close(); for (GYS_GongYiSan gys : gys_list) { if (gys.getGYS_fromUserName().equals(fromUserName)) { id = gys.getGYS_id(); break; // System.out.println(id); } } return id; }
From source file:smile.weixin.jdquanyi.database.Database.java
public int getWC_count() { int weekcount = -1; SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();/*from ww w.j a v a 2 s .co m*/ s.beginTransaction(); Query q = s.createQuery("from WC_WeekCount"); List<WC_WeekCount> wc_list = q.list(); sf.close(); for (WC_WeekCount wc : wc_list) { if (1 == wc.getId()) { weekcount = wc.getCount(); break; } } return weekcount; }
From source file:smile.weixin.jdquanyi.database.Database.java
public boolean updatePure(String fromUserName, boolean change) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();/*from w w w. j a va2 s . c o m*/ s.beginTransaction(); GYS_GongYiSan gys = (GYS_GongYiSan) s.get(GYS_GongYiSan.class, getGYS_Id(fromUserName)); gys.setGYS_pure(change); s.save(gys); s.getTransaction().commit(); sf.close(); return true; }
From source file:smile.weixin.jdquanyi.database.Database.java
public boolean updateTelephone(String fromUserName, String telephone) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();/*from ww w .j av a 2 s .co m*/ s.beginTransaction(); GYS_GongYiSan gys = (GYS_GongYiSan) s.get(GYS_GongYiSan.class, getGYS_Id(fromUserName)); gys.setGYS_telephone(telephone); s.save(gys); s.getTransaction().commit(); sf.close(); return true; }
From source file:smile.weixin.jdquanyi.database.Database.java
public boolean updateVerification(String fromUserName, boolean change) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();// w w w.j a v a2 s. c om s.beginTransaction(); GYS_GongYiSan gys = (GYS_GongYiSan) s.get(GYS_GongYiSan.class, getGYS_Id(fromUserName)); gys.setGYS_verification(change); s.save(gys); s.getTransaction().commit(); sf.close(); return true; }
From source file:smile.weixin.jdquanyi.database.Database.java
public boolean updateMenuClickCount(int menu_id) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();/* w w w. j a v a2s. com*/ try { s.beginTransaction(); MCC_MenuClickCount mcc = (MCC_MenuClickCount) s.get(MCC_MenuClickCount.class, menu_id); mcc.setHistory_count(mcc.getHistory_count() + 1); String date = new Date().toString(); String week = date.toString().substring(0, 3); switch (week) { case "Mon": mcc.setMonday_count(mcc.getMonday_count() + 1); break; case "Tue": mcc.setTuesday_count(mcc.getTuesday_count() + 1); break; case "Wed": mcc.setWednesday_count(mcc.getWednesday_count() + 1); break; case "Thu": mcc.setThursday_count(mcc.getThursday_count() + 1); break; case "Fri": mcc.setFriday_count(mcc.getFriday_count() + 1); break; case "Sat": mcc.setSaturday_count(mcc.getSaturday_count() + 1); break; case "Sun": mcc.setSunday_count(mcc.getSunday_count() + 1); break; default: break; } s.save(mcc); s.getTransaction().commit(); } catch (Exception e) { System.out.println(e); } finally { sf.close(); } return true; }
From source file:smile.weixin.jdquanyi.database.Database.java
/*********************************************************/ /*/*from www . j a v a 2 s. c o m*/ * * */ public boolean AddQuestion(MQ_MyQuestions question) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession(); s.beginTransaction(); s.save(question); // int id = question.getId(); s.getTransaction().commit(); sf.close(); return true; }
From source file:smile.weixin.jdquanyi.database.Database.java
public List<MQ_MyQuestions> GetMyQuestions(String fromUserName) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession();/*from w w w . j a v a 2s . c o m*/ s.beginTransaction(); Query q = s.createQuery("from MQ_MyQuestions"); List<MQ_MyQuestions> mq_list = q.list(); s.getTransaction().commit(); sf.close(); List<MQ_MyQuestions> result = new ArrayList<MQ_MyQuestions>(); for (MQ_MyQuestions mq : mq_list) { if (mq.getFromUserName().equals(fromUserName)) { result.add(mq); } } return result; }
From source file:staff.dao.impl.DeptDaoImpl.java
@Override public List<Dept> getDepts() throws SQLException { List<Dept> depts = null; Session session = null;/* w ww .j a v a 2s . c om*/ SessionFactory sessionFactory = null; try { sessionFactory = HibernateUtil.getSessionFactory(); session = sessionFactory.openSession(); depts = session.createCriteria(Dept.class).list(); } catch (Exception e) { e.printStackTrace(); } finally { if (session.isOpen()) { session.close(); sessionFactory.close(); System.out.println("close getDeps"); } } return depts; }