use of org.hibernate.envers.exception.AuditException in project hibernate-orm by hibernate.
the class AuditReaderImpl method findRevision.
@Override
@SuppressWarnings({ "unchecked" })
public <T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException, RevisionDoesNotExistException, IllegalStateException {
revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Set<Number> revisions = new HashSet<>(1);
revisions.add(revision);
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
try {
final T revisionData = (T) query.uniqueResult();
if (revisionData == null) {
throw new RevisionDoesNotExistException(revision);
}
return revisionData;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.envers.exception.AuditException in project hibernate-orm by hibernate.
the class AuditReaderImpl method getRevisionNumberForDate.
@Override
public Number getRevisionNumberForDate(Date date) {
checkNotNull(date, "Date of revision");
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionNumberForDateQuery(session, date);
try {
final Number res = (Number) query.uniqueResult();
if (res == null) {
throw new RevisionDoesNotExistException(date);
}
return res;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
}
use of org.hibernate.envers.exception.AuditException 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.exception.AuditException 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.exception.AuditException 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