From 1eec41a136b3405e104b6c9cc9aa200e3f8cd8fe Mon Sep 17 00:00:00 2001 From: Felix Feisst Date: Thu, 16 Mar 2017 21:02:08 +0100 Subject: [PATCH] HHH-11573 Query based on type expressions --- .../internal/tools/query/Parameters.java | 5 + .../hibernate/envers/query/AuditEntity.java | 44 ++++++- .../internal/EntityTypeAuditExpression.java | 47 +++++++ .../query/EntityTypeQueryTest.java | 117 ++++++++++++++++++ 4 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 hibernate-envers/src/main/java/org/hibernate/envers/query/criteria/internal/EntityTypeAuditExpression.java create mode 100644 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/query/EntityTypeQueryTest.java diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java index 3212a26bfa..32507b54bd 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/query/Parameters.java @@ -482,6 +482,11 @@ public class Parameters { expressions.add( expression.toString() ); } + public void addEntityTypeRestriction(String alias, String entityName) { + String expression = String.format( "type(%s) = %s", alias, entityName ); + expressions.add( expression ); + } + private void append(StringBuilder sb, String toAppend, MutableBoolean isFirst) { if ( !isFirst.isSet() ) { sb.append( " " ).append( connective ).append( " " ); diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java index 5cf2889b70..9e7264e499 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/query/AuditEntity.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.List; import org.hibernate.envers.RevisionType; +import org.hibernate.envers.internal.tools.EntityTools; import org.hibernate.envers.query.criteria.AuditConjunction; import org.hibernate.envers.query.criteria.AuditCriterion; import org.hibernate.envers.query.criteria.AuditDisjunction; @@ -18,6 +19,7 @@ import org.hibernate.envers.query.criteria.AuditFunction; import org.hibernate.envers.query.criteria.AuditId; import org.hibernate.envers.query.criteria.AuditProperty; import org.hibernate.envers.query.criteria.AuditRelatedId; +import org.hibernate.envers.query.criteria.internal.EntityTypeAuditExpression; import org.hibernate.envers.query.criteria.internal.LogicalAuditExpression; import org.hibernate.envers.query.criteria.internal.NotAuditExpression; import org.hibernate.envers.query.internal.property.EntityPropertyName; @@ -192,7 +194,7 @@ public class AuditEntity { *
  • AuditEntity.function("concat", AuditEntity.function("upper", AuditEntity.property("prop1")), * AuditEntity.function("substring", AuditEntity.property("prop2"), 1, 2))
  • * - * + * * @param function the name of the function * @param arguments the arguments of the function. A function argument can either be *