Author: adamw
Date: 2008-10-31 08:14:46 -0400 (Fri, 31 Oct 2008)
New Revision: 15463
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java
Log:
HHH-3575: fix with test
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java 2008-10-31
12:00:22 UTC (rev 15462)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditConjunction.java 2008-10-31
12:14:46 UTC (rev 15463)
@@ -48,8 +48,12 @@
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb,
Parameters parameters) {
Parameters andParameters = parameters.addSubParameters(Parameters.AND);
- for (AuditCriterion criterion : criterions) {
- criterion.addToQuery(verCfg, entityName, qb, andParameters);
+ if (criterions.size() == 0) {
+ andParameters.addWhere("1", false, "=", "1",
false);
+ } else {
+ for (AuditCriterion criterion : criterions) {
+ criterion.addToQuery(verCfg, entityName, qb, andParameters);
+ }
}
}
}
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java 2008-10-31
12:00:22 UTC (rev 15462)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditDisjunction.java 2008-10-31
12:14:46 UTC (rev 15463)
@@ -48,8 +48,12 @@
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb,
Parameters parameters) {
Parameters orParameters = parameters.addSubParameters(Parameters.OR);
- for (AuditCriterion criterion : criterions) {
- criterion.addToQuery(verCfg, entityName, qb, orParameters);
+ if (criterions.size() == 0) {
+ orParameters.addWhere("0", false, "=", "1",
false);
+ } else {
+ for (AuditCriterion criterion : criterions) {
+ criterion.addToQuery(verCfg, entityName, qb, orParameters);
+ }
}
}
}
\ No newline at end of file
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java
===================================================================
---
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java 2008-10-31
12:00:22 UTC (rev 15462)
+++
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractVersionsQuery.java 2008-10-31
12:14:46 UTC (rev 15463)
@@ -84,6 +84,8 @@
qb.build(querySb, queryParamValues);
+ System.out.println("QUERY: " + querySb.toString());
+
Query query = versionsReader.getSession().createQuery(querySb.toString());
for (Map.Entry<String, Object> paramValue : queryParamValues.entrySet()) {
query.setParameter(paramValue.getKey(), paramValue.getValue());
Modified:
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java
===================================================================
---
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java 2008-10-31
12:00:22 UTC (rev 15462)
+++
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java 2008-10-31
12:14:46 UTC (rev 15463)
@@ -240,4 +240,33 @@
assert result.get(1).equals(RevisionType.MOD);
assert result.get(2).equals(RevisionType.DEL);
}
+
+ @Test
+ public void testEmptyRevisionOfEntityQuery() {
+ List result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .getResultList();
+
+ assert result.size() == 7;
+ }
+
+ @Test
+ public void testEmptyConjunctionRevisionOfEntityQuery() {
+ List result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(AuditRestrictions.conjunction())
+ .getResultList();
+
+ assert result.size() == 7;
+ }
+
+ @Test
+ public void testEmptyDisjunctionRevisionOfEntityQuery() {
+ List result = getVersionsReader().createQuery()
+ .forRevisionsOfEntity(StrIntTestEntity.class, false, true)
+ .add(AuditRestrictions.disjunction())
+ .getResultList();
+
+ assert result.size() == 0;
+ }
}
Show replies by date