use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class RevisionsOfEntityQuery method list.
@SuppressWarnings({ "unchecked" })
public List list() throws AuditException {
AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration();
/*
The query that should be executed in the versions table:
SELECT e (unless another projection is specified) FROM ent_ver e, rev_entity r WHERE
e.revision_type != DEL (if selectDeletedEntities == false) AND
e.revision = r.revision AND
(all specified conditions, transformed, on the "e" entity)
ORDER BY e.revision ASC (unless another order or projection is specified)
*/
if (!selectDeletedEntities) {
// e.revision_type != DEL AND
qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
}
// all specified conditions, transformed
for (AuditCriterion criterion : criterions) {
criterion.addToQuery(enversService, versionsReader, aliasToEntityNameMap, QueryConstants.REFERENCED_ENTITY_ALIAS, qb, qb.getRootParameters());
}
if (!hasProjection() && !hasOrder) {
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
qb.addOrder(QueryConstants.REFERENCED_ENTITY_ALIAS, revisionPropertyPath, true);
}
if (!selectEntitiesOnly) {
qb.addFrom(enversService.getAuditEntitiesConfiguration().getRevisionInfoEntityName(), "r", true);
qb.getRootParameters().addWhere(enversService.getAuditEntitiesConfiguration().getRevisionNumberPath(), true, "=", "r.id", false);
}
List<Object> queryResult = buildAndExecuteQuery();
if (hasProjection()) {
return queryResult;
} else {
List entities = new ArrayList();
String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
for (Object resultRow : queryResult) {
Map versionsEntity;
Object revisionData;
if (selectEntitiesOnly) {
versionsEntity = (Map) resultRow;
revisionData = null;
} else {
Object[] arrayResultRow = (Object[]) resultRow;
versionsEntity = (Map) arrayResultRow[0];
revisionData = arrayResultRow[1];
}
Number revision = getRevisionNumber(versionsEntity);
Object entity = entityInstantiator.createInstanceFromVersionsEntity(entityName, versionsEntity, revision);
if (!selectEntitiesOnly) {
entities.add(new Object[] { entity, revisionData, versionsEntity.get(revisionTypePropertyName) });
} else {
entities.add(entity);
}
}
return entities;
}
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class RevisionsOfEntityQuery method getRevisionNumber.
private Number getRevisionNumber(Map versionsEntity) {
AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration();
String originalId = verEntCfg.getOriginalIdPropName();
String revisionPropertyName = verEntCfg.getRevisionFieldName();
Object revisionInfoObject = ((Map) versionsEntity.get(originalId)).get(revisionPropertyName);
if (revisionInfoObject instanceof HibernateProxy) {
return (Number) ((HibernateProxy) revisionInfoObject).getHibernateLazyInitializer().getIdentifier();
} else {
// Not a proxy - must be read from cache or with a join
return enversService.getRevisionInfoNumberReader().getRevisionNumber(revisionInfoObject);
}
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class PersistentCollectionChangeWorkUnit method perform.
@Override
@SuppressWarnings({ "unchecked" })
public void perform(Session session, Object revisionData) {
final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration();
for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) {
// Setting the revision number
((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName())).put(entitiesCfg.getRevisionFieldName(), revisionData);
auditStrategy.performCollectionChange(session, getEntityName(), referencingPropertyName, enversService, persistentCollectionChangeData, revisionData);
}
}
Aggregations