Search in sources :

Example 16 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, String prefix2) {
    final List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
    final Parameters parametersToUse = getParametersToUse(parameters, paramDatas);
    for (QueryParameterData paramData : paramDatas) {
        parametersToUse.addWhere(paramData.getProperty(prefix1), false, "=", paramData.getProperty(prefix2), false);
    }
}
Also used : Parameters(org.hibernate.envers.internal.tools.query.Parameters)

Example 17 with Parameters

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

the class TwoEntityOneAuditedQueryGenerator 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
    final QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
    qb.addFrom(referencedIdData.getEntityName(), 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);
    // 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)

Example 18 with Parameters

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

the class TwoEntityOneAuditedQueryGenerator 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");
    createValidDataRestrictions(auditStrategy, versionsMiddleEntityName, remQb, valid, 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 19 with Parameters

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

the class ThreeEntityQueryGenerator method commonQueryPart.

/**
 * Compute common part for both queries.
 */
private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, MiddleIdData indexIdData, String versionsMiddleEntityName, String originalIdPropertyName) {
    final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
    // SELECT new list(ee) FROM middleEntity ee
    final QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
    qb.addFrom(referencedIdData.getAuditEntityName(), REFERENCED_ENTITY_ALIAS, false);
    qb.addFrom(indexIdData.getAuditEntityName(), INDEX_ENTITY_ALIAS, false);
    qb.addProjection("new list", MIDDLE_ENTITY_ALIAS + ", " + REFERENCED_ENTITY_ALIAS + ", " + INDEX_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.id_ref_ind = f.id_ref_ind
    indexIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, indexIdData.getOriginalMapper(), INDEX_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)

Example 20 with Parameters

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

the class TwoEntityQueryGenerator 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, 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, componentData);
    // ee.revision = :revision
    removed.addWhereWithNamedParam(revisionPropertyPath, "=", REVISION_PARAMETER);
    // e.revision = :revision
    removed.addWhereWithNamedParam(REFERENCED_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);
}
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