io.agrest.cayenne.processor.select.ViaQueryWithParentExpResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agrest-cayenne Show documentation
Show all versions of agrest-cayenne Show documentation
Cayenne backend for Agrest
package io.agrest.cayenne.processor.select;
import io.agrest.AgObjectId;
import io.agrest.CompoundObjectId;
import io.agrest.NestedResourceEntity;
import io.agrest.SimpleObjectId;
import io.agrest.cayenne.persister.ICayennePersister;
import io.agrest.cayenne.processor.CayenneProcessor;
import io.agrest.cayenne.processor.ICayenneQueryAssembler;
import io.agrest.meta.AgAttribute;
import io.agrest.property.NestedEntityListResultReader;
import io.agrest.property.NestedEntityResultReader;
import io.agrest.property.PropertyReader;
import io.agrest.resolver.BaseNestedDataResolver;
import io.agrest.runtime.processor.select.SelectContext;
import org.apache.cayenne.DataObject;
import org.apache.cayenne.query.SelectQuery;
import java.util.*;
import java.util.function.BiConsumer;
/**
* A nested resolver that builds a database query using a qualifier from the parent entity. This is the default nested
* resolver used by Cayenne backend.
*
* @since 3.4
*/
public class ViaQueryWithParentExpResolver extends BaseNestedDataResolver {
protected ICayenneQueryAssembler queryAssembler;
protected ICayennePersister persister;
public ViaQueryWithParentExpResolver(ICayenneQueryAssembler queryAssembler, ICayennePersister persister) {
this.queryAssembler = queryAssembler;
this.persister = persister;
}
@Override
protected void doOnParentQueryAssembled(NestedResourceEntity entity, SelectContext> context) {
CayenneProcessor.setQuery(entity, queryAssembler.createQueryWithParentQualifier(entity));
}
@Override
protected Iterable doOnParentDataResolved(
NestedResourceEntity entity,
Iterable> parentData,
SelectContext> context) {
// no parents, no need to fetch children
Iterator> parentIt = parentData.iterator();
if (!parentIt.hasNext()) {
return Collections.emptyList();
}
SelectQuery