Search in sources :

Example 1 with PathNode

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());
}
Also used : PathNode(com.haulmont.cuba.core.sys.jpql.tree.PathNode)

Example 2 with PathNode

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));
}
Also used : VirtualJpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel) PathNode(com.haulmont.cuba.core.sys.jpql.tree.PathNode) VirtualJpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)

Example 3 with PathNode

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());
        }
    });
}
Also used : HashSet(java.util.HashSet) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel) Pointer(com.haulmont.cuba.core.sys.jpql.pointer.Pointer) CommonTree(org.antlr.runtime.tree.CommonTree) List(java.util.List) IdentificationVariableNode(com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode) Set(java.util.Set) HasEntityPointer(com.haulmont.cuba.core.sys.jpql.pointer.HasEntityPointer) TreeVisitorAction(org.antlr.runtime.tree.TreeVisitorAction) PathNode(com.haulmont.cuba.core.sys.jpql.tree.PathNode) JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode) ArrayList(java.util.ArrayList) HasEntityPointer(com.haulmont.cuba.core.sys.jpql.pointer.HasEntityPointer) Pointer(com.haulmont.cuba.core.sys.jpql.pointer.Pointer) HasEntityPointer(com.haulmont.cuba.core.sys.jpql.pointer.HasEntityPointer) JpqlEntityModel(com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)

Example 4 with PathNode

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);
}
Also used : PathNode(com.haulmont.cuba.core.sys.jpql.tree.PathNode)

Example 5 with PathNode

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);
}
Also used : PathNode(com.haulmont.cuba.core.sys.jpql.tree.PathNode)

Aggregations

PathNode (com.haulmont.cuba.core.sys.jpql.tree.PathNode)8 JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)4 IdentificationVariableNode (com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode)2 ArrayList (java.util.ArrayList)2 Attribute (com.haulmont.cuba.core.sys.jpql.model.Attribute)1 VirtualJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel)1 HasEntityPointer (com.haulmont.cuba.core.sys.jpql.pointer.HasEntityPointer)1 Pointer (com.haulmont.cuba.core.sys.jpql.pointer.Pointer)1 JoinVariableNode (com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CommonTree (org.antlr.runtime.tree.CommonTree)1 TreeVisitor (org.antlr.runtime.tree.TreeVisitor)1 TreeVisitorAction (org.antlr.runtime.tree.TreeVisitorAction)1