List of usage examples for org.hibernate Transaction setTimeout
void setTimeout(int seconds);
From source file:com.trifork.stamdata.persistence.PersistenceFilter.java
License:Mozilla Public License
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Each request is wrapped in a transaction. Session session = null;//from ww w .j a v a 2s . co m Transaction transaction = null; try { session = sessionProvider.get(); session.beginTransaction(); transaction = session.beginTransaction(); transaction.setTimeout(5); chain.doFilter(request, response); session.getTransaction().commit(); } catch (Exception e) { try { if (transaction != null) { transaction.rollback(); } } catch (Exception ex) { ex.printStackTrace(); } // Let other filters handle the exception. throw new ServletException(e); } finally { } }
From source file:com.trifork.stamdata.persistence.StatelessPersistenceFilter.java
License:Mozilla Public License
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { StatelessSession session = null;//from w w w. ja va2s. com try { session = sessionProvider.get(); session.beginTransaction(); Transaction transaction = session.beginTransaction(); transaction.setTimeout(5); chain.doFilter(request, response); session.getTransaction().commit(); } catch (Exception e) { try { session.getTransaction().rollback(); } catch (Exception ex) { } throw new ServletException(e); } }
From source file:core.db.impl.BankConditionDaoImpl.java
/** * zmaze Podmienku pre Banku z databazy * @param bankCondition objekt BankCondition na zmazanie * @see BankCondition//from w w w. java2s.co m */ @Override public void deleteBankCondition(BankCondition bankCondition) { Transaction tx = null; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); tx.setTimeout(5); session.delete(bankCondition); tx.commit(); } catch (RuntimeException e) { try { tx.rollback(); } catch (RuntimeException rbe) { } throw e; } finally { if (session != null) { session.close(); } } }
From source file:core.db.impl.BankDaoImpl.java
/** * maze banku z databazy/*w w w .j a v a 2s . c o m*/ * @param bank objekt Bank, ktory bude zmazany * @see Bank */ @Override public void deleteBank(Bank bank) { Transaction tx = null; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); tx.setTimeout(5); session.delete(bank); tx.commit(); } catch (RuntimeException e) { try { tx.rollback(); } catch (RuntimeException rbe) { } throw e; } finally { if (session != null) { session.close(); } } }
From source file:core.db.impl.ConditionDaoImpl.java
/** * zmaze podmienku z databazy//from w w w . ja v a 2 s . co m * * @param condition objekt Condition ktory ma byt zmazany z databazy * @see Condition */ @Override public void deleteCondition(Condition condition) { Transaction tx = null; Session session = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); tx.setTimeout(5); session.delete(condition); tx.commit(); } catch (RuntimeException e) { try { tx.rollback(); } catch (RuntimeException rbe) { } throw e; } finally { if (session != null) { session.close(); } } }
From source file:dao.FacultyDAO.java
@Override public Faculty getFaculty(Integer idFaculty) { Faculty obj;/*ww w. j a v a 2s . co m*/ Session sess = sessionFactory.openSession(); Transaction tx = sess.getTransaction(); try { //set transaction timeout to 3 seconds tx.setTimeout(3); tx.begin(); obj = (Faculty) sess.get(Faculty.class, idFaculty); tx.commit(); } catch (Exception e) { tx.rollback(); throw e; // or display error message } finally { sess.close(); } return obj; }
From source file:dao.FacultyDAO.java
@Override public Faculty getAdviser() { Faculty o;//from w ww .ja v a2 s .co m Session sess = sessionFactory.openSession(); Transaction tx = sess.getTransaction(); try { //set transaction timeout to 3 seconds tx.setTimeout(3); tx.begin(); String sql = "Select f, count(c.idCustomer) as cnt from " + "Faculty f left join f.customerList c group by f.idFaculty order by cnt ASC"; Query sqlQuery = sess.createQuery(sql); List<Object[]> fList = sqlQuery.list(); if (fList.size()==0) return null; o = (Faculty) fList.get(0)[0]; tx.commit(); } catch (Exception e) { tx.rollback(); throw e; // or display error message } finally { sess.close(); } return o; }
From source file:dao.FacultyDAO.java
@Override public List<Customer> getFacultyCustomer(Faculty faculty) { List<Customer> obj;//from w w w . j a va 2s. c om Session sess = sessionFactory.openSession(); Transaction tx = sess.getTransaction(); try { //set transaction timeout to 3 seconds tx.setTimeout(3); tx.begin(); Query query = sess.createQuery("FROM Customer where advisor = :fa"); query.setEntity("fa", faculty); obj = query.list(); tx.commit(); } catch (Exception e) { tx.rollback(); throw e; // or display error message } finally { sess.close(); } return obj; }
From source file:dao.FacultyDAO.java
@Override public List<Section> getSections(Faculty faculty) { List<Section> obj;//from w w w . ja v a 2 s .c om Session sess = sessionFactory.openSession(); Transaction tx = sess.getTransaction(); try { //set transaction timeout to 3 seconds tx.setTimeout(3); tx.begin(); Query query = sess.createQuery("FROM Section where faculty =:fa"); query.setEntity("fa", faculty); obj = query.list(); tx.commit(); } catch (Exception e) { tx.rollback(); throw e; // or display error message } finally { sess.close(); } return obj; }
From source file:dao.FacultyDAO.java
@Override public void addFaculty(Faculty faculty) { Session sess = sessionFactory.openSession(); Transaction tx = sess.getTransaction(); try {/*from ww w.j ava 2 s . co m*/ //set transaction timeout to 3 seconds tx.setTimeout(3); tx.begin(); sess.save(faculty); tx.commit(); } catch (Exception e) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, e); tx.rollback(); throw e; // or display error message } finally { sess.close(); } }