Package org.datanucleus.store.rdbms.sql

Examples of org.datanucleus.store.rdbms.sql.SQLText


        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);
View Full Code Here


    protected BooleanExpression getBooleanLikeExpression(SQLExpression expr, SQLExpression regExpr,
            SQLExpression escapeExpr)
    {
        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);
        }

        DatabaseAdapter dba = (DatabaseAdapter) 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;
    }
View Full Code Here

    protected BooleanExpression getBooleanLikeExpression(SQLExpression expr, SQLExpression regExpr,
            SQLExpression escapeExpr)
    {
        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);
        }

        DatabaseAdapter dba = (DatabaseAdapter) 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;
    }
View Full Code Here

                trimArgs.add(expr);
            }
            else
            {
                StringExpression argExpr = new StringExpression(stmt, expr.getJavaTypeMapping(), "NULL", null);
                SQLText sql = argExpr.toSQLText();
                sql.clearStatement();
                sql.append(getTrimSpecKeyword() + " ");
                sql.append(trimCharExpr);
                sql.append(" FROM ");
                sql.append(expr);
                trimArgs.add(argExpr);
            }

            StringExpression trimExpr = new StringExpression(stmt, expr.getJavaTypeMapping(), "TRIM", trimArgs);
            return trimExpr;
View Full Code Here

                    "NumericExpression/IntegerLiteral/ParameterLiteral"));
            }

            // Create a new StringExpression and manually update its SQL
            StringExpression strExpr = new StringExpression(stmt, null, null);
            SQLText sql = strExpr.toSQLText();
            sql.append("SUBSTRING(").append(expr).append(" FROM ").append(startExpr.add(one)).append(')');
            return strExpr;
        }
        else
        {
            // {stringExpr}.substring(numExpr1, numExpr2)
            SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);

            SQLExpression startExpr = (SQLExpression)args.get(0);
            if (!(startExpr instanceof NumericExpression))
            {
                throw new NucleusException(LOCALISER.msg("060003", "substring", "StringExpression", 0,
                    "NumericExpression"));
            }
            SQLExpression endExpr = (SQLExpression)args.get(1);
            if (!(endExpr instanceof NumericExpression))
            {
                throw new NucleusException(LOCALISER.msg("060003", "substring", "StringExpression", 1,
                    "NumericExpression"));
            }

            // Create a new StringExpression and manually update its SQL
            StringExpression strExpr = new StringExpression(stmt, null, null);
            SQLText sql = strExpr.toSQLText();
            sql.append("SUBSTRING(").append(expr).append(" FROM ").append(startExpr.add(one))
                .append(" FOR ").append(endExpr.sub(startExpr)).append(')');
            return strExpr;
        }
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.rdbms.sql.SQLText

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.