Search in sources :

Example 1 with Parameters

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

the class AbstractIdMapper method addIdsEqualToQuery.

@Override
public void addIdsEqualToQuery(Parameters parameters, String prefix1, IdMapper mapper2, String prefix2) {
    final List<QueryParameterData> paramDatas1 = mapToQueryParametersFromId(null);
    final List<QueryParameterData> paramDatas2 = mapper2.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.addWhereOrNullRestriction(paramData1.getProperty(prefix1), false, "=", paramData2.getProperty(prefix2), false);
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 2 with Parameters

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

the class AbstractIdMapper method addIdEqualsToQuery.

@Override
public void addIdEqualsToQuery(Parameters parameters, Object id, String alias, String prefix, boolean equals) {
    final List<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
    final Parameters parametersToUse = getParametersToUse(parameters, paramDatas);
    for (QueryParameterData paramData : paramDatas) {
        if (paramData.getValue() == null) {
            handleNullValue(parametersToUse, alias, paramData.getProperty(prefix), equals);
        } else if (alias == null) {
            parametersToUse.addWhereWithParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getValue());
        } else {
            parametersToUse.addWhereWithParam(alias, paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getValue());
        }
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 3 with Parameters

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

the class AggregatedAuditExpression method addToQuery.

@Override
public void addToQuery(EnversService enversService, AuditReaderImplementor versionsReader, Map<String, String> aliasToEntityNameMap, String baseAlias, QueryBuilder qb, Parameters parameters) {
    String effectiveAlias = this.alias == null ? baseAlias : this.alias;
    String entityName = aliasToEntityNameMap.get(effectiveAlias);
    String propertyName = CriteriaTools.determinePropertyName(enversService, versionsReader, entityName, propertyNameGetter);
    CriteriaTools.checkPropertyNotARelation(enversService, entityName, propertyName);
    // Make sure our conditions are ANDed together even if the parent Parameters have a different connective
    Parameters subParams = parameters.addSubParameters(Parameters.AND);
    // This will be the aggregated query, containing all the specified conditions
    String auditEntityName = enversService.getAuditEntitiesConfiguration().getAuditEntityName(entityName);
    String subQueryAlias = qb.generateAlias();
    QueryBuilder subQb = qb.newSubQueryBuilder(auditEntityName, subQueryAlias);
    aliasToEntityNameMap.put(subQueryAlias, entityName);
    // aggregated one.
    for (AuditCriterion versionsCriteria : criterions) {
        versionsCriteria.addToQuery(enversService, versionsReader, aliasToEntityNameMap, effectiveAlias, qb, subParams);
        versionsCriteria.addToQuery(enversService, versionsReader, aliasToEntityNameMap, subQueryAlias, subQb, subQb.getRootParameters());
    }
    // Setting the desired projection of the aggregated query
    switch(mode) {
        case MIN:
            subQb.addProjection("min", subQb.getAlias(), propertyName, false);
            break;
        case MAX:
            subQb.addProjection("max", subQb.getAlias(), propertyName, false);
    }
    // Correlating subquery with the outer query by entity id. See JIRA HHH-7827.
    if (correlate) {
        final String originalIdPropertyName = enversService.getAuditEntitiesConfiguration().getOriginalIdPropName();
        enversService.getEntitiesConfigurations().get(entityName).getIdMapper().addIdsEqualToQuery(subQb.getRootParameters(), subQb.getRootAlias() + "." + originalIdPropertyName, effectiveAlias + "." + originalIdPropertyName);
    }
    // Adding the constrain on the result of the aggregated criteria
    subParams.addWhere(effectiveAlias, propertyName, "=", subQb);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters) QueryBuilder(org.hibernate.envers.internal.tools.query.QueryBuilder)

Example 4 with Parameters

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

the class LogicalAuditExpression method addToQuery.

public void addToQuery(EnversService enversService, AuditReaderImplementor versionsReader, Map<String, String> aliasToEntityNameMap, String alias, QueryBuilder qb, Parameters parameters) {
    Parameters opParameters = parameters.addSubParameters(op);
    lhs.addToQuery(enversService, versionsReader, aliasToEntityNameMap, alias, qb, opParameters.addSubParameters("and"));
    rhs.addToQuery(enversService, versionsReader, aliasToEntityNameMap, alias, qb, opParameters.addSubParameters("and"));
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 5 with Parameters

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

the class DefaultAuditStrategy method addEntityAtRevisionRestriction.

public void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2, boolean inclusive) {
    // create a subquery builder
    // SELECT max(e.revision) FROM versionsReferencedEntity e2
    QueryBuilder maxERevQb = rootQueryBuilder.newSubQueryBuilder(idData.getAuditEntityName(), alias2);
    maxERevQb.addProjection("max", alias2, revisionPropertyPath, false);
    // WHERE
    Parameters maxERevQbParameters = maxERevQb.getRootParameters();
    // e2.revision <= :revision
    maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER);
    // e2.id_ref_ed = e.id_ref_ed
    idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters, alias1 + "." + originalIdPropertyName, alias2 + "." + originalIdPropertyName);
    // add subquery to rootParameters
    String subqueryOperator = globalCfg.getCorrelatedSubqueryOperator();
    parameters.addWhere(revisionProperty, addAlias, subqueryOperator, maxERevQb);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters) QueryBuilder(org.hibernate.envers.internal.tools.query.QueryBuilder)

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