Search in sources :

Example 6 with Parameters

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

the class DefaultAuditStrategy method addAssociationAtRevisionRestriction.

public void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath, String originalIdPropertyName, String alias1, boolean inclusive, MiddleComponentData... componentDatas) {
    // SELECT max(ee2.revision) FROM middleEntity ee2
    QueryBuilder maxEeRevQb = rootQueryBuilder.newSubQueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS_DEF_AUD_STR);
    maxEeRevQb.addProjection("max", MIDDLE_ENTITY_ALIAS_DEF_AUD_STR, revisionPropertyPath, false);
    // WHERE
    Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
    // ee2.revision <= :revision
    maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, inclusive ? "<=" : "<", REVISION_PARAMETER);
    // ee2.originalId.* = ee.originalId.*
    String ee2OriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS_DEF_AUD_STR + "." + originalIdPropertyName;
    referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
    for (MiddleComponentData componentData : componentDatas) {
        componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, alias1, ee2OriginalIdPropertyPath, MIDDLE_ENTITY_ALIAS_DEF_AUD_STR);
    }
    // add subquery to rootParameters
    parameters.addWhere(revisionProperty, addAlias, "=", maxEeRevQb);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters) QueryBuilder(org.hibernate.envers.internal.tools.query.QueryBuilder) MiddleComponentData(org.hibernate.envers.internal.entities.mapper.relation.MiddleComponentData)

Example 7 with Parameters

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

the class ValidityAuditStrategy method addRevisionRestriction.

private void addRevisionRestriction(Parameters rootParameters, String revisionProperty, String revisionEndProperty, boolean addAlias, boolean inclusive) {
    // e.revision <= _revision and (e.endRevision > _revision or e.endRevision is null)
    Parameters subParm = rootParameters.addSubParameters("or");
    rootParameters.addWhereWithNamedParam(revisionProperty, addAlias, inclusive ? "<=" : "<", REVISION_PARAMETER);
    subParm.addWhereWithNamedParam(revisionEndProperty + ".id", addAlias, inclusive ? ">" : ">=", REVISION_PARAMETER);
    subParm.addWhere(revisionEndProperty, addAlias, "is", "null", false);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 8 with Parameters

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

the class OneEntityQueryGenerator method createValidAndRemovedDataRestrictions.

/**
 * Create query restrictions used to retrieve actual data and deletions that took place at exactly given revision.
 */
private void createValidAndRemovedDataRestrictions(AuditStrategy auditStrategy, String versionsMiddleEntityName, QueryBuilder remQb, 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");
    // Excluding current revision, because we need to match data valid at the previous one.
    createValidDataRestrictions(auditStrategy, versionsMiddleEntityName, remQb, valid, false, componentData);
    // ee.revision = :revision
    removed.addWhereWithNamedParam(verEntCfg.getRevisionNumberPath(), "=", REVISION_PARAMETER);
    // ee.revision_type = DEL
    removed.addWhereWithNamedParam(getRevisionTypePath(), "=", DEL_REVISION_TYPE_PARAMETER);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 9 with Parameters

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

the class OneAuditEntityQueryGenerator 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, QueryBuilder remQb) {
    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");
    // Excluding current revision, because we need to match data valid at the previous one.
    createValidDataRestrictions(globalCfg, auditStrategy, referencedIdData, remQb, valid);
    // e.revision = :revision
    removed.addWhereWithNamedParam(verEntCfg.getRevisionNumberPath(), false, "=", REVISION_PARAMETER);
    // e.revision_type = DEL
    removed.addWhereWithNamedParam(getRevisionTypePath(), false, "=", DEL_REVISION_TYPE_PARAMETER);
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 10 with Parameters

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

the class TwoEntityQueryGenerator method commonQueryPart.

/**
 * Compute common part for both queries.
 */
private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, String versionsMiddleEntityName, String originalIdPropertyName) {
    final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
    // SELECT new list(ee) FROM middleEntity ee
    QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
    qb.addFrom(referencedIdData.getAuditEntityName(), REFERENCED_ENTITY_ALIAS, false);
    qb.addProjection("new list", MIDDLE_ENTITY_ALIAS + ", " + REFERENCED_ENTITY_ALIAS, null, false);
    // WHERE
    final Parameters rootParameters = qb.getRootParameters();
    // ee.id_ref_ed = e.id_ref_ed
    referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, referencedIdData.getOriginalMapper(), REFERENCED_ENTITY_ALIAS + "." + originalIdPropertyName);
    // ee.originalId.id_ref_ing = :id_ref_ing
    referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
    return qb;
}
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