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

Examples of org.datanucleus.store.rdbms.sql.expression.NumericExpression


                VersionMetaData vermd = candidateCmd.getVersionMetaData();
                if (vermd.getVersionStrategy() == VersionStrategy.VERSION_NUMBER)
                {
                    // Increment the version
                    SQLTable verSqlTbl = stmt.getTable(verTable, stmt.getPrimaryTable().getGroupName());
                    SQLExpression verExpr = new NumericExpression(stmt, verSqlTbl, verMapping);
                    SQLExpression incrExpr = verExpr.add(new IntegerLiteral(stmt,
                        stmt.getSQLExpressionFactory().getMappingForType(Integer.class, false), new Integer(1), null));

                    updateSqlExpr = verExpr.eq(incrExpr);

                    SQLExpression[] oldArray = updateSqlExprs;
                    updateSqlExprs = new SQLExpression[oldArray.length+1];
                    System.arraycopy(oldArray, 0, updateSqlExprs, 0, oldArray.length);
                    updateSqlExprs[oldArray.length] = updateSqlExpr;
                }
                else if (vermd.getVersionStrategy() == VersionStrategy.DATE_TIME)
                {
                    // Set version to the time of update
                    SQLTable verSqlTbl = stmt.getTable(verTable, stmt.getPrimaryTable().getGroupName());
                    SQLExpression verExpr = new NumericExpression(stmt, verSqlTbl, verMapping);
                    Object newVersion = VersionHelper.getNextVersion(vermd.getVersionStrategy(), null);
                    JavaTypeMapping valMapping = stmt.getSQLExpressionFactory().getMappingForType(newVersion.getClass(), false);
                    SQLExpression valExpr = new TemporalLiteral(stmt, valMapping, newVersion, null);

                    updateSqlExpr = verExpr.eq(valExpr);

                    SQLExpression[] oldArray = updateSqlExprs;
                    updateSqlExprs = new SQLExpression[oldArray.length+1];
                    System.arraycopy(oldArray, 0, updateSqlExprs, 0, oldArray.length);
                    updateSqlExprs[oldArray.length] = updateSqlExpr;
View Full Code Here


        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

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

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

            {
                // 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

                {
                    cls = Long.class;
                    clsLevel = 1;
                }
            }
            return new NumericExpression(stmt, getMappingForClass(cls), "NULLIF", args);
        }
        else
        {
            throw new NucleusException(LOCALISER.msg("060002", "NULLIF", expr));
        }
View Full Code Here

    public SQLExpression getExpression(SQLExpression expr, SQLExpression expr2)
    {
        ArrayList args = new ArrayList();
        args.add(expr);
        args.add(expr2);
        return new NumericExpression(expr.getSQLStatement(), getMappingForClass(int.class), "MOD", args);
    }
View Full Code Here

        List types = new ArrayList();
        types.add("BIGINT");

        List argsOp1 = new ArrayList();
        argsOp1.add(expr);
        args.add(new NumericExpression(expr.getSQLStatement(), getMappingForClass(int.class), "CAST", argsOp1, types));

        List argsOp2 = new ArrayList();
        argsOp2.add(expr2);
        args.add(new NumericExpression(expr.getSQLStatement(), getMappingForClass(int.class), "CAST", argsOp2, types));

        return new NumericExpression(expr.getSQLStatement(), getMappingForClass(int.class), "MOD", args);
    }
View Full Code Here

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

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(expr);
        NumericExpression monthExpr = new NumericExpression(stmt, getMappingForClass(int.class), "MONTH", funcArgs);

        // Delete one from the SQL "month" (origin=1) to be compatible with Java month (origin=0)
        SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
        NumericExpression numExpr = new NumericExpression(monthExpr, Expression.OP_SUB, one);
        numExpr.encloseInParentheses();
        return numExpr;
    }
View Full Code Here

           throw new NucleusUserException("Cannot use SQL_numeric() without string argument");
        }
        String sql = (String)((StringLiteral)expr).getValue();

        JavaTypeMapping m = exprFactory.getMappingForType(boolean.class, false);
        NumericExpression retExpr = new NumericExpression(stmt, m, sql);
        return retExpr;
    }
View Full Code Here

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(mm);
        funcArgs.add(expr);

        // Delete one from the SQL "month" (origin=1) to be compatible with Java month (origin=0)
        NumericExpression numExpr = new NumericExpression(
            new NumericExpression(stmt, getMappingForClass(int.class), "date_part", funcArgs),
            Expression.OP_SUB, one);
        numExpr.encloseInParentheses();
        return numExpr;
    }
View Full Code Here

TOP

Related Classes of org.datanucleus.store.rdbms.sql.expression.NumericExpression

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.