下面列出了org.hibernate.Transaction#getStatus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
Session hibSes = ses.attach(null);
if (hibSes != null) {
try {
Transaction tx = hibSes.getTransaction();
if (commit) {
if (hibSes.isDirty())
hibSes.flush();
if (tx.getStatus() == TransactionStatus.ACTIVE)
tx.commit();
}
else if (tx.getStatus().canRollback())
tx.rollback();
}
catch (HibernateException e) {
throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
}
finally {
hibSes.close();
}
}
}
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();
Session s = store.session(null);
if (s == null)
return;
try {
s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
.setFlushMode(FlushMode.ALWAYS).executeUpdate();
Transaction hTx = s.getTransaction();
if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
hTx.commit();
}
finally {
s.close();
}
}
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
Session hibSes = ses.attach(null);
if (hibSes != null) {
try {
Transaction tx = hibSes.getTransaction();
if (commit) {
if (hibSes.isDirty())
hibSes.flush();
if (tx.getStatus() == TransactionStatus.ACTIVE)
tx.commit();
}
else if (tx.getStatus().canRollback())
tx.rollback();
}
catch (HibernateException e) {
throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
}
finally {
hibSes.close();
}
}
}
/** {@inheritDoc} */
@Override protected void afterTest() throws Exception {
super.afterTest();
Session s = store.session(null);
if (s == null)
return;
try {
s.createQuery("delete from " + CacheHibernateBlobStoreEntry.class.getSimpleName())
.setFlushMode(FlushMode.ALWAYS).executeUpdate();
Transaction hTx = s.getTransaction();
if (hTx != null && hTx.getStatus() == TransactionStatus.ACTIVE)
hTx.commit();
}
finally {
s.close();
}
}