use of org.apache.cayenne.ejbql.parser.SimpleNode 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 + "')");
}
}
Aggregations