use of org.hibernate.StatelessSession in project dhis2-core by dhis2.
the class DeletedObjectPostInsertEventListener method onPostInsert.
@Override
public void onPostInsert(PostInsertEvent event) {
if (IdentifiableObject.class.isInstance(event.getEntity()) && MetadataObject.class.isInstance(event.getEntity()) && !EmbeddedObject.class.isInstance(event.getEntity())) {
StatelessSession session = event.getPersister().getFactory().openStatelessSession();
session.beginTransaction();
try {
List<DeletedObject> deletedObjects = deletedObjectService.getDeletedObjects(new DeletedObjectQuery((IdentifiableObject) event.getEntity()));
deletedObjects.forEach(session::delete);
knownTransactionsService.registerEvent(event);
session.getTransaction().commit();
} catch (Exception ex) {
log.error("Failed to delete DeletedObject for:" + event.getEntity());
session.getTransaction().rollback();
} finally {
session.close();
}
}
}
use of org.hibernate.StatelessSession in project dhis2-core by dhis2.
the class DeletedObjectPostDeleteEventListener method onPostDelete.
@Override
public void onPostDelete(PostDeleteEvent event) {
if (IdentifiableObject.class.isInstance(event.getEntity()) && MetadataObject.class.isInstance(event.getEntity()) && !EmbeddedObject.class.isInstance(event.getEntity())) {
IdentifiableObject identifiableObject = (IdentifiableObject) event.getEntity();
DeletedObject deletedObject = new DeletedObject(identifiableObject);
deletedObject.setDeletedBy(getUsername());
StatelessSession session = event.getPersister().getFactory().openStatelessSession();
session.beginTransaction();
knownTransactionsService.registerEvent(event);
try {
session.insert(deletedObject);
session.getTransaction().commit();
} catch (Exception ex) {
log.error("Failed to save DeletedObject: " + deletedObject);
session.getTransaction().rollback();
} finally {
session.close();
}
}
}
Aggregations