Search in sources :

Example 11 with Parameters

use of org.hibernate.envers.internal.tools.query.Parameters in project hibernate-orm by hibernate.

the class ThreeEntityQueryGenerator method createValidAndRemovedDataRestrictions.

/**
 * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision.
 */
private void createValidAndRemovedDataRestrictions(GlobalConfiguration globalCfg, AuditStrategy auditStrategy, MiddleIdData referencedIdData, String versionsMiddleEntityName, QueryBuilder remQb, MiddleIdData indexIdData, MiddleComponentData... componentData) {
    final Parameters disjoint = remQb.getRootParameters().addSubParameters("or");
    // Restrictions to match all valid rows.
    final Parameters valid = disjoint.addSubParameters("and");
    // Restrictions to match all rows deleted at exactly given revision.
    final Parameters removed = disjoint.addSubParameters("and");
    final String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
    final String revisionTypePropName = getRevisionTypePath();
    // Excluding current revision, because we need to match data valid at the previous one.
    createValidDataRestrictions(globalCfg, auditStrategy, referencedIdData, versionsMiddleEntityName, remQb, valid, false, indexIdData, componentData);
    // ee.revision = :revision
    removed.addWhereWithNamedParam(revisionPropertyPath, "=", REVISION_PARAMETER);
    // e.revision = :revision
    removed.addWhereWithNamedParam(REFERENCED_ENTITY_ALIAS + "." + revisionPropertyPath, false, "=", REVISION_PARAMETER);
    // f.revision = :revision
    removed.addWhereWithNamedParam(INDEX_ENTITY_ALIAS + "." + revisionPropertyPath, false, "=", REVISION_PARAMETER);
    // ee.revision_type = DEL
    removed.addWhereWithNamedParam(revisionTypePropName, "=", DEL_REVISION_TYPE_PARAMETER);
    // e.revision_type = DEL
    removed.addWhereWithNamedParam(REFERENCED_ENTITY_ALIAS + "." + revisionTypePropName, false, "=", DEL_REVISION_TYPE_PARAMETER);
    // f.revision_type = DEL
    removed.addWhereWithNamedParam(INDEX_ENTITY_ALIAS + "." + revisionTypePropName, false, "=", DEL_REVISION_TYPE_PARAMETER);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 12 with Parameters

use of org.hibernate.envers.internal.tools.query.Parameters 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);
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters) MiddleIdData(org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData) AuditEntitiesConfiguration(org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration) IdMapper(org.hibernate.envers.internal.entities.mapper.id.IdMapper) AuditCriterion(org.hibernate.envers.query.criteria.AuditCriterion)

Example 13 with Parameters

use of org.hibernate.envers.internal.tools.query.Parameters in project hibernate-orm by hibernate.

the class BetweenAuditExpression method addToQuery.

@Override
protected void addToQuery(EnversService enversService, AuditReaderImplementor versionsReader, String entityName, String alias, QueryBuilder qb, Parameters parameters) {
    String propertyName = CriteriaTools.determinePropertyName(enversService, versionsReader, entityName, propertyNameGetter);
    CriteriaTools.checkPropertyNotARelation(enversService, entityName, propertyName);
    Parameters subParams = parameters.addSubParameters(Parameters.AND);
    subParams.addWhereWithParam(alias, propertyName, ">=", lo);
    subParams.addWhereWithParam(alias, propertyName, "<=", hi);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 14 with Parameters

use of org.hibernate.envers.internal.tools.query.Parameters in project hibernate-orm by hibernate.

the class AbstractIdMapper method addNamedIdEqualsToQuery.

@Override
public void addNamedIdEqualsToQuery(Parameters parameters, String prefix, boolean equals) {
    final List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
    final Parameters parametersToUse = getParametersToUse(parameters, paramDatas);
    for (QueryParameterData paramData : paramDatas) {
        parametersToUse.addWhereWithNamedParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getQueryParameterName());
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 15 with Parameters

use of org.hibernate.envers.internal.tools.query.Parameters in project hibernate-orm by hibernate.

the class AbstractIdMapper method addNamedIdEqualsToQuery.

@Override
public void addNamedIdEqualsToQuery(Parameters parameters, String prefix1, IdMapper mapper, boolean equals) {
    final List<QueryParameterData> paramDatas1 = mapToQueryParametersFromId(null);
    final List<QueryParameterData> paramDatas2 = mapper.mapToQueryParametersFromId(null);
    final Parameters parametersToUse = getParametersToUse(parameters, paramDatas1);
    final Iterator<QueryParameterData> paramDataIter1 = paramDatas1.iterator();
    final Iterator<QueryParameterData> paramDataIter2 = paramDatas2.iterator();
    while (paramDataIter1.hasNext()) {
        final QueryParameterData paramData1 = paramDataIter1.next();
        final QueryParameterData paramData2 = paramDataIter2.next();
        parametersToUse.addWhereWithNamedParam(paramData1.getProperty(prefix1), equals ? "=" : "<>", paramData2.getQueryParameterName());
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Aggregations

Parameters (org.hibernate.envers.internal.tools.query.Parameters)20 QueryBuilder (org.hibernate.envers.internal.tools.query.QueryBuilder)6 AuditEntitiesConfiguration (org.hibernate.envers.configuration.internal.AuditEntitiesConfiguration)1 IdMapper (org.hibernate.envers.internal.entities.mapper.id.IdMapper)1 MiddleComponentData (org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData)1 MiddleIdData (org.hibernate.envers.internal.entities.mapper.relation.MiddleIdData)1 AuditCriterion (org.hibernate.envers.query.criteria.AuditCriterion)1