use of org.datanucleus.store.rdbms.sql.expression.ParameterLiteral in project datanucleus-rdbms by datanucleus.
the class StringCharAtMethod method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
*/
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
if (args == null || args.size() == 0 || args.size() > 1) {
throw new NucleusException(Localiser.msg("060003", "charAt", "StringExpression", 0, "NumericExpression/IntegerLiteral/ParameterLiteral"));
}
// {strExpr}.charAt(numExpr)
SQLExpression startExpr = args.get(0);
if (!(startExpr instanceof NumericExpression) && !(startExpr instanceof ParameterLiteral)) {
throw new NucleusException(Localiser.msg("060003", "charAt", "StringExpression", 0, "NumericExpression/IntegerLiteral/ParameterLiteral"));
}
SQLExpression endExpr = startExpr.add(ExpressionUtils.getLiteralForOne(stmt));
// Invoke substring(startExpr, endExpr)
List<SQLExpression> newArgs = new ArrayList<>(2);
newArgs.add(startExpr);
newArgs.add(endExpr);
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
return exprFactory.invokeMethod(stmt, String.class.getName(), "substring", expr, newArgs);
}
use of org.datanucleus.store.rdbms.sql.expression.ParameterLiteral in project datanucleus-rdbms by datanucleus.
the class StringStartsWith2Method method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List)
*/
public SQLExpression getExpression(SQLStatement stmt, SQLExpression expr, List<SQLExpression> args) {
if (args == null || args.size() == 0 || args.size() > 2) {
throw new NucleusException(Localiser.msg("060003", "startsWith", "StringExpression", 0, "StringExpression/CharacterExpression/Parameter"));
}
// {stringExpr}.indexOf(strExpr1 [,numExpr2])
SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
ArrayList funcArgs = new ArrayList();
SQLExpression substrExpr = args.get(0);
if (!(substrExpr instanceof StringExpression) && !(substrExpr instanceof CharacterExpression) && !(substrExpr instanceof ParameterLiteral)) {
throw new NucleusException(Localiser.msg("060003", "startsWith", "StringExpression", 0, "StringExpression/CharacterExpression/Parameter"));
}
if (args.size() == 2) {
NumericExpression numExpr = (NumericExpression) args.get(1);
funcArgs.add(substrExpr);
funcArgs.add(expr);
return new BooleanExpression(new StringExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "CHARINDEX", funcArgs), Expression.OP_EQ, one.add(numExpr));
}
funcArgs.add(substrExpr);
funcArgs.add(expr);
return new BooleanExpression(new StringExpression(stmt, stmt.getSQLExpressionFactory().getMappingForType(int.class), "CHARINDEX", funcArgs), Expression.OP_EQ, one);
}
Aggregations