List of usage examples for org.hibernate SessionFactory getCurrentSession
Session getCurrentSession() throws HibernateException;
From source file:smile.weixin.jdquanyi.database.Database.java
public boolean updateFX_count(String fromUsername) { SessionFactory sf = new AnnotationConfiguration().configure().buildSessionFactory(); Session s = sf.getCurrentSession(); s.beginTransaction();/*from w w w . j a va2 s .c o m*/ Query q = s.createQuery("from FX_FuXiu"); List<FX_FuXiu> fx_list = q.list(); for (FX_FuXiu fx : fx_list) { if (fx.getFx_fromUserName().equals(fromUsername)) { if (0 == fx.getFx_flag()) { fx.setFx_count(fx.getFx_count() + 1); fx.setFx_flag(1); s.save(fx); s.getTransaction().commit(); } break; } } s.close(); return true; }
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(); s.beginTransaction();/*from w w w. jav a2s . c om*/ 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(); s.beginTransaction();/*from w w w.j a v a2 s . c o m*/ 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(); s.beginTransaction();//from w w w. ja va2 s.com 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(); try {//w ww. j av a 2 s .c o m 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 va 2 s. c om*/ * * */ 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(); s.beginTransaction();/*from w ww . j a v a2s . c o m*/ 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:tempapp.TempApp.java
/** * @param args the command line arguments *///from www.jav a 2 s . c om public static void main(String[] args) { Random rnd = new Random(); //--- Configuration cnf = new Configuration(); cnf.configure(); ServiceRegistry srv = new StandardServiceRegistryBuilder().applySettings(cnf.getProperties()).build(); ; SessionFactory sfac = cnf.buildSessionFactory(srv); //--- //Session sf = DAOclass.getSessionFactory().getCurrentSession(); for (int i = 0; i < 10; i++) { Session sf = sfac.getCurrentSession(); sf.beginTransaction(); User usr = new User(); usr.setLogin(Integer.toString(i)); usr.setEmail("nikita.brazhnik@gmail.com"); usr.setLoginType("1"); usr.setName(Long.toString(rnd.nextLong())); sf.save(usr); sf.getTransaction().commit(); } }
From source file:tools.xor.util.Hibernate4Support.java
License:Apache License
@Override public Session getCurrentSession(SessionFactory sessionFactory) { return sessionFactory.getCurrentSession(); }
From source file:ubic.gemma.persistence.util.EntityUtils.java
License:Apache License
/** * Populates parameters in query created using addGroupAndUserNameRestriction(boolean, boolean). * * @param queryObject the query object created using the sql query with group and username restrictions. * @param sessionFactory session factory from the DAO that is using this method. *///from w w w . j a v a 2s. c om public static void addUserAndGroupParameters(SQLQuery queryObject, SessionFactory sessionFactory) { if (SecurityUtil.isUserAnonymous()) { return; } String sqlQuery = queryObject.getQueryString(); String userName = SecurityUtil.getCurrentUsername(); // if user is member of any groups. if (sqlQuery.contains(":groups")) { //noinspection unchecked Collection<String> groups = sessionFactory.getCurrentSession().createQuery( "select ug.name from UserGroup ug inner join ug.groupMembers memb where memb.userName = :user") .setParameter("user", userName).list(); queryObject.setParameterList("groups", groups); } if (sqlQuery.contains(":userName")) { queryObject.setParameter("userName", userName); } }