use of com.haulmont.cuba.core.sys.jpql.tree.PathNode in project cuba by cuba-platform.
the class QueryParserAstBased method isEntitySelect.
@Override
public boolean isEntitySelect(String targetEntity) {
List<PathNode> returnedPathNodes = getQueryAnalyzer().getReturnedPathNodes();
if (CollectionUtils.isEmpty(returnedPathNodes) || returnedPathNodes.size() > 1) {
return false;
}
PathNode pathNode = returnedPathNodes.get(0);
String targetEntityAlias = getQueryAnalyzer().getRootEntityVariableName(targetEntity);
return targetEntityAlias.equals(pathNode.getEntityVariableName()) && CollectionUtils.isEmpty(pathNode.getChildren());
}
use of com.haulmont.cuba.core.sys.jpql.tree.PathNode in project cuba by cuba-platform.
the class EntityReferenceInferer method infer.
public EntityReference infer(QueryTreeTransformer queryAnalyzer) {
String entityVariableNameInQuery = queryAnalyzer.getRootEntityVariableName(entityName);
if (entityVariableNameInQuery != null) {
return new VariableEntityReference(entityName, entityVariableNameInQuery);
}
PathNode path = queryAnalyzer.getSelectedPathNode();
JpqlEntityModel entity = queryAnalyzer.getSelectedEntity(path);
if (!(entity instanceof VirtualJpqlEntityModel) && entity.getName().equals(entityName)) {
JpqlEntityModel pathStartingEntity = queryAnalyzer.getRootQueryVariableContext().getEntityByVariableName(path.getEntityVariableName());
return new PathEntityReference(path, pathStartingEntity.getName());
}
throw new RuntimeException(String.format("No variable or selected field of entity %s found in query", entityName));
}
use of com.haulmont.cuba.core.sys.jpql.tree.PathNode in project cuba by cuba-platform.
the class EntitiesFinder method resolveEntityNames.
protected void resolveEntityNames(Set<String> entityNames, PathNode node, DomainModel model, QueryVariableContext queryVariableContext) {
List<Pointer> pointers = node.resolveTransitionalPointers(model, queryVariableContext);
pointers.stream().filter(pointer -> pointer instanceof HasEntityPointer).forEach(pointer -> {
JpqlEntityModel entityModel = ((HasEntityPointer) pointer).getEntity();
if (entityModel != null) {
entityNames.add(entityModel.getName());
}
});
}
use of com.haulmont.cuba.core.sys.jpql.tree.PathNode in project cuba by cuba-platform.
the class PathEntityReference method addFieldPath.
@Override
public PathEntityReference addFieldPath(String fieldPath) {
PathNode newPathNode = pathNode.dupNode();
newPathNode.addDefaultChildren(fieldPath);
return new PathEntityReference(newPathNode, pathStartingEntityName);
}
use of com.haulmont.cuba.core.sys.jpql.tree.PathNode in project cuba by cuba-platform.
the class VariableEntityReference method addFieldPath.
@Override
public PathEntityReference addFieldPath(String fieldPath) {
PathNode pathNode = new PathNode(JPA2Lexer.T_SELECTED_FIELD, entityVariableName);
pathNode.addDefaultChildren(fieldPath);
return new PathEntityReference(pathNode, entityName);
}
Aggregations