Search in sources :

Example 1 with VirtualJpqlEntityModel

use of com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel 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)

Aggregations

JpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.JpqlEntityModel)1 VirtualJpqlEntityModel (com.haulmont.cuba.core.sys.jpql.model.VirtualJpqlEntityModel)1 PathNode (com.haulmont.cuba.core.sys.jpql.tree.PathNode)1