use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class AbstractAuditWorkUnit method fillDataWithId.
protected void fillDataWithId(Map<String, Object> data, Object revision) {
final AuditEntitiesConfiguration entitiesCfg = enversService.getAuditEntitiesConfiguration();
final Map<String, Object> originalId = new HashMap<>();
originalId.put(entitiesCfg.getRevisionFieldName(), revision);
enversService.getEntitiesConfigurations().get(getEntityName()).getIdMapper().mapToMapFromId(originalId, id);
data.put(entitiesCfg.getRevisionTypePropName(), revisionType);
data.put(entitiesCfg.getOriginalIdPropName(), originalId);
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class EntitiesModifiedAtRevisionQuery method list.
@Override
public List list() {
/*
* The query that we need to create:
* SELECT new list(e) FROM versionsReferencedEntity e
* WHERE
* (all specified conditions, transformed, on the "e" entity) AND
* e.revision = :revision
*/
AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration();
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
qb.getRootParameters().addWhereWithParam(revisionPropertyPath, "=", revision);
// all specified conditions
for (AuditCriterion criterion : criterions) {
criterion.addToQuery(enversService, versionsReader, aliasToEntityNameMap, QueryConstants.REFERENCED_ENTITY_ALIAS, qb, qb.getRootParameters());
}
for (final AuditAssociationQueryImpl<?> associationQuery : associationQueries) {
associationQuery.addCriterionsToQuery(versionsReader);
}
Query query = buildQuery();
List queryResult = query.list();
return applyProjections(queryResult, revision);
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class EnversServiceImpl method doInitialize.
private void doInitialize(final MetadataImplementor metadata, final MappingCollector mappingCollector, ServiceRegistry serviceRegistry) {
final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
final Properties properties = new Properties();
properties.putAll(cfgService.getSettings());
this.globalConfiguration = new GlobalConfiguration(this, properties);
final ReflectionManager reflectionManager = metadata.getMetadataBuildingOptions().getReflectionManager();
final RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration(globalConfiguration);
final RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(metadata, reflectionManager);
EnversServiceImpl.this.auditEntitiesConfiguration = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName(), this);
this.auditProcessManager = new AuditProcessManager(revInfoCfgResult.getRevisionInfoGenerator());
this.revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
this.revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
this.modifiedEntityNamesReader = revInfoCfgResult.getModifiedEntityNamesReader();
this.auditStrategy = initializeAuditStrategy(auditEntitiesConfiguration.getAuditStrategyName(), revInfoCfgResult.getRevisionInfoClass(), revInfoCfgResult.getRevisionInfoTimestampData(), serviceRegistry);
this.entitiesConfigurations = new EntitiesConfigurator().configure(metadata, serviceRegistry, reflectionManager, mappingCollector, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class AuditAssociationQueryImpl method addCriterionsToQuery.
protected void addCriterionsToQuery(AuditReaderImplementor versionsReader) {
if (enversService.getEntitiesConfigurations().isVersioned(entityName)) {
String auditEntityName = enversService.getAuditEntitiesConfiguration().getAuditEntityName(entityName);
Parameters joinConditionParameters = queryBuilder.addJoin(joinType, auditEntityName, alias, false);
// owner.reference_id = target.originalId.id
AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
IdMapper idMapperTarget = enversService.getEntitiesConfigurations().get(entityName).getIdMapper();
final String prefix = alias.concat(".").concat(originalIdPropertyName);
ownerAssociationIdMapper.addIdsEqualToQuery(joinConditionParameters, ownerAlias, idMapperTarget, prefix);
// filter revision of target entity
Parameters parametersToUse = parameters;
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
if (joinType == JoinType.LEFT) {
parametersToUse = parameters.addSubParameters(Parameters.OR);
parametersToUse.addNullRestriction(revisionPropertyPath, true);
parametersToUse = parametersToUse.addSubParameters(Parameters.AND);
}
MiddleIdData referencedIdData = new MiddleIdData(verEntCfg, enversService.getEntitiesConfigurations().get(entityName).getIdMappingData(), null, entityName, enversService.getEntitiesConfigurations().isVersioned(entityName));
enversService.getAuditStrategy().addEntityAtRevisionRestriction(enversService.getGlobalConfiguration(), queryBuilder, parametersToUse, revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencedIdData, revisionPropertyPath, originalIdPropertyName, alias, queryBuilder.generateAlias(), true);
} else {
Parameters joinConditionParameters = queryBuilder.addJoin(joinType, entityName, alias, false);
// owner.reference_id = target.id
final IdMapper idMapperTarget = enversService.getEntitiesConfigurations().getNotVersionEntityConfiguration(entityName).getIdMapper();
ownerAssociationIdMapper.addIdsEqualToQuery(joinConditionParameters, ownerAlias, idMapperTarget, alias);
}
for (AuditCriterion criterion : criterions) {
criterion.addToQuery(enversService, versionsReader, aliasToEntityNameMap, alias, queryBuilder, parameters);
}
for (final AuditAssociationQueryImpl<?> sub : associationQueries) {
sub.addCriterionsToQuery(versionsReader);
}
}
use of org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration in project hibernate-orm by hibernate.
the class EntitiesAtRevisionQuery method list.
public List list() {
/*
* The query that we need to create:
* SELECT new list(e) FROM versionsReferencedEntity e
* WHERE
* (all specified conditions, transformed, on the "e" entity) AND
* (selecting e entities at revision :revision)
* --> for DefaultAuditStrategy:
* e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
* WHERE e2.revision <= :revision AND e2.id = e.id)
*
* --> for ValidityAuditStrategy:
* e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)
*
* AND
* (only non-deleted entities)
* e.revision_type != DEL
*/
AuditEntitiesConfiguration verEntCfg = enversService.getAuditEntitiesConfiguration();
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
MiddleIdData referencedIdData = new MiddleIdData(verEntCfg, enversService.getEntitiesConfigurations().get(entityName).getIdMappingData(), null, entityName, enversService.getEntitiesConfigurations().isVersioned(entityName));
// (selecting e entities at revision :revision)
// --> based on auditStrategy (see above)
enversService.getAuditStrategy().addEntityAtRevisionRestriction(enversService.getGlobalConfiguration(), qb, qb.getRootParameters(), revisionPropertyPath, verEntCfg.getRevisionEndFieldName(), true, referencedIdData, revisionPropertyPath, originalIdPropertyName, REFERENCED_ENTITY_ALIAS, REFERENCED_ENTITY_ALIAS_DEF_AUD_STR, true);
if (!includeDeletions) {
// e.revision_type != DEL
qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
}
// all specified conditions
for (AuditCriterion criterion : criterions) {
criterion.addToQuery(enversService, versionsReader, aliasToEntityNameMap, QueryConstants.REFERENCED_ENTITY_ALIAS, qb, qb.getRootParameters());
}
for (final AuditAssociationQueryImpl<?> associationQuery : associationQueries) {
associationQuery.addCriterionsToQuery(versionsReader);
}
Query query = buildQuery();
// add named parameter (used for ValidityAuditStrategy and association queries)
Collection<String> params = query.getParameterMetadata().getNamedParameterNames();
if (params.contains(REVISION_PARAMETER)) {
query.setParameter(REVISION_PARAMETER, revision);
}
List queryResult = query.list();
return applyProjections(queryResult, revision);
}
Aggregations