use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.
the class StringMatchesMethod method getBooleanLikeExpression.
protected BooleanExpression getBooleanLikeExpression(SQLStatement stmt, SQLExpression expr, SQLExpression regExpr, SQLExpression escapeExpr) {
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
BooleanExpression likeExpr = new BooleanExpression(stmt, exprFactory.getMappingForType(boolean.class, false));
SQLText sql = likeExpr.toSQLText();
sql.clearStatement();
if (Expression.OP_LIKE.isHigherThanLeftSide(expr.getLowestOperator())) {
sql.append("(").append(expr).append(")");
} else {
sql.append(expr);
}
sql.append(" LIKE ");
if (Expression.OP_LIKE.isHigherThanRightSide(regExpr.getLowestOperator())) {
sql.append("(").append(regExpr).append(")");
} else {
sql.append(regExpr);
}
BaseDatastoreAdapter dba = (BaseDatastoreAdapter) stmt.getRDBMSManager().getDatastoreAdapter();
if (escapeExpr != null) {
if (escapeExpr instanceof CharacterLiteral) {
String chr = "" + ((CharacterLiteral) escapeExpr).getValue();
if (chr.equals(dba.getEscapeCharacter())) {
// If the escape character specified matches the Java character then apply the known working ESCAPE
// This is because some datastore JDBC drivers require additional "\" characters to allow
// for Java usage
sql.append(dba.getEscapePatternExpression());
} else {
sql.append(" ESCAPE " + escapeExpr);
}
} else {
sql.append(" ESCAPE " + escapeExpr);
}
} else {
sql.append(" " + dba.getEscapePatternExpression());
}
return likeExpr;
}
use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.
the class StringSimilarPostgresqlMethod method getBooleanLikeExpression.
protected BooleanExpression getBooleanLikeExpression(SQLStatement stmt, SQLExpression expr, SQLExpression regExpr, SQLExpression escapeExpr) {
SQLExpressionFactory exprFactory = stmt.getSQLExpressionFactory();
BooleanExpression similarToExpr = new BooleanExpression(stmt, exprFactory.getMappingForType(boolean.class, false));
SQLText sql = similarToExpr.toSQLText();
sql.clearStatement();
if (OP_SIMILAR_TO.isHigherThanLeftSide(expr.getLowestOperator())) {
sql.append("(").append(expr).append(")");
} else {
sql.append(expr);
}
sql.append(" SIMILAR TO ");
if (OP_SIMILAR_TO.isHigherThanRightSide(regExpr.getLowestOperator())) {
sql.append("(").append(regExpr).append(")");
} else {
sql.append(regExpr);
}
BaseDatastoreAdapter dba = (BaseDatastoreAdapter) stmt.getRDBMSManager().getDatastoreAdapter();
if (escapeExpr != null) {
if (escapeExpr instanceof CharacterLiteral) {
String chr = "" + ((CharacterLiteral) escapeExpr).getValue();
if (chr.equals(dba.getEscapeCharacter())) {
// If the escape character specified matches the Java character then apply the known working ESCAPE
// This is because some datastore JDBC drivers require additional "\" characters to allow
// for Java usage
sql.append(dba.getEscapePatternExpression());
} else {
sql.append(" ESCAPE " + escapeExpr);
}
} else {
sql.append(" ESCAPE " + escapeExpr);
}
} else {
sql.append(" " + dba.getEscapePatternExpression());
}
return similarToExpr;
}
use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.
the class Concat3Operation method getExpression.
/* (non-Javadoc)
* @see org.datanucleus.store.rdbms.sql.operation.SQLOperation#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, org.datanucleus.store.rdbms.sql.expression.SQLExpression)
*/
public SQLExpression getExpression(SQLExpression expr, SQLExpression expr2) {
/*
* We cast it to VARCHAR otherwise the concatenation in derby it is promoted to LONG VARCHAR.
*
* In Derby, ? string parameters are promoted to LONG VARCHAR, and Derby
* does not allow comparisons between LONG VARCHAR types. so the below
* example would be invalid in Derby
* (THIS.FIRSTNAME||?) = ?
*
* Due to that we convert it to
* (CAST(THIS.FIRSTNAME||? AS VARCHAR(4000))) = ?
*
* The only issue with this solution is for columns bigger than 4000 chars.
* Secondly, if both operands are parameters, derby does not allow concatenation e.g.
* ? || ? is not allowed by derby
*
* so we do
* CAST(? AS VARCHAR(4000)) || CAST(? AS VARCHAR(4000))
*
* If both situations happen,
* (CAST(CAST( ? AS VARCHAR(4000) ) || CAST( ? AS VARCHAR(4000) ) AS VARCHAR(4000))) = ?
*/
JavaTypeMapping m = expr.getSQLStatement().getSQLExpressionFactory().getMappingForType(String.class, false);
List types = new ArrayList();
types.add("VARCHAR(4000)");
List argsOp1 = new ArrayList();
argsOp1.add(expr);
SQLExpression firstExpr = new StringExpression(expr.getSQLStatement(), m, "CAST", argsOp1, types).encloseInParentheses();
List argsOp2 = new ArrayList();
argsOp2.add(expr2);
SQLExpression secondExpr = new StringExpression(expr.getSQLStatement(), m, "CAST", argsOp2, types).encloseInParentheses();
StringExpression concatExpr = new StringExpression(expr.getSQLStatement(), null, null);
SQLText sql = concatExpr.toSQLText();
sql.clearStatement();
sql.append(firstExpr);
sql.append("||");
sql.append(secondExpr);
List args = new ArrayList();
args.add(concatExpr);
return new StringExpression(expr.getSQLStatement(), m, "CAST", args, types);
}
use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.
the class SQLAnywhereAdapter method getUpdateTableStatement.
/**
* Method to return the SQLText for an UPDATE TABLE statement. Returns the SQLText for
* <code>UPDATE T1 SET x1 = val1, x2 = val2 FROM MYTBL T1</code>. Override if the datastore doesn't
* support that standard syntax.
* @param tbl The primary table
* @param setSQL The SQLText for the SET component
* @return SQLText for the update statement
*/
public SQLText getUpdateTableStatement(SQLTable tbl, SQLText setSQL) {
// "UPDATE T1"
SQLText sql = new SQLText("UPDATE ").append(tbl.getAlias().toString());
// " SET x1 = val1, x2 = val2"
sql.append(" ").append(setSQL);
// " FROM MYTBL T1"
sql.append(" FROM ").append(tbl.toString());
return sql;
}
use of org.datanucleus.store.rdbms.sql.SQLText in project datanucleus-rdbms by datanucleus.
the class SQLServerAdapter method getUpdateTableStatement.
/**
* Method to return the SQLText for an UPDATE TABLE statement.
* Returns the SQLText for <code>UPDATE T1 SET x1 = val1, x2 = val2 FROM MYTBL T1</code>.
* Override if the datastore doesn't support that standard syntax.
* @param tbl The primary table
* @param setSQL The SQLText for the SET component
* @return SQLText for the update statement
*/
public SQLText getUpdateTableStatement(SQLTable tbl, SQLText setSQL) {
// "UPDATE T1"
SQLText sql = new SQLText("UPDATE ").append(tbl.getAlias().toString());
// " SET x1 = val1, x2 = val2"
sql.append(" ").append(setSQL);
// " FROM MYTBL T1"
sql.append(" FROM ").append(tbl.toString());
return sql;
}
Aggregations