use of org.hibernate.envers.internal.synchronization.work.AuditWorkUnit in project hibernate-orm by hibernate.
the class EnversPostInsertEventListenerImpl method onPostInsert.
@Override
public void onPostInsert(PostInsertEvent event) {
final String entityName = event.getPersister().getEntityName();
if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
checkIfTransactionInProgress(event.getSession());
final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
final AuditWorkUnit workUnit = new AddWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), event.getState());
auditProcess.addWorkUnit(workUnit);
if (workUnit.containsWork()) {
generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, event.getState(), null, event.getSession());
}
}
}
use of org.hibernate.envers.internal.synchronization.work.AuditWorkUnit in project hibernate-orm by hibernate.
the class EnversPostUpdateEventListenerImpl method onPostUpdate.
@Override
public void onPostUpdate(PostUpdateEvent event) {
final String entityName = event.getPersister().getEntityName();
if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
checkIfTransactionInProgress(event.getSession());
final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
Object[] oldState = getOldDBState(auditProcess, entityName, event);
final Object[] newDbState = postUpdateDBState(event);
final AuditWorkUnit workUnit = new ModWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), newDbState, oldState);
auditProcess.addWorkUnit(workUnit);
if (workUnit.containsWork()) {
generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, newDbState, oldState, event.getSession());
}
}
}
use of org.hibernate.envers.internal.synchronization.work.AuditWorkUnit in project hibernate-orm by hibernate.
the class AuditProcess method executeInSession.
private void executeInSession(Session session) {
// Making sure the revision data is persisted.
final Object currentRevisionData = getCurrentRevisionData(session, true);
AuditWorkUnit vwu;
// First undoing any performed work units
while ((vwu = undoQueue.poll()) != null) {
vwu.undo(session);
}
while ((vwu = workUnits.poll()) != null) {
vwu.perform(session, revisionData);
entityChangeNotifier.entityChanged(session, currentRevisionData, vwu);
}
}
use of org.hibernate.envers.internal.synchronization.work.AuditWorkUnit in project hibernate-orm by hibernate.
the class BaseEnversCollectionEventListener method generateFakeBidirecationalRelationWorkUnits.
private void generateFakeBidirecationalRelationWorkUnits(AuditProcess auditProcess, PersistentCollection newColl, Serializable oldColl, String collectionEntityName, String referencingPropertyName, AbstractCollectionEvent event, RelationDescription rd) {
// First computing the relation changes
final List<PersistentCollectionChangeData> collectionChanges = getEnversService().getEntitiesConfigurations().get(collectionEntityName).getPropertyMapper().mapCollectionChanges(event.getSession(), referencingPropertyName, newColl, oldColl, event.getAffectedOwnerIdOrNull());
// Getting the id mapper for the related entity, as the work units generated will correspond to the related
// entities.
final String relatedEntityName = rd.getToEntityName();
final IdMapper relatedIdMapper = getEnversService().getEntitiesConfigurations().get(relatedEntityName).getIdMapper();
// For each collection change, generating the bidirectional work unit.
for (PersistentCollectionChangeData changeData : collectionChanges) {
final Object relatedObj = changeData.getChangedElement();
final Serializable relatedId = (Serializable) relatedIdMapper.mapToIdFromEntity(relatedObj);
final RevisionType revType = (RevisionType) changeData.getData().get(getEnversService().getAuditEntitiesConfiguration().getRevisionTypePropName());
// This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass
// of relatedEntityName).
final String realRelatedEntityName = event.getSession().bestGuessEntityName(relatedObj);
// By default, the nested work unit is a collection change work unit.
final AuditWorkUnit nestedWorkUnit = new CollectionChangeWorkUnit(event.getSession(), realRelatedEntityName, rd.getMappedByPropertyName(), getEnversService(), relatedId, relatedObj);
auditProcess.addWorkUnit(new FakeBidirectionalRelationWorkUnit(event.getSession(), realRelatedEntityName, getEnversService(), relatedId, referencingPropertyName, event.getAffectedOwnerOrNull(), rd, revType, changeData.getChangedElementIndex(), nestedWorkUnit));
}
// We also have to generate a collection change work unit for the owning entity.
auditProcess.addWorkUnit(new CollectionChangeWorkUnit(event.getSession(), collectionEntityName, referencingPropertyName, getEnversService(), event.getAffectedOwnerIdOrNull(), event.getAffectedOwnerOrNull()));
}
use of org.hibernate.envers.internal.synchronization.work.AuditWorkUnit in project hibernate-orm by hibernate.
the class EnversPostDeleteEventListenerImpl method onPostDelete.
@Override
public void onPostDelete(PostDeleteEvent event) {
final String entityName = event.getPersister().getEntityName();
if (getEnversService().getEntitiesConfigurations().isVersioned(entityName)) {
checkIfTransactionInProgress(event.getSession());
final AuditProcess auditProcess = getEnversService().getAuditProcessManager().get(event.getSession());
final AuditWorkUnit workUnit = new DelWorkUnit(event.getSession(), event.getPersister().getEntityName(), getEnversService(), event.getId(), event.getPersister(), event.getDeletedState());
auditProcess.addWorkUnit(workUnit);
if (workUnit.containsWork()) {
generateBidirectionalCollectionChangeWorkUnits(auditProcess, event.getPersister(), entityName, null, event.getDeletedState(), event.getSession());
}
}
}
Aggregations