List of usage examples for org.hibernate.internal StatelessSessionImpl isClosed
@Override public boolean isClosed()
From source file:debop4k.data.orm.hibernate.StatelessEx.java
License:Apache License
public static <T> T withTransaction(@NonNull SessionFactory factory, @NonNull final Function1<StatelessSessionImpl, T> func) { StatelessSessionImpl stateless = of(factory); try {// ww w. jav a 2 s .co m Transaction tx = stateless.beginTransaction(); try { T result = func.invoke(stateless); tx.commit(); return result; } catch (HibernateException e) { log.error("Hibernate StatelessSession ? ?.", e); tx.rollback(); return null; } } finally { if (stateless != null && !stateless.isClosed()) stateless.close(); } }
From source file:debop4k.data.orm.hibernate.StatelessEx.java
License:Apache License
/** * DB? ? ? ./*from www. ja v a2 s.c om*/ * * @param factory hibernate session factory * @param func ? * @param <T> ?? ? * @return ?? * @deprecated {@literal @}Transactional(readOnly=true) . */ @Deprecated @Transactional(readOnly = true) public static <T> T withReadOnly(@NonNull SessionFactory factory, @NonNull Function1<StatelessSessionImpl, T> func) { StatelessSessionImpl stateless = of(factory); try { Connection conn = stateless.connection(); conn.setReadOnly(true); conn.setAutoCommit(false); Transaction tx = stateless.beginTransaction(); try { T result = func.invoke(stateless); tx.commit(); return result; } catch (Exception e) { log.error("Hibernate StatelessSession ? ?.", e); tx.rollback(); return null; } } catch (SQLException e) { log.error("Connection ? ? ?.", e); throw new RuntimeException(e); } finally { if (stateless != null && !stateless.isClosed()) stateless.close(); } }