Skip to content

Commit

Permalink
Fixed MID-3390: Repo query for two abstract types (or more OIDs in OR…
Browse files Browse the repository at this point in the history
…-clause) fail
  • Loading branch information
mederly committed Dec 5, 2016
1 parent 68fe045 commit e7980b2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Expand Up @@ -1397,7 +1397,7 @@ public void test330InOidTest() throws Exception {
"from\n" +
" RObject o\n" +
"where\n" +
" o.oid in :oid\n";
" o.oid in (:oid)\n";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
Expand All @@ -1417,7 +1417,7 @@ public void test335OwnerInOidTest() throws Exception {
"from\n" +
" RAccessCertificationCase a\n" +
"where\n" +
" a.ownerOid in :ownerOid";
" a.ownerOid in (:ownerOid)";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
Expand Down Expand Up @@ -2021,7 +2021,7 @@ public void test550queryObjectClassTypeAbstractRole() throws Exception {
"from\n" +
" RObject o\n" +
"where\n" +
" o.objectTypeClass in :objectTypeClass";
" o.objectTypeClass in (:objectTypeClass)";

assertEqualsIgnoreWhitespace(expected, real);
} finally {
Expand Down Expand Up @@ -2292,6 +2292,36 @@ public void test600QueryObjectypeByTypeComplex() throws Exception {
}
}

@Test
public void test601QueryObjectypeByTwoAbstractTypes() throws Exception {
Session session = open();
try {
ObjectQuery query = QueryBuilder.queryFor(ObjectType.class, prismContext)
.type(FocusType.class).block().endBlock()
.or().type(AbstractRoleType.class).block().endBlock()
.build();
String real = getInterpretedQuery2(session, ObjectType.class, query);
String expected = "select\n"
+ " o.fullObject,\n"
+ " o.stringsCount,\n"
+ " o.longsCount,\n"
+ " o.datesCount,\n"
+ " o.referencesCount,\n"
+ " o.polysCount,\n"
+ " o.booleansCount\n"
+ "from\n"
+ " RObject o\n"
+ "where\n"
+ " (\n"
+ " o.objectTypeClass in (:objectTypeClass) or\n"
+ " o.objectTypeClass in (:objectTypeClass2)\n"
+ " )\n";
assertEqualsIgnoreWhitespace(expected, real);
} finally {
close(session);
}
}

@Test
public void test605QueryObjectypeByTypeAndReference() throws Exception {
Session session = open();
Expand Down
Expand Up @@ -48,7 +48,12 @@ public void dumpToHql(StringBuilder sb, int indent) {
if (values != null) {
String parameterNamePrefix = createParameterName(propertyPath);
String parameterName = rootHibernateQuery.addParameter(parameterNamePrefix, values); // TODO special treatment of collections?
sb.append(propertyPath).append(" in :").append(parameterName);
// these parentheses are here because of hibernate bug, manifesting itself as MID-3390
boolean useParentheses = values.size() != 1; // just a (quite dubious) optimization
sb.append(propertyPath).append(" in ")
.append(useParentheses ? "(" : "")
.append(":").append(parameterName)
.append(useParentheses ? ")" : "");
} else {
sb.append(propertyPath).append(" in (").append(innerQueryText).append(")");
}
Expand Down

0 comments on commit e7980b2

Please sign in to comment.