Package org.datanucleus.store.rdbms.sql.expression

Examples of org.datanucleus.store.rdbms.sql.expression.SQLExpression$ColumnExpressionList


            {
                discriminatorValue = targetCmd.getInheritanceMetaData().getDiscriminatorMetaData().getValue();
            }
        }

        SQLExpression discrExpr =
            stmt.getSQLExpressionFactory().newExpression(stmt, discrimSqlTbl, discriminatorMapping);
        SQLExpression discrVal =
            stmt.getSQLExpressionFactory().newLiteral(stmt, discriminatorMapping, discriminatorValue);
        return discrExpr.eq(discrVal);
    }
View Full Code Here


        for (int i = 0; i < appended.size(); i++)
        {
            Object item = appended.get(i);
            if (item instanceof SQLExpression)
            {
                SQLExpression expr = (SQLExpression) item;
                SQLText st = expr.toSQLText();
                sql.append(st.toSQL());

                if (st.parameters != null)
                {
                    if (parameters == null)
View Full Code Here

        }

        // Apply condition to filter by owner
        SQLTable ownerSqlTbl =
            SQLStatementHelper.getSQLTableForMappingOfTable(sqlStmt, sqlStmt.getPrimaryTable(), ownerMapping);
        SQLExpression ownerExpr = exprFactory.newExpression(sqlStmt, ownerSqlTbl, ownerMapping);
        SQLExpression ownerVal = exprFactory.newLiteralParameter(sqlStmt, ownerMapping, null, "OWNER");
        sqlStmt.whereAnd(ownerExpr.eq(ownerVal), true);

        if (relationDiscriminatorMapping != null)
        {
            // Apply condition on distinguisher field to filter by distinguisher (when present)
            SQLTable distSqlTbl =
                SQLStatementHelper.getSQLTableForMappingOfTable(sqlStmt, sqlStmt.getPrimaryTable(), relationDiscriminatorMapping);
            SQLExpression distExpr = exprFactory.newExpression(sqlStmt, distSqlTbl, relationDiscriminatorMapping);
            SQLExpression distVal = exprFactory.newLiteral(sqlStmt, relationDiscriminatorMapping, relationDiscriminatorValue);
            sqlStmt.whereAnd(distExpr.eq(distVal), true);
        }

        if (orderMapping != null)
        {
View Full Code Here

        // Apply condition on owner field to filter by owner
        SQLExpressionFactory exprFactory = storeMgr.getSQLExpressionFactory();
        SQLTable ownerSqlTbl =
            SQLStatementHelper.getSQLTableForMappingOfTable(sqlStmt, containerSqlTbl, ownerMapping);
        SQLExpression ownerExpr = exprFactory.newExpression(sqlStmt, ownerSqlTbl, ownerMapping);
        SQLExpression ownerVal = exprFactory.newLiteralParameter(sqlStmt, ownerMapping, null, "OWNER");
        sqlStmt.whereAnd(ownerExpr.eq(ownerVal), true);

        // Input parameter(s) - the owner
        int inputParamNum = 1;
        StatementMappingIndex ownerIdx = new StatementMappingIndex(ownerMapping);
View Full Code Here

            }

            if (hasOption(OPTION_ALLOW_NULLS))
            {
                // Allow for null value of discriminator
                SQLExpression expr = stmt.getSQLExpressionFactory().newExpression(stmt, discrimSqlTbl,
                    discMapping);
                SQLExpression val = new NullLiteral(stmt, null, null, null);
                BooleanExpression nullDiscExpr = expr.eq(val);
                discExpr = discExpr.ior(nullDiscExpr);
                if (!multipleCandidates)
                {
                    multipleCandidates = true;
View Full Code Here

            throw new NucleusException(LOCALISER.msg("060001", "getYear()", expr));
        }

        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(String.class);
        SQLExpression day = exprFactory.newLiteral(stmt, mapping, "year");

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(day);
        funcArgs.add(expr);
        return new NumericExpression(stmt, getMappingForClass(int.class), "date_part", funcArgs);
View Full Code Here

    public SQLExpression getExpression(SQLExpression expr, List args)
    {
        if (expr == null)
        {
            // Assume that we have something like "CURRENT_DATE()"
            SQLExpression dateExpr =
                new TemporalExpression(stmt, getMappingForClass(getClassForMapping()), getFunctionName(), args);
            // Update the SQL manually since the default is to add brackets after the name
            dateExpr.toSQLText().clearStatement();
            dateExpr.toSQLText().append(getFunctionName());
            return dateExpr;
        }
        else
        {
            throw new NucleusException(LOCALISER.msg("060002", getFunctionName(), expr));
View Full Code Here

                "StringExpression/CharacterExpression/ParameterLiteral"));
        }
        else
        {
            // {stringExpr}.indexOf(strExpr1 [,numExpr2])
            SQLExpression substrExpr = (SQLExpression)args.get(0);
            if (!(substrExpr instanceof StringExpression) &&
                !(substrExpr instanceof CharacterExpression) &&
                !(substrExpr instanceof ParameterLiteral))
            {
                throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 0,
                    "StringExpression/CharacterExpression/ParameterLiteral"));
            }

            ArrayList funcArgs = new ArrayList();
            if (args.size() == 1)
            {
                // strExpr.indexOf(str1)
                funcArgs.add(expr);
                funcArgs.add(substrExpr);
                SQLExpression oneExpr = ExpressionUtils.getLiteralForOne(stmt);
                NumericExpression locateExpr = new NumericExpression(stmt, getMappingForClass(int.class), "STRPOS", funcArgs);
                return new NumericExpression(locateExpr, Expression.OP_SUB, oneExpr);
            }
            else
            {
                // strExpr.indexOf(str1, pos)
                SQLExpression fromExpr = (SQLExpression)args.get(1);
                if (!(fromExpr instanceof NumericExpression))
                {
                    throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 1,
                        "NumericExpression"));
                }

                // Find the substring starting at this position
                ArrayList substrArgs = new ArrayList(1);
                substrArgs.add(fromExpr);
                SQLExpression strExpr = exprFactory.invokeMethod(stmt, "java.lang.String", "substring", expr, substrArgs);

                funcArgs.add(strExpr);
                funcArgs.add(substrExpr);
                NumericExpression locateExpr = new NumericExpression(stmt, getMappingForClass(int.class), "STRPOS", funcArgs);

                SQLExpression[] whenExprs = new SQLExpression[1];
                NumericExpression zeroExpr = new IntegerLiteral(stmt, exprFactory.getMappingForType(Integer.class, false), Integer.valueOf(0), null);
                whenExprs[0] = locateExpr.gt(zeroExpr);

                SQLExpression[] actionExprs = new SQLExpression[1];
                SQLExpression oneExpr = ExpressionUtils.getLiteralForOne(stmt);
                NumericExpression posExpr1 = new NumericExpression(locateExpr, Expression.OP_SUB, oneExpr);
                actionExprs[0] = new NumericExpression(posExpr1, Expression.OP_ADD, fromExpr);

                SQLExpression elseExpr = new IntegerLiteral(stmt, exprFactory.getMappingForType(Integer.class, false), Integer.valueOf(-1), null);

                return new CaseExpression(whenExprs, actionExprs, elseExpr);
            }
        }
    }
View Full Code Here

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

            Class cls = Integer.class;
            int clsLevel = 0;
            // Priority order is Double, Float, BigDecimal, BigInteger, Long, Integer
            for (int i=0;i<args.size();i++)
            {
                SQLExpression argExpr = (SQLExpression) args.get(i);
                Class argType = argExpr.getJavaTypeMapping().getJavaType();
                if (clsLevel < 5 && (argType == double.class || argType == Double.class))
                {
                    cls = Double.class;
                    clsLevel = 5;
                }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.rdbms.sql.expression.SQLExpression$ColumnExpressionList

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.