use of org.hibernate.Transaction 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.Transaction 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.Transaction 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
}
}
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class TestStoreRetrieveUsingGeolatte method storeTestObjects.
private void storeTestObjects(Map<Integer, GeomEntity> stored) {
Session session = null;
Transaction tx = null;
int id = -1;
try {
session = openSession();
// to improve feedback in case of failure
for (TestDataElement element : testData) {
id = element.id;
tx = session.beginTransaction();
GeomEntity entity = GeomEntity.createFrom(element);
stored.put(entity.getId(), entity);
session.save(entity);
tx.commit();
}
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw new RuntimeException("Failed storing testsuite-suite object with id:" + id, e);
} finally {
if (session != null) {
session.close();
}
}
}
use of org.hibernate.Transaction in project hibernate-orm by hibernate.
the class TestStoreRetrieveUsingJTS method retrieveAndCompare.
private void retrieveAndCompare(Map<Integer, GeomEntity> stored) {
int id = -1;
Transaction tx = null;
Session session = null;
try {
session = openSession();
tx = session.beginTransaction();
for (GeomEntity storedEntity : stored.values()) {
id = storedEntity.getId();
GeomEntity retrievedEntity = (GeomEntity) session.get(GeomEntity.class, id);
Geometry retrievedGeometry = retrievedEntity.getGeom();
Geometry storedGeometry = storedEntity.getGeom();
String msg = createFailureMessage(storedEntity.getId(), storedGeometry, retrievedGeometry);
assertTrue(msg, geometryEquality.test(storedGeometry, retrievedGeometry));
}
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw new RuntimeException(String.format("Failure on case: %d", id), e);
} finally {
if (session != null) {
session.close();
}
}
}
Aggregations