use of org.hibernate.envers.exception.AuditException in project hibernate-orm by hibernate.
the class AuditReaderImpl method find.
@Override
@SuppressWarnings({ "unchecked" })
public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision, boolean includeDeletions) throws IllegalArgumentException, NotAuditedException, IllegalStateException {
cls = getTargetClassIfProxied(cls);
checkNotNull(cls, "Entity class");
checkNotNull(entityName, "Entity name");
checkNotNull(primaryKey, "Primary key");
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
if (firstLevelCache.contains(entityName, revision, primaryKey)) {
return (T) firstLevelCache.get(entityName, revision, primaryKey);
}
Object result;
try {
// The result is put into the cache by the entity instantiator called from the query
result = createQuery().forEntitiesAtRevision(cls, entityName, revision, includeDeletions).add(AuditEntity.id().eq(primaryKey)).getSingleResult();
} catch (NoResultException e) {
result = null;
} catch (NonUniqueResultException e) {
throw new AuditException(e);
}
return (T) result;
}
use of org.hibernate.envers.exception.AuditException in project hibernate-orm by hibernate.
the class AuditReaderImpl method findRevisions.
@Override
@SuppressWarnings({ "unchecked" })
public <T> Map<Number, T> findRevisions(Class<T> revisionEntityClass, Set<Number> revisions) throws IllegalArgumentException, IllegalStateException {
revisionEntityClass = getTargetClassIfProxied(revisionEntityClass);
final Map<Number, T> result = new HashMap<>(revisions.size());
for (Number revision : revisions) {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
}
checkSession();
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
try {
final List<?> revisionList = query.getResultList();
for (Object revision : revisionList) {
final Number revNo = enversService.getRevisionInfoNumberReader().getRevisionNumber(revision);
result.put(revNo, (T) revision);
}
return result;
} catch (HibernateException e) {
throw new AuditException(e);
}
}
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