Search in sources :

Example 1 with QueryParameterData

use of org.hibernate.envers.internal.entities.mapper.id.QueryParameterData in project hibernate-orm by hibernate.

the class RelatedAuditInExpression 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);
    RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(enversService, entityName, propertyName);
    if (relatedEntity == null) {
        throw new AuditException("The criterion can only be used on a property that is a relation to another property.");
    }
    // todo: should this throw an error if qpdList is null?  is it possible?
    List<QueryParameterData> qpdList = relatedEntity.getIdMapper().mapToQueryParametersFromId(propertyName);
    if (qpdList != null) {
        QueryParameterData qpd = qpdList.iterator().next();
        parameters.addWhereWithParams(alias, qpd.getQueryParameterName(), "in (", ids, ")");
    }
}
Also used : QueryParameterData(org.hibernate.envers.internal.entities.mapper.id.QueryParameterData) RelationDescription(org.hibernate.envers.internal.entities.RelationDescription) AuditException(org.hibernate.envers.exception.AuditException)

Example 2 with QueryParameterData

use of org.hibernate.envers.internal.entities.mapper.id.QueryParameterData in project hibernate-orm by hibernate.

the class AbstractRelationQueryGenerator method getQuery.

@Override
public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision, boolean removed) {
    final Query query = versionsReader.getSession().createQuery(removed ? getQueryRemovedString() : getQueryString());
    query.setParameter(DEL_REVISION_TYPE_PARAMETER, RevisionType.DEL);
    query.setParameter(REVISION_PARAMETER, revision);
    for (QueryParameterData paramData : referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
        paramData.setParameterValue(query);
    }
    return query;
}
Also used : QueryParameterData(org.hibernate.envers.internal.entities.mapper.id.QueryParameterData) Query(org.hibernate.query.Query)

Aggregations

QueryParameterData (org.hibernate.envers.internal.entities.mapper.id.QueryParameterData)2 AuditException (org.hibernate.envers.exception.AuditException)1 RelationDescription (org.hibernate.envers.internal.entities.RelationDescription)1 Query (org.hibernate.query.Query)1