use of org.hibernate.Session in project hibernate-orm by hibernate.
the class BaseCoreFunctionalTestCase method readCommittedIsolationMaintained.
protected boolean readCommittedIsolationMaintained(String scenario) {
int isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
Session testSession = null;
try {
testSession = openSession();
isolation = testSession.doReturningWork(new AbstractReturningWork<Integer>() {
@Override
public Integer execute(Connection connection) throws SQLException {
return connection.getTransactionIsolation();
}
});
} catch (Throwable ignore) {
} finally {
if (testSession != null) {
try {
testSession.close();
} catch (Throwable ignore) {
}
}
}
if (isolation < java.sql.Connection.TRANSACTION_READ_COMMITTED) {
SkipLog.reportSkip("environment does not support at least read committed isolation", scenario);
return false;
} else {
return true;
}
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class InsertedDataTest method testInsertWithClear.
@Test
public void testInsertWithClear() {
sessionFactory().getCache().evictEntityRegions();
sessionFactory().getStatistics().clear();
Session s = openSession();
s.beginTransaction();
CacheableItem item = new CacheableItem("data");
s.save(item);
s.flush();
s.clear();
s.getTransaction().commit();
s.close();
Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
assertEquals(1, cacheMap.size());
s = openSession();
s.beginTransaction();
s.createQuery("delete CacheableItem").executeUpdate();
s.getTransaction().commit();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class InsertedDataTest method testInsertWithRefresh.
@Test
public void testInsertWithRefresh() {
sessionFactory().getCache().evictEntityRegions();
sessionFactory().getStatistics().clear();
Session s = openSession();
s.beginTransaction();
CacheableItem item = new CacheableItem("data");
s.save(item);
s.flush();
s.refresh(item);
s.getTransaction().commit();
s.close();
Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
assertEquals(1, cacheMap.size());
s = openSession();
s.beginTransaction();
s.createQuery("delete CacheableItem").executeUpdate();
s.getTransaction().commit();
s.close();
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class InsertedDataTest method testInsertWithClearThenRollback.
@Test
public void testInsertWithClearThenRollback() {
sessionFactory().getCache().evictEntityRegions();
sessionFactory().getStatistics().clear();
Session s = openSession();
s.beginTransaction();
CacheableItem item = new CacheableItem("data");
s.save(item);
s.flush();
s.clear();
item = (CacheableItem) s.get(CacheableItem.class, item.getId());
s.getTransaction().rollback();
s.close();
Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
assertEquals(0, cacheMap.size());
s = openSession();
s.beginTransaction();
item = (CacheableItem) s.get(CacheableItem.class, item.getId());
s.getTransaction().commit();
s.close();
assertNull("it should be null", item);
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class InsertedDataTest method testInsertThenUpdate.
@Test
public void testInsertThenUpdate() {
sessionFactory().getCache().evictEntityRegions();
sessionFactory().getStatistics().clear();
Session s = openSession();
s.beginTransaction();
CacheableItem item = new CacheableItem("data");
s.save(item);
s.flush();
item.setName("new data");
s.getTransaction().commit();
s.close();
Map cacheMap = sessionFactory().getStatistics().getSecondLevelCacheStatistics("item").getEntries();
assertEquals(1, cacheMap.size());
s = openSession();
s.beginTransaction();
s.createQuery("delete CacheableItem").executeUpdate();
s.getTransaction().commit();
s.close();
}
Aggregations