Search in sources :

Example 1 with RelationDescription

use of org.hibernate.envers.internal.entities.RelationDescription in project hibernate-orm by hibernate.

the class NotNullAuditExpression 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) {
        parameters.addNotNullRestriction(alias, propertyName);
    } else {
        relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, alias, null, false);
    }
}
Also used : RelationDescription(org.hibernate.envers.internal.entities.RelationDescription)

Example 2 with RelationDescription

use of org.hibernate.envers.internal.entities.RelationDescription 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 3 with RelationDescription

use of org.hibernate.envers.internal.entities.RelationDescription in project hibernate-orm by hibernate.

the class SimpleAuditExpression 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) {
        // HHH-9178 - Add support to component type equality.
        // This basically will allow = and <> operators to perform component-based equality checks.
        // Any other operator for a component type will not be supported.
        // Non-component types will continue to behave normally.
        final SessionImplementor session = versionsReader.getSessionImplementor();
        final Type type = getPropertyType(session, entityName, propertyName);
        if (type != null && type.isComponentType()) {
            if (!"=".equals(op) && !"<>".equals(op)) {
                throw new AuditException("Component-based criterion is not supported for op: " + op);
            }
            final ComponentType componentType = (ComponentType) type;
            for (int i = 0; i < componentType.getPropertyNames().length; i++) {
                final Object componentValue = componentType.getPropertyValue(value, i, session);
                parameters.addWhereWithParam(alias, propertyName + "_" + componentType.getPropertyNames()[i], op, componentValue);
            }
        } else {
            parameters.addWhereWithParam(alias, propertyName, op, value);
        }
    } else {
        if (!"=".equals(op) && !"<>".equals(op)) {
            throw new AuditException("This type of operation: " + op + " (" + entityName + "." + propertyName + ") isn't supported and can't be used in queries.");
        }
        Object id = relatedEntity.getIdMapper().mapToIdFromEntity(value);
        relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, alias, null, "=".equals(op));
    }
}
Also used : ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) ComponentType(org.hibernate.type.ComponentType) RelationDescription(org.hibernate.envers.internal.entities.RelationDescription) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) AuditException(org.hibernate.envers.exception.AuditException)

Example 4 with RelationDescription

use of org.hibernate.envers.internal.entities.RelationDescription in project hibernate-orm by hibernate.

the class BaseEnversCollectionEventListener method searchForRelationDescription.

/**
 * Looks up a relation description corresponding to the given property in the given entity. If no description is
 * found in the given entity, the parent entity is checked (so that inherited relations work).
 *
 * @param entityName Name of the entity, in which to start looking.
 * @param referencingPropertyName The name of the property.
 *
 * @return A found relation description corresponding to the given entity or {@code null}, if no description can
 *         be found.
 */
private RelationDescription searchForRelationDescription(String entityName, String referencingPropertyName) {
    final EntityConfiguration configuration = getEnversService().getEntitiesConfigurations().get(entityName);
    final String propertyName = sanitizeReferencingPropertyName(referencingPropertyName);
    final RelationDescription rd = configuration.getRelationDescription(propertyName);
    if (rd == null && configuration.getParentEntityName() != null) {
        return searchForRelationDescription(configuration.getParentEntityName(), propertyName);
    }
    return rd;
}
Also used : EntityConfiguration(org.hibernate.envers.internal.entities.EntityConfiguration) RelationDescription(org.hibernate.envers.internal.entities.RelationDescription)

Example 5 with RelationDescription

use of org.hibernate.envers.internal.entities.RelationDescription in project hibernate-orm by hibernate.

the class RelatedAuditEqualityExpression 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("This criterion can only be used on a property that is a relation to another property.");
    }
    relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, alias, null, equals);
}
Also used : RelationDescription(org.hibernate.envers.internal.entities.RelationDescription) AuditException(org.hibernate.envers.exception.AuditException)

Aggregations

RelationDescription (org.hibernate.envers.internal.entities.RelationDescription)9 AuditException (org.hibernate.envers.exception.AuditException)3 AbstractCollectionPersister (org.hibernate.persister.collection.AbstractCollectionPersister)2 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)1 EntityConfiguration (org.hibernate.envers.internal.entities.EntityConfiguration)1 QueryParameterData (org.hibernate.envers.internal.entities.mapper.id.QueryParameterData)1 AuditProcess (org.hibernate.envers.internal.synchronization.AuditProcess)1 CollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.CollectionChangeWorkUnit)1 PersistentCollectionChangeWorkUnit (org.hibernate.envers.internal.synchronization.work.PersistentCollectionChangeWorkUnit)1 ComponentType (org.hibernate.type.ComponentType)1 Type (org.hibernate.type.Type)1