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);
}
}
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, ")");
}
}
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));
}
}
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;
}
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);
}
Aggregations