use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.
the class MapExpressionImpl method containsEntry.
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.MapExpression#containsEntry(java.util.Map.Entry)
*/
public BooleanExpression containsEntry(Entry<K, V> entry) {
List<org.datanucleus.query.expression.Expression> args = new ArrayList();
args.add(new Literal(entry));
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsEntry", args);
return new BooleanExpressionImpl(invokeExpr);
}
use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.
the class MapExpressionImpl method containsValue.
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.MapExpression#containsValue(java.lang.Object)
*/
public BooleanExpression containsValue(V value) {
List<org.datanucleus.query.expression.Expression> args = new ArrayList();
args.add(new Literal(value));
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsValue", args);
return new BooleanExpressionImpl(invokeExpr);
}
use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.
the class MapExpressionImpl method containsKey.
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.MapExpression#containsKey(java.lang.Object)
*/
public BooleanExpression containsKey(K key) {
List<org.datanucleus.query.expression.Expression> args = new ArrayList();
args.add(new Literal(key));
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "containsKey", args);
return new BooleanExpressionImpl(invokeExpr);
}
use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.
the class AbstractJDOQLTypedQuery method getJDOQLForExpression.
public String getJDOQLForExpression(Expression expr) {
if (expr instanceof DyadicExpression) {
DyadicExpression dyExpr = (DyadicExpression) expr;
Expression left = dyExpr.getLeft();
Expression right = dyExpr.getRight();
StringBuilder str = new StringBuilder("(");
if (dyExpr.getOperator() == Expression.OP_DISTINCT) {
// Distinct goes in front of the left expression
str.append("DISTINCT ");
}
if (left != null) {
str.append(getJDOQLForExpression(left));
}
// Special cases
if (dyExpr.getOperator() == Expression.OP_AND) {
str.append(" && ");
} else if (dyExpr.getOperator() == Expression.OP_OR) {
str.append(" || ");
} else if (dyExpr.getOperator() == Expression.OP_ADD) {
str.append(" + ");
} else if (dyExpr.getOperator() == Expression.OP_SUB) {
str.append(" - ");
} else if (dyExpr.getOperator() == Expression.OP_MUL) {
str.append(" * ");
} else if (dyExpr.getOperator() == Expression.OP_DIV) {
str.append(" / ");
} else if (dyExpr.getOperator() == Expression.OP_EQ) {
str.append(" == ");
} else if (dyExpr.getOperator() == Expression.OP_GT) {
str.append(" > ");
} else if (dyExpr.getOperator() == Expression.OP_LT) {
str.append(" < ");
} else if (dyExpr.getOperator() == Expression.OP_GTEQ) {
str.append(" >= ");
} else if (dyExpr.getOperator() == Expression.OP_LTEQ) {
str.append(" <= ");
} else if (dyExpr.getOperator() == Expression.OP_NOTEQ) {
str.append(" != ");
} else if (dyExpr.getOperator() == Expression.OP_DISTINCT) {
// Processed above
} else {
// TODO Support other operators
throw new UnsupportedOperationException("Dont currently support operator " + dyExpr.getOperator() + " in JDOQL conversion");
}
if (right != null) {
str.append(getJDOQLForExpression(right));
}
str.append(")");
return str.toString();
} else if (expr instanceof PrimaryExpression) {
PrimaryExpression primExpr = (PrimaryExpression) expr;
if (primExpr.getLeft() != null) {
return getJDOQLForExpression(primExpr.getLeft()) + "." + primExpr.getId();
}
return primExpr.getId();
} else if (expr instanceof ParameterExpression) {
ParameterExpression paramExpr = (ParameterExpression) expr;
if (paramExpr.getId() != null) {
return ":" + paramExpr.getId();
}
return "?" + paramExpr.getPosition();
} else if (expr instanceof VariableExpression) {
VariableExpression varExpr = (VariableExpression) expr;
return varExpr.getId();
} else if (expr instanceof InvokeExpression) {
InvokeExpression invExpr = (InvokeExpression) expr;
StringBuilder str = new StringBuilder();
if (invExpr.getLeft() != null) {
str.append(getJDOQLForExpression(invExpr.getLeft())).append(".");
}
str.append(invExpr.getOperation());
str.append("(");
List<Expression> args = invExpr.getArguments();
if (args != null) {
Iterator<Expression> iter = args.iterator();
while (iter.hasNext()) {
str.append(getJDOQLForExpression(iter.next()));
if (iter.hasNext()) {
str.append(",");
}
}
}
str.append(")");
return str.toString();
} else if (expr instanceof Literal) {
Literal litExpr = (Literal) expr;
Object value = litExpr.getLiteral();
if (value instanceof String || value instanceof Character) {
return "'" + value.toString() + "'";
} else if (value instanceof Boolean) {
return ((Boolean) value ? "TRUE" : "FALSE");
} else {
if (litExpr.getLiteral() == null) {
return "null";
}
return litExpr.getLiteral().toString();
}
} else {
throw new UnsupportedOperationException("Dont currently support " + expr.getClass().getName() + " in JDOQLHelper");
}
}
use of org.datanucleus.query.expression.InvokeExpression in project datanucleus-api-jdo by datanucleus.
the class StringExpressionImpl method substring.
/* (non-Javadoc)
* @see org.datanucleus.query.typesafe.StringExpression#substring(int)
*/
public StringExpression substring(int pos) {
List<org.datanucleus.query.expression.Expression> args = new ArrayList();
args.add(new Literal(pos));
org.datanucleus.query.expression.Expression invokeExpr = new InvokeExpression(queryExpr, "substring", args);
return new StringExpressionImpl(invokeExpr);
}
Aggregations