use of org.apache.cayenne.ejbql.parser.Node in project cayenne by apache.
the class EJBQLPathAnaliserTranslator method processParameter.
private void processParameter(String boundName, EJBQLExpression expression) {
Object object = context.getBoundParameter(boundName);
Map<?, ?> map = null;
if (object instanceof Persistent) {
map = ((Persistent) object).getObjectId().getIdSnapshot();
} else if (object instanceof ObjectId) {
map = ((ObjectId) object).getIdSnapshot();
} else if (object instanceof Map) {
map = (Map<?, ?>) object;
}
if (map != null) {
if (map.size() == 1) {
context.rebindParameter(boundName, map.values().iterator().next());
} else {
addMultiColumnOperand(EJBQLMultiColumnOperand.getObjectOperand(context, map));
return;
}
}
if (object != null) {
context.append(" #bind($").append(boundName).append(")");
} else {
String type = null;
Node parent = ((SimpleNode) expression).jjtGetParent();
context.pushMarker("@processParameter", true);
EJBQLPathAnaliserTranslator translator = new EJBQLPathAnaliserTranslator(context);
parent.visit(translator);
translator.visitPath(parent, parent.getChildrenCount());
String id = translator.idPath;
if (id != null) {
ClassDescriptor descriptor = context.getEntityDescriptor(id);
if (descriptor == null) {
throw new EJBQLException("Unmapped id variable: " + id);
}
String pathChunk = translator.lastPathComponent;
PropertyDescriptor property = descriptor.getProperty(pathChunk);
if (property instanceof AttributeProperty) {
String atrType = ((AttributeProperty) property).getAttribute().getType();
type = TypesMapping.getSqlNameByType(TypesMapping.getSqlTypeByJava(atrType));
}
}
context.popMarker();
if (type == null) {
type = "VARCHAR";
}
// this is a hack to prevent execptions on DB's like Derby for
// expressions
// "X = NULL". The 'VARCHAR' parameter is totally bogus, but seems
// to work on
// all tested DB's... Also note what JPA spec, chapter 4.11 says:
// "Comparison
// or arithmetic operations with a NULL value always yield an
// unknown value."
// TODO: andrus 6/28/2007 Ideally we should track the type of the
// current
// expression to provide a meaningful type.
context.append(" #bind($").append(boundName).append(" '" + type + "')");
}
}
use of org.apache.cayenne.ejbql.parser.Node in project cayenne by apache.
the class OracleEJBQLConditionTranslator method swapNodeChildren.
/**
* @since 4.0
*/
private void swapNodeChildren(EJBQLExpression expression, int i, int j) {
if (!(expression instanceof Node)) {
return;
}
Node node = (Node) expression;
Node tmp = node.jjtGetChild(i);
node.jjtAddChild(node.jjtGetChild(j), i);
node.jjtAddChild(tmp, j);
}
Aggregations