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

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


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

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

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


        int inputParamNum = 1;
        if (table.getIdentityType() == IdentityType.DATASTORE)
        {
            // Datastore identity value for input
            JavaTypeMapping datastoreIdMapping = table.getDatastoreObjectIdMapping();
            SQLExpression expr = exprFactory.newExpression(sqlStatement, sqlStatement.getPrimaryTable(),
                datastoreIdMapping);
            SQLExpression val = exprFactory.newLiteralParameter(sqlStatement, datastoreIdMapping, null, "ID");
            sqlStatement.whereAnd(expr.eq(val), true);

            StatementMappingIndex datastoreIdx =
                mappingDefinition.getMappingForMemberPosition(StatementClassMapping.MEMBER_DATASTORE_ID);
            if (datastoreIdx == null)
            {
                datastoreIdx = new StatementMappingIndex(datastoreIdMapping);
                mappingDefinition.addMappingForMember(StatementClassMapping.MEMBER_DATASTORE_ID, datastoreIdx);
            }
            datastoreIdx.addParameterOccurrence(new int[] {inputParamNum});
        }
        else if (table.getIdentityType() == IdentityType.APPLICATION)
        {
            // Application identity value(s) for input
            int[] pkNums = cmd.getPKMemberPositions();
            for (int i=0;i<pkNums.length;i++)
            {
                AbstractMemberMetaData mmd = cmd.getMetaDataForManagedMemberAtAbsolutePosition(pkNums[i]);
                JavaTypeMapping pkMapping = table.getMemberMappingInDatastoreClass(mmd);
                if (pkMapping == null)
                {
                    pkMapping = table.getMemberMapping(mmd);
                }
                SQLExpression expr = exprFactory.newExpression(sqlStatement, sqlStatement.getPrimaryTable(),
                    pkMapping);
                SQLExpression val = exprFactory.newLiteralParameter(sqlStatement, pkMapping, null, "PK" + i);
                sqlStatement.whereAnd(expr.eq(val), true);

                StatementMappingIndex pkIdx = mappingDefinition.getMappingForMemberPosition(pkNums[i]);
                if (pkIdx == null)
                {
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

        if (args == null || args.size() == 0)
        {
            throw new NucleusUserException("Cannot invoke Math.log without an argument");
        }

        SQLExpression expr = (SQLExpression)args.get(0);
        if (expr == null)
        {
            return new NullLiteral(stmt, null, null, null);
        }
        else if (expr instanceof SQLLiteral)
        {
            if (expr instanceof ByteLiteral)
            {
                int originalValue = ((BigInteger) ((ByteLiteral) expr).getValue()).intValue();
                BigInteger absValue = new BigInteger(String.valueOf(Math.log(originalValue)));
                return new ByteLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
            }
            else if (expr instanceof IntegerLiteral)
            {
                int originalValue = ((Number) ((IntegerLiteral) expr).getValue()).intValue();
                Double absValue = new Double(Math.log(originalValue));
                return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
            }
            else if (expr instanceof FloatingPointLiteral)
            {
                double originalValue = ((BigDecimal) ((FloatingPointLiteral) expr).getValue()).doubleValue();
                Double absValue = new Double(Math.log(originalValue));
                return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
            }
            throw new IllegalExpressionOperationException("Math.log()", expr);
        }
        else
        {
View Full Code Here

            throw new NucleusException(LOCALISER.msg("060003", "endsWith", "StringExpression", 0,
                "StringExpression/CharacterExpression/ParameterLiteral"));
        }
        else
        {
            SQLExpression substrExpr = (SQLExpression)args.get(0);
            if (!(substrExpr instanceof StringExpression) &&
                !(substrExpr instanceof CharacterExpression) &&
                !(substrExpr instanceof ParameterLiteral))
            {
                throw new NucleusException(LOCALISER.msg("060003", "endsWith", "StringExpression", 0,
                    "StringExpression/CharacterExpression/ParameterLiteral"));
            }
            if (args.size() > 1)
            {
                // SQLExpression numExpr = (SQLExpression)args.get(1);
                // TODO Use numExpr in a SUBSTRING
                if (substrExpr.isParameter())
                {
                    // Any pattern expression cannot be a parameter here
                    SQLLiteral substrLit = (SQLLiteral)substrExpr;
                    stmt.getQueryGenerator().useParameterExpressionAsLiteral(substrLit);
                    if (substrLit.getValue() == null)
                    {
                        return new BooleanExpression(expr, Expression.OP_LIKE,
                            ExpressionUtils.getEscapedPatternExpression(substrExpr));
                    }
                }
                SQLExpression likeSubstrExpr = new StringLiteral(stmt,
                    expr.getJavaTypeMapping(), '%', null);
                return new BooleanExpression(expr, Expression.OP_LIKE,
                    likeSubstrExpr.add(ExpressionUtils.getEscapedPatternExpression(substrExpr)));
            }
            else
            {
                // Create a new StringExpression and manually update its SQL
                if (substrExpr.isParameter())
                {
                    // Any pattern expression cannot be a parameter here
                    SQLLiteral substrLit = (SQLLiteral)substrExpr;
                    stmt.getQueryGenerator().useParameterExpressionAsLiteral(substrLit);
                    if (substrLit.getValue() == null)
                    {
                        return new BooleanExpression(expr, Expression.OP_LIKE,
                            ExpressionUtils.getEscapedPatternExpression(substrExpr));
                    }
                }
                SQLExpression likeSubstrExpr = new StringLiteral(stmt,
                    expr.getJavaTypeMapping(), '%', null);
                return new BooleanExpression(expr, Expression.OP_LIKE,
                    likeSubstrExpr.add(ExpressionUtils.getEscapedPatternExpression(substrExpr)));
            }
        }
    }
View Full Code Here

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

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

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

            JavaTypeMapping m = exprFactory.getMappingForType(boolean.class, false);
            return new BooleanLiteral(stmt, m, isEmpty ? Boolean.TRUE : Boolean.FALSE);
        }
        else
        {
            SQLExpression sizeExpr = exprFactory.invokeMethod(stmt, Map.class.getName(), "size", expr, args);
            JavaTypeMapping mapping = exprFactory.getMappingForType(Integer.class, true);
            SQLExpression zeroExpr = exprFactory.newLiteral(stmt, mapping, 0);
            return sizeExpr.eq(zeroExpr);
        }
    }
View Full Code Here

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

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

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

        }
        else
        {
            // {stringExpr}.indexOf(strExpr1 [,numExpr2])
            ArrayList funcArgs = new ArrayList();
            SQLExpression substrExpr = (SQLExpression)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"));
            }

            SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
            if (args.size() > 1)
            {
                SQLExpression numExpr = (SQLExpression)args.get(1);
                funcArgs.add(substrExpr);
                funcArgs.add(expr);
                return new BooleanExpression(
                    new StringExpression(stmt, getMappingForClass(int.class), "LOCATE", funcArgs), Expression.OP_EQ, one.add(numExpr));
            }
View Full Code Here

            return new AggregateNumericExpression(stmt, m, getFunctionName(), args);
        }
        else
        {
            // Handle as Subquery "SELECT AVG(expr) FROM tbl"
            SQLExpression argExpr = (SQLExpression)args.get(0);
            SQLStatement subStmt = new SQLStatement(stmt, stmt.getRDBMSManager(),
                argExpr.getSQLTable().getTable(), argExpr.getSQLTable().getAlias(), null);
            subStmt.setClassLoaderResolver(clr);

            JavaTypeMapping mapping =
                stmt.getRDBMSManager().getMappingManager().getMappingWithDatastoreMapping(String.class, false, false, clr);
            String aggregateString = getFunctionName() + "(" + argExpr.toSQLText() + ")";
            SQLExpression aggExpr = exprFactory.newLiteral(subStmt, mapping, aggregateString);
            ((StringLiteral)aggExpr).generateStatementWithoutQuotes();
            subStmt.select(aggExpr, null);

            JavaTypeMapping subqMapping = exprFactory.getMappingForType(returnType, false);
            SQLExpression subqExpr = new NumericSubqueryExpression(stmt, subStmt);
            subqExpr.setJavaTypeMapping(subqMapping);
            return subqExpr;
        }
    }
View Full Code Here

TOP

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

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.