public ActivityPartnerRequest getPartnerRequest(User user, Activity activity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from ActivityPartnerRequest as partnerrequest " + "where partnerrequest.idactivity=" + activity.getIdactivity() + " and partnerrequest.iduser=" + user.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { return (ActivityPartnerRequest) result.get(0); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return null; }
public void savePartnerRequest(ActivityPartnerRequest activityPartnerRequest) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from ActivityPartnerRequest as partnerrequest " + "where partnerrequest.idactivity=" + activityPartnerRequest.getIdactivity() + " and partnerrequest.iduser=" + activityPartnerRequest.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { Session session1 = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction1 = session1.beginTransaction(); for (Object o : result) { session1.delete(o); } transaction1.commit(); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } saveObject(activityPartnerRequest); }
public User getUser(String username) { User result = null; Session session; Object user; session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = null; user = null; try { transaction = session.beginTransaction(); Query query = session.createQuery("from User as user where user.userName='******'"); user = query.uniqueResult(); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } if (user != null) { result = (User) user; } } finally { if (session.isOpen()) { if (session.isOpen()) { session.disconnect(); session.close(); } } } return result; }
public void saveEvent(Event event) { Event event1 = getEvent(event); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { if (event1 == null) { Transaction transaction = session.beginTransaction(); try { session.save(event); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } } else { Transaction transaction = session.beginTransaction(); try { session.update(event); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } }
public List<Activity> getActivities(Event parent) { List<Activity> result = new ArrayList<Activity>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object event = session .createQuery("from Event as event where event.idevent= " + parent.getIdevent()) .uniqueResult(); transaction.commit(); if (event != null) { Event eventEntity = (Event) event; Collection<Activity> activityList = eventEntity.getActivities(); for (Activity activity : activityList) { result.add(activity); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public void saveEventPassesRequest(EventNumberOfPassesRequest eventNumberOfPassesRequest) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from EventNumberOfPassesRequest as eventNumberOfPassesRequest " + "where eventNumberOfPassesRequest.idevent=" + eventNumberOfPassesRequest.getIdevent() + " and eventNumberOfPassesRequest.iduser=" + eventNumberOfPassesRequest.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { Session session1 = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction1 = session1.beginTransaction(); for (Object o : result) { session1.delete(o); } transaction1.commit(); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } saveObject(eventNumberOfPassesRequest); }
@Override public void conversationPausing(Conversation conversation) { EntityManager em = conversation.getEntityManager(); if (em != null) { boolean needToReleaseConnection = false; if (unbindEntityManager(conversation.getEntityManager())) { needToReleaseConnection = true; } if (!conversation.isEntityManagerStillNeeded()) { em.close(); conversation.setEntityManager(null); if (log.isDebugEnabled()) { log.debug( "conv. " + conversation.getId() + " pausing: conversation's entityManager closed: " + em.hashCode()); } } else if (needToReleaseConnection) { // _HACK_ as we depend on Hibernate // Note: normally we should not have to do this as we have configured hibernate // with hibernate.connection.release_mode=after_transaction // But we load some lazy data non transactionnally from the view... Session session = em.unwrap(Session.class); session.disconnect(); // will be reconnected automatically as needed. } } }
public EventNumberOfPassesRequest getEventPassesRequest(User user, Event event) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List result = session .createQuery( "from EventNumberOfPassesRequest as eventNumberOfPassesRequest " + "where eventNumberOfPassesRequest.idevent=" + event.getIdevent() + " and eventNumberOfPassesRequest.iduser=" + user.getIduser()) .list(); transaction.commit(); if (result != null && result.size() > 0) { return (EventNumberOfPassesRequest) result.get(0); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return null; }
public Location getLocation(int id) { Location result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery("from Location as location where location.idlocation = " + id) .uniqueResult(); transaction.commit(); if (o != null) { if (o instanceof Location) { Location location = (Location) o; result = new Location(); result.setName(location.getName()); result.setIdlocation(location.getIdlocation()); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public ClassificationValue getClassification(String value) { ClassificationValue result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery( "from ClassificationValue as classificationValue where classificationValue.value like '" + value + "'") .uniqueResult(); transaction.commit(); if (o != null) { if (o instanceof ClassificationValue) { result = (ClassificationValue) o; } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public Location getLocation(String s) { Location result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery("from Location as location where location.name like '" + s + "'") .uniqueResult(); transaction.commit(); if (o != null) { if (o instanceof Location) { result = (Location) o; } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public static void closeSession() { if (session != null && session.isOpen()) { session.disconnect(); session.flush(); session.close(); session = null; sessionFactory.close(); isSessionOpen = false; } }
public void updateObject(Object entity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); session.update(entity); session.flush(); transaction.commit(); } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } }
public void deletePartnerRequest(ActivityPartnerRequest activityPartnerRequest) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); session.delete(activityPartnerRequest); session.flush(); transaction.commit(); } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } }
public void createNewAccount(Users users) { SessionFactory sf = null; Session session = null; sf = HibernateUtil.getSessionFactory(); session = sf.openSession(); try { Transaction tr = session.beginTransaction(); session.save(users); tr.commit(); } catch (Exception e) { } finally { session.disconnect(); } }
public void saveObject(Object entity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); session.saveOrUpdate(entity); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } }
public List<Event> getEvent(String name) { List<Event> result = new ArrayList<Event>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Event as event where event.name='" + name + "'").list(); transaction.commit(); for (Object o : list) { result.add((Event) o); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<User> getUsers() { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from User").list(); transaction.commit(); for (Object o : list) { User user = (User) o; result.add(user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
void indb() { try { int newcount = 0; // 记录下本次的新入库数量 Session session = HibernateSessionFactory.getSession(); session.beginTransaction(); DoccatalogDAO dao = new DoccatalogDAO(); String code = ""; String info = ""; int repeatcount = 0; // 如果已经入库数达到3,退出循环。 (20140122) for (int i = 0; i < v.size(); i++) { // 20140123 int i = v.size(); i > 1; i-- code = v.elementAt(i).getDoccode(); // 20140123 i-1=> i if (dao.findByDoccode(code.trim()).size() <= 0) { dao.save(v.elementAt(i)); // 20140123 i-1=> i newcount++; info = info + ";" + v.elementAt(i).getDoccaption(); // 20140123 i-1=> i } else { // System.out.print(code+"已经入库!"); repeatcount++; // System.out.print("_"+repeatcount+"_"); } if (repeatcount > 3) break; // 便于提高效率(20140122) } if (repeatcount > 3) System.out.print("3"); // 便于提高效率(20140122) session.getTransaction().commit(); session.disconnect(); // 20140122看看占不占资源; session.close(); // 20140122看看占不占资源; if (newcount != 0) { System.out.println( "\n" + "insert " + newcount + " recodes ok!" + new Timestamp(System.currentTimeMillis()).toString()); mail(info); } else { System.out.print("+"); // mail("-"); } } catch (Exception ex) { ex.printStackTrace(); } }
public List<Logo> getLogos() { List<Logo> result = new ArrayList<Logo>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Logo").list(); transaction.commit(); for (Object o : list) { Logo logo = (Logo) o; result.add(logo); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<Activity> getActivities() { List<Activity> result = new ArrayList<Activity>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Activity").list(); transaction.commit(); for (Object o : list) { Activity activity = (Activity) o; result.add(activity); } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public Event getEvent(Event event) { Event result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery("from Event as event where event.idevent= " + event.getIdevent()) .uniqueResult(); transaction.commit(); if (o != null) { result = (Event) o; } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public User getUser(User user) { User result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery("from User as user where user.iduser=" + user.getIduser()) .uniqueResult(); transaction.commit(); if (o != null) { result = (User) o; } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public Location getLocation(Location location) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery( "from Location as location where location.idlocation = " + location.getIdlocation()) .uniqueResult(); transaction.commit(); if (o != null) { return (Location) o; } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return null; }
public List<Location> getLocations() { List<Location> result = new ArrayList<Location>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from Location").list(); transaction.commit(); if (list != null) { for (Object o : list) { Location location = (Location) o; result.add(location); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public void deleteUser(User user) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); User o = (User) session .createQuery("from User as user where user.userName='******'") .uniqueResult(); transaction.commit(); if (o != null) { Session session1 = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction1 = session1.beginTransaction(); session1.delete(o); transaction1.commit(); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } }
public List<ClassificationType> getClassificationTypes() { List<ClassificationType> result = new ArrayList<ClassificationType>(); Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); List list = session.createQuery("from ClassificationType").list(); transaction.commit(); if (list != null) { for (Object o : list) { ClassificationType classificationType = (ClassificationType) o; result.add(classificationType); } } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public Activity getActivity(Activity activity) { Activity result = null; Session session = SessionFactoryUtil.getInstance().getCurrentSession(); try { Transaction transaction = session.beginTransaction(); Object o = session .createQuery( "from Activity as activity where activity.idactivity= " + activity.getIdactivity()) .uniqueResult(); transaction.commit(); if (o != null) { result = (Activity) o; } } finally { if (session.isOpen()) { session.flush(); session.disconnect(); session.close(); } } return result; }
public List<User> getUserForActivity(Activity activity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); String queryString = "select user from User as user where " + activity.getIdactivity() + " in elements (user.activities)"; List users = session.createQuery(queryString).list(); transaction.commit(); for (Object user : users) { result.add((User) user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }
public List<User> getUserForEvent(Event selectedEvent) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); List<User> result = new ArrayList<User>(); try { Transaction transaction = session.beginTransaction(); String queryString = "select user from User as user where " + selectedEvent.getIdevent() + " in elements (user.events) order by user.firstname"; List users = session.createQuery(queryString).list(); transaction.commit(); for (Object user : users) { result.add((User) user); } } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } return result; }