use of org.hibernate.Session in project druid by alibaba.
the class HibernateCRUDTest method test_get.
public void test_get() {
Session session = null;
try {
session = sessionFactory.openSession();
doCreate(session);
doGet(session);
} finally {
if (session != null) {
session.flush();
session.close();
}
}
}
use of org.hibernate.Session in project druid by alibaba.
the class HibernateCRUDTest method test_transactional_delete.
public void test_transactional_delete() {
Session session = null;
Transaction tran = null;
try {
session = sessionFactory.openSession();
tran = session.beginTransaction();
doCreate(session);
doDelete(session);
} finally {
if (tran != null) {
tran.commit();
}
if (session != null) {
session.flush();
session.close();
}
}
}
use of org.hibernate.Session in project druid by alibaba.
the class HibernateCRUDTest method test_delete.
public void test_delete() {
Session session = null;
try {
session = sessionFactory.openSession();
doCreate(session);
doDelete(session);
} finally {
if (session != null) {
session.flush();
session.close();
}
}
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class SpatialFunctionalTestCase method cleanUpTest.
private void cleanUpTest(String pckg) {
Session session = null;
Transaction tx = null;
try {
session = openSession();
tx = session.beginTransaction();
String hql = String.format("delete from org.hibernate.spatial.integration.%s.GeomEntity", pckg);
Query q = session.createQuery(hql);
q.executeUpdate();
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
} finally {
if (session != null) {
session.close();
}
}
}
use of org.hibernate.Session in project hibernate-orm by hibernate.
the class BaseCoreFunctionalTestCase method assertAllDataRemoved.
@SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
protected void assertAllDataRemoved() {
if (!createSchema()) {
// no tables were created...
return;
}
if (!Boolean.getBoolean(VALIDATE_DATA_CLEANUP)) {
return;
}
Session tmpSession = sessionFactory.openSession();
Transaction transaction = tmpSession.beginTransaction();
try {
List list = tmpSession.createQuery("select o from java.lang.Object o").list();
Map<String, Integer> items = new HashMap<String, Integer>();
if (!list.isEmpty()) {
for (Object element : list) {
Integer l = items.get(tmpSession.getEntityName(element));
if (l == null) {
l = 0;
}
l = l + 1;
items.put(tmpSession.getEntityName(element), l);
System.out.println("Data left: " + element);
}
transaction.rollback();
fail("Data is left in the database: " + items.toString());
}
transaction.rollback();
} finally {
try {
if (transaction.getStatus().canRollback()) {
transaction.rollback();
}
tmpSession.close();
} catch (Throwable t) {
// intentionally empty
}
}
}
Aggregations