Hi,
I came accross something that looks like a bug : I cannot use the Query API to
build a Query using a Where clause on an subtyped Property.
I get the following exception:
org.qi4j.runtime.query.QueryException: Unsupported property type:interface
test.SubtypedPropertyQueryTest$Name
at
org.qi4j.runtime.query.grammar.impl.PropertyReferenceImpl.<init>(PropertyReferenceImpl.java:88)
at
org.qi4j.runtime.query.proxy.PropertyReferenceProxy.<init>(PropertyReferenceProxy.java:49)
at
org.qi4j.runtime.query.proxy.MixinTypeProxy.invoke(MixinTypeProxy.java:122)
at test.$Proxy13.name(Unknown Source)
at
test.SubtypedPropertyQueryTest.givenAnEntityWithSubtypedPropertyWhenQueriedOnPropertyThenJustWork(SubtypedPropertyQueryTest.java:94)
Here is the complete unit test with one first test that query on a legacy
property and pass, the second one that query on a subtyped property and fail.
public class SubtypedPropertyQueryTest
extends AbstractQi4jTest
{
public void assemble(ModuleAssembly module)
throws AssemblyException
{
module.addEntities(FlatEntity.class, WoupsEntity.class);
module.addServices(MemoryEntityStoreService.class,
UuidIdentityGeneratorService.class);
new RdfMemoryStoreAssembler().assemble(module);
}
interface FlatEntity extends EntityComposite
{
Property<String> name();
}
interface WoupsEntity extends EntityComposite
{
Name name();
}
interface Name extends Property<String> { }
@Test
public void
givenAnEntityWithSimplePropertyWhenQueriedOnPropertyThenJustWork()
throws UnitOfWorkCompletionException
{
FlatEntity test;
{
UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
EntityBuilder<FlatEntity> builder =
uow.newEntityBuilder(FlatEntity.class);
test = builder.instance();
test.name().set("Bob");
test = builder.newInstance();
uow.complete();
}
{
UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
QueryBuilder<FlatEntity> queryBuilder =
queryBuilderFactory.newQueryBuilder(FlatEntity.class);
FlatEntity thingTemplate =
QueryExpressions.templateFor(FlatEntity.class);
queryBuilder.where(QueryExpressions.eq(thingTemplate.name(),
"Bob"));
Query<FlatEntity> query = queryBuilder.newQuery(uow);
query.maxResults(1);
FlatEntity foundByName = CollectionUtils.firstElementOrNull(query);
Assert.assertEquals("Bob", foundByName.name().get());
uow.complete();
}
}
// FIXME : This one do not work.
@Test
public void
givenAnEntityWithSubtypedPropertyWhenQueriedOnPropertyThenJustWork()
throws UnitOfWorkCompletionException
{
WoupsEntity test;
{
UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
EntityBuilder<WoupsEntity> builder =
uow.newEntityBuilder(WoupsEntity.class);
test = builder.instance();
test.name().set("Bob");
test = builder.newInstance();
uow.complete();
}
{
UnitOfWork uow = unitOfWorkFactory.newUnitOfWork();
QueryBuilder<WoupsEntity> queryBuilder =
queryBuilderFactory.newQueryBuilder(WoupsEntity.class);
WoupsEntity thingTemplate =
QueryExpressions.templateFor(WoupsEntity.class);
queryBuilder.where(QueryExpressions.eq(thingTemplate.name(),
"Bob"));
Query<WoupsEntity> query = queryBuilder.newQuery(uow);
query.maxResults(1);
WoupsEntity foundByName = CollectionUtils.firstElementOrNull(query);
Assert.assertEquals("Bob", foundByName.name().get());
uow.complete();
}
}
}
As subtyping Property is encouraged, I expected queries to work on them.
Hope this code can help you fix the issue.
BTW I registered in JIRA and wanted to fill an issue but it seems I do not have
the required credentials.
Paul
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev