use of io.crnk.meta.model.MetaAttributePath in project crnk-framework by crnk-project.
the class JoinRegistry method getEntityAttribute.
public E getEntityAttribute(MetaAttributePath attrPath) {
MetaAttributePath associationPath = extractAssociationPath(attrPath);
MetaAttributePath primitivePath = attrPath.subPath(associationPath.length());
@SuppressWarnings("unchecked") E from = (E) getOrCreateJoin(associationPath);
if (primitivePath.length() == 0) {
return from;
}
MetaAttributePath currentPath = associationPath;
E criteriaPath = null;
for (MetaAttribute pathElement : primitivePath) {
currentPath = currentPath.concat(pathElement);
E currentCriteriaPath = criteriaPath != null ? criteriaPath : from;
if (pathElement instanceof MetaMapAttribute) {
if (criteriaPath != null)
throw new IllegalStateException("Cannot join to map");
criteriaPath = joinMap(currentCriteriaPath, pathElement);
} else {
// we may need to downcast if attribute is defined on a subtype
MetaDataObject parent = pathElement.getParent().asDataObject();
Class<?> pathType = parent.getImplementationClass();
Class<?> currentType = backend.getJavaElementType(currentCriteriaPath);
boolean isSubType = !pathType.isAssignableFrom(currentType);
if (isSubType) {
currentCriteriaPath = backend.joinSubType(currentCriteriaPath, pathType);
}
criteriaPath = backend.getAttribute(currentCriteriaPath, pathElement);
}
}
return criteriaPath;
}
use of io.crnk.meta.model.MetaAttributePath in project crnk-framework by crnk-project.
the class EntityGraphBuilderImpl method applyFetchPaths.
private <T> Subgraph<Object> applyFetchPaths(EntityGraph<T> graph, MetaAttributePath fetchPath) {
if (fetchPath.length() >= 2) {
// ensure parent is fetched
MetaAttributePath parentPath = fetchPath.subPath(0, fetchPath.length() - 1);
Subgraph<Object> parentGraph = applyFetchPaths(graph, parentPath);
return parentGraph.addSubgraph(fetchPath.toString());
} else {
return graph.addSubgraph(fetchPath.toString());
}
}
use of io.crnk.meta.model.MetaAttributePath in project crnk-framework by crnk-project.
the class EntityGraphBuilderImpl method build.
@Override
public <T> void build(EntityManager em, Query criteriaQuery, Class<T> entityClass, Set<MetaAttributePath> fetchPaths) {
EntityGraph<T> graph = em.createEntityGraph(entityClass);
for (MetaAttributePath fetchPath : fetchPaths) {
applyFetchPaths(graph, fetchPath);
}
criteriaQuery.setHint("javax.persistence.fetchgraph", graph);
}
use of io.crnk.meta.model.MetaAttributePath in project crnk-framework by crnk-project.
the class QueryFilterBuilder method filterSimpleOperation.
private P filterSimpleOperation(FilterSpec fs, MetaDataObject rootMeta) {
Object value = fs.getValue();
if (value instanceof Set) {
// HashSet not properly supported in ORM/JDBC, convert to
// list
Set<?> set = (Set<?>) value;
value = new ArrayList<Object>(set);
}
MetaAttributePath path = rootMeta.resolvePath(fs.getAttributePath(), attributeFinder);
path = enhanceAttributePath(path, value);
return backend.buildPredicate(fs.getOperator(), path, value);
}
use of io.crnk.meta.model.MetaAttributePath in project crnk-framework by crnk-project.
the class JoinRegistry method getOrCreateJoin.
private F getOrCreateJoin(MetaAttributePath srcPath, MetaAttribute targetAttr) {
MetaAttributePath path = srcPath.concat(targetAttr);
F parent = joinMap.get(srcPath);
F join = joinMap.get(path);
if (join == null) {
JoinType joinType = query.getJoinType(path);
join = backend.doJoin(targetAttr, joinType, parent);
joinMap.put(path, join);
}
return join;
}
Aggregations