use of com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException in project cuba by cuba-platform.
the class EntityPointer method next.
@Override
public Pointer next(DomainModel model, String field) {
Attribute attribute = entity.getAttributeByName(field);
if (attribute == null) {
return NoPointer.instance();
}
if (!attribute.isEntityReferenceAttribute()) {
return new SimpleAttributePointer(entity, attribute);
}
String targetEntityName = attribute.getReferencedEntityName();
try {
JpqlEntityModel targetEntity = model.getEntityByName(targetEntityName);
return attribute.isCollection() ? new CollectionPointer(targetEntity) : new EntityPointer(targetEntity);
} catch (UnknownEntityNameException e) {
return NoPointer.instance();
}
}
use of com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException in project cuba by cuba-platform.
the class QueryTreeTransformer method getPathNodesForOrderBy.
protected List<PathNode> getPathNodesForOrderBy(PathEntityReference pathEntityReference) {
List<PathNode> pathNodes = new ArrayList<>();
String entityName = pathEntityReference.getPathStartingEntityName();
PathNode pathNode = pathEntityReference.getPathNode();
try {
JpqlEntityModel entity = model.getEntityByName(entityName);
String currentVariableName = pathNode.getEntityVariableName();
PathNode currentPathNode = new PathNode(pathNode.getToken(), currentVariableName);
for (int i = 0; i < pathNode.getChildCount(); i++) {
String fieldName = pathNode.getChild(i).toString();
Attribute entityAttribute = entity.getAttributeByName(fieldName);
if (entityAttribute.isEntityReferenceAttribute() && !entityAttribute.isEmbedded()) {
currentPathNode.addDefaultChild(fieldName);
pathNodes.add(currentPathNode);
currentVariableName = currentPathNode.asPathString('_');
currentPathNode = new PathNode(pathNode.getToken(), currentVariableName);
} else {
currentPathNode.addDefaultChild(fieldName);
}
if (entityAttribute.isEntityReferenceAttribute()) {
entityName = entityAttribute.getReferencedEntityName();
entity = model.getEntityByName(entityName);
}
}
pathNodes.add(currentPathNode);
} catch (UnknownEntityNameException e) {
throw new RuntimeException(String.format("Could not find entity by name %s", entityName), e);
}
return pathNodes;
}
use of com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException in project cuba by cuba-platform.
the class BaseJoinNode method identifyVariableEntity.
public void identifyVariableEntity(DomainModel model, Deque<QueryVariableContext> stack, List<ErrorRec> invalidNodes) {
String variableName = getVariableName();
if (variableName == null) {
invalidNodes.add(new ErrorRec(this, "No variable name found"));
return;
}
List children = getChildren();
if (children == null || children.size() == 0) {
invalidNodes.add(new ErrorRec(this, "No children found"));
return;
}
CommonTree child0 = (CommonTree) children.get(0);
if (child0 instanceof CommonErrorNode) {
invalidNodes.add(new ErrorRec(this, "Child 0 is an error node"));
return;
}
QueryVariableContext queryVC = stack.peekLast();
if (child0 instanceof PathNode) {
PathNode pathNode = (PathNode) child0;
Pointer pointer = pathNode.resolvePointer(model, queryVC);
if (pointer instanceof NoPointer) {
invalidNodes.add(new ErrorRec(this, "Cannot resolve joined entity"));
} else if (pointer instanceof SimpleAttributePointer) {
invalidNodes.add(new ErrorRec(this, "Joined entity resolved to a non-entity attribute"));
} else if (pointer instanceof EntityPointer) {
queryVC.addEntityVariable(variableName, ((EntityPointer) pointer).getEntity());
} else if (pointer instanceof CollectionPointer) {
queryVC.addEntityVariable(variableName, ((CollectionPointer) pointer).getEntity());
} else {
invalidNodes.add(new ErrorRec(this, "Unexpected pointer variable type: " + pointer.getClass()));
}
} else {
// this special case is for "join X on X.a = Y.b" query. Entity name would be just text in the child node
try {
queryVC.addEntityVariable(variableName, model.getEntityByName(child0.getText()));
} catch (UnknownEntityNameException e) {
invalidNodes.add(new ErrorRec(this, "Could not find entity for name " + child0.getText()));
}
}
}
Aggregations