Skip to content

Commit

Permalink
Fixed querying unqualified extension items (MID-2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed May 24, 2016
1 parent 9d73d84 commit 9f2d5d0
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 55 deletions.
4 changes: 4 additions & 0 deletions repo/repo-sql-impl-test/pom.xml
Expand Up @@ -103,6 +103,10 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -487,4 +487,52 @@ public void testResourceUp() throws SchemaException {
assertTrue(result.isSuccess());
assertEquals("Should find one resource", 1, resources.size());
}

@Test
public void testMultivaluedExtensionPropertySubstringQualified() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext)
.item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "multivalued")).contains("slava")
.build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> resources = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find one object", 1, resources.size());
}

@Test
public void testMultivaluedExtensionPropertyEqualsQualified() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext)
.item(ObjectType.F_EXTENSION, new QName("http://example.com/p", "multivalued")).eq("Bratislava")
.build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> resources = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find one object", 1, resources.size());
}

@Test
public void testMultivaluedExtensionPropertySubstringUnqualified() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext)
.item(ObjectType.F_EXTENSION, new QName("multivalued")).contains("slava")
.build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> resources = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find one object", 1, resources.size());
}

@Test
public void testMultivaluedExtensionPropertyEqualsUnqualified() throws SchemaException {
ObjectQuery query = QueryBuilder.queryFor(GenericObjectType.class, prismContext)
.item(ObjectType.F_EXTENSION, new QName("multivalued")).eq("Bratislava")
.build();
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> resources = repositoryService.searchObjects(GenericObjectType.class, query, null, result);
result.recomputeStatus();
assertTrue(result.isSuccess());
assertEquals("Should find one object", 1, resources.size());
}
}
3 changes: 3 additions & 0 deletions repo/repo-sql-impl-test/src/test/resources/basic/objects.xml
Expand Up @@ -648,6 +648,9 @@
<t:norm>userx00002</t:norm>
</p:polyType>
<p:skipAutogeneration>true</p:skipAutogeneration>
<p:multivalued>Bratislava</p:multivalued>
<p:multivalued>Levice</p:multivalued>
<p:multivalued>Kalna</p:multivalued>
</extension>
<objectType>http://myself.me/schemas/objects#SampleConfigType</objectType>
</genericObject>
Expand Down
Expand Up @@ -98,6 +98,13 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="multivalued" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:appinfo>
<a:indexed>true</a:indexed>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand Down
Expand Up @@ -55,6 +55,6 @@ public RQuery interpret(ObjectQuery query, Class<? extends Containerable> type,
QueryInterpreter2 interpreter = new QueryInterpreter2(repoConfiguration);
RootHibernateQuery hibernateQuery = interpreter.interpret(query, type, options, prismContext, countingObjects, session);

return new RQueryImpl(hibernateQuery.getAsHqlQuery(session));
return new RQueryImpl(hibernateQuery.getAsHqlQuery(session), hibernateQuery);
}
}
Expand Up @@ -17,8 +17,10 @@
package com.evolveum.midpoint.repo.sql.query2;

import com.evolveum.midpoint.repo.sql.query.RQuery;
import com.evolveum.midpoint.repo.sql.query2.hqm.RootHibernateQuery;
import org.apache.commons.lang.Validate;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;

Expand All @@ -29,11 +31,13 @@
*/
public class RQueryImpl implements RQuery {

private RootHibernateQuery querySource; // only for diagnostic purposes
private org.hibernate.Query query;

public RQueryImpl(org.hibernate.Query query) {
public RQueryImpl(Query query, RootHibernateQuery querySource) {
Validate.notNull(query, "Query must not be null.");
this.query = query;
this.querySource = querySource;
}

@Override
Expand All @@ -54,4 +58,8 @@ public ScrollableResults scroll(ScrollMode mode) throws HibernateException {
public org.hibernate.Query getQuery() {
return query;
}

public RootHibernateQuery getQuerySource() {
return querySource;
}
}
Expand Up @@ -43,8 +43,7 @@ protected String getDebugDumpClassName() {

@Override
public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDefinition) throws QueryException {
QName itemName = ItemPath.asSingleName(path);
if (itemName == null) {
if (ItemPath.asSingleName(path) == null) {
throw new QueryException("Couldn't resolve paths other than those in the form of single name in extension/attributes container: " + path);
}
if (itemDefinition == null) {
Expand All @@ -62,7 +61,7 @@ public DataSearchResult nextLinkDefinition(ItemPath path, ItemDefinition itemDef

CollectionSpecification collSpec = itemDefinition.isSingleValue() ? null : new CollectionSpecification();
JpaAnyPropertyDefinition anyPropDefinition = new JpaAnyPropertyDefinition(Object.class, null); // TODO
JpaLinkDefinition linkDefinition = new JpaAnyPropertyLinkDefinition(itemName, jpaName, collSpec, ownerType, anyPropDefinition);
JpaLinkDefinition linkDefinition = new JpaAnyPropertyLinkDefinition(itemDefinition.getName(), jpaName, collSpec, ownerType, anyPropDefinition);
DataSearchResult result = new DataSearchResult(linkDefinition, ItemPath.EMPTY_PATH);
return result;
}
Expand Down
Expand Up @@ -65,7 +65,11 @@ public String addParameter(String prefix, Object value) {
return addParameter(prefix, value, null);
}

private String findFreeName(String prefix) {
public Map<String, QueryParameterValue> getParameters() {
return parameters;
}

private String findFreeName(String prefix) {
int i = 1;
for (;;) {
String name = i == 1 ? prefix : prefix+i;
Expand Down

0 comments on commit 9f2d5d0

Please sign in to comment.