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

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


        if (args == null || args.size() == 0)
        {
            throw new NucleusUserException("Cannot invoke Math.exp 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.exp(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.exp(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.exp(originalValue));
                return new FloatingPointLiteral(stmt, expr.getJavaTypeMapping(), absValue, null);
            }
            throw new IllegalExpressionOperationException("Math.exp()", expr);
        }
        else
        {
View Full Code Here


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

        SQLExpression expr = (SQLExpression)args.get(0);
        if (expr == null)
        {
            return new NullLiteral(stmt, null, null, null);
        }
        if (expr instanceof SQLLiteral)
        {
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
            ApiAdapter api = storeMgr.getApiAdapter();
            Object id = api.getIdForObject(((SQLLiteral)expr).getValue());
            if (id == null)
            {
                return new NullLiteral(stmt, null, null, null);
            }
            else
            {
                JavaTypeMapping m = getMappingForClass(id.getClass());
                return new ObjectLiteral(stmt, m, id, null);
            }
        }
        else if (ObjectExpression.class.isAssignableFrom(expr.getClass()))
        {
            // When the expression represents a PC object need to extract out as the identity
            if (expr.getJavaTypeMapping() instanceof PersistableMapping)
            {
                JavaTypeMapping mapping = new PersistableIdMapping((PersistableMapping)expr.getJavaTypeMapping());
                return new ObjectExpression(stmt, expr.getSQLTable(), mapping);
            }
            else if (expr.getJavaTypeMapping() instanceof ReferenceMapping)
            {
                JavaTypeMapping mapping = new ReferenceIdMapping((ReferenceMapping)expr.getJavaTypeMapping());
                return new ObjectExpression(stmt, expr.getSQLTable(), mapping);
            }
            return expr;
        }

        throw new IllegalExpressionOperationException("JDOHelper.getObjectId", expr);
View Full Code Here

            }

            SQLExpressionFactory factory = rdbmsMgr.getSQLExpressionFactory();

            // Set joinCondition to be "source = target"
            SQLExpression sourceExpr = null;
            if (sourceParentMapping == null)
            {
                sourceExpr = factory.newExpression(this,
                    sourceTable != null ? sourceTable : primaryTable, sourceMapping);
            }
            else
            {
                sourceExpr = factory.newExpression(this,
                    sourceTable != null ? sourceTable : primaryTable, sourceMapping, sourceParentMapping);
            }

            SQLExpression targetExpr = null;
            if (targetParentMapping == null)
            {
                targetExpr = factory.newExpression(this, targetTable, targetMapping);
            }
            else
            {
                targetExpr = factory.newExpression(this, targetTable, targetMapping, targetParentMapping);
            }

            joinCondition = sourceExpr.eq(targetExpr);

            // Process discriminator for any additional conditions
            JavaTypeMapping discrimMapping = targetTable.getTable().getDiscriminatorMapping(false);
            if (discrimMapping != null && discrimValues != null)
            {
                SQLExpression discrimExpr = factory.newExpression(this, targetTable, discrimMapping);
                BooleanExpression discrimCondition = null;
                for (int i=0;i<discrimValues.length;i++)
                {
                    SQLExpression discrimVal = factory.newLiteral(this, discrimMapping, discrimValues[i]);
                    BooleanExpression condition = discrimExpr.eq(discrimVal);
                    if (discrimCondition == null)
                    {
                        discrimCondition = condition;
                    }
View Full Code Here

        {
            List groupBy = new ArrayList();
            Iterator<SQLExpression> groupIter = groupingExpressions.iterator();
            while (groupIter.hasNext())
            {
                SQLExpression expr = groupIter.next();
                String exprText = expr.toSQLText().toSQL();
                if (!groupBy.contains(exprText))
                {
                    groupBy.add(exprText);
                }
            }
View Full Code Here

                AbstractClassMetaData targetCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(className, clr);
                discriminatorValue = targetCmd.getInheritanceMetaData().getDiscriminatorMetaData().getValue();
            }

            SQLExpression discExpr = factory.newExpression(stmt, stmt.getPrimaryTable(), discriminatorMapping);
            SQLExpression discVal = factory.newLiteral(stmt, discriminatorMapping, discriminatorValue);
            stmt.whereAnd(discExpr.eq(discVal), false);
        }

        // Eliminate any subclasses (catered for in separate UNION statement)
        Iterator<String> subIter = storeMgr.getSubClassesForClass(className, false, clr).iterator();
        while (subIter.hasNext())
        {
            String subclassName = subIter.next();
            DatastoreClass[] subclassTables = null;
            DatastoreClass subclassTable = storeMgr.getDatastoreClass(subclassName, clr);

            if (subclassTable == null)
            {
                AbstractClassMetaData targetSubCmd =
                    storeMgr.getNucleusContext().getMetaDataManager().getMetaDataForClass(subclassName, clr);
                AbstractClassMetaData[] targetSubCmds = storeMgr.getClassesManagingTableForClass(targetSubCmd, clr);
                subclassTables = new DatastoreClass[targetSubCmds.length];
                for (int i=0;i<targetSubCmds.length;i++)
                {
                    subclassTables[i] = storeMgr.getDatastoreClass(targetSubCmds[i].getFullClassName(), clr);
                }
            }
            else
            {
                subclassTables = new DatastoreClass[1];
                subclassTables[0] = subclassTable;
            }

            for (int i=0;i<subclassTables.length;i++)
            {
                if (subclassTables[i] != table)
                {
                    // Subclass of our class is stored in different table to the candidate so exclude it
                    // Adds FROM clause of "LEFT OUTER JOIN {subTable} ON ..."
                    // and WHERE clause of "{subTable}.ID = NULL"
                    JavaTypeMapping tableIdMapping = table.getIdMapping();
                    JavaTypeMapping subclassIdMapping = subclassTables[i].getIdMapping();
                    SQLTable sqlTableSubclass =
                        stmt.leftOuterJoin(null, tableIdMapping, subclassTables[i], null, subclassIdMapping,
                            null, stmt.getPrimaryTable().getGroupName());

                    SQLExpression subclassIdExpr = factory.newExpression(stmt, sqlTableSubclass, subclassIdMapping);
                    SQLExpression nullExpr = new NullLiteral(stmt, null, null, null);
                    stmt.whereAnd(subclassIdExpr.eq(nullExpr), false);
                }
            }
        }
View Full Code Here

                    JavaTypeMapping subclassIdMapping = subclassTables[i].getIdMapping();
                    SQLTable sqlTableSubclass =
                        stmt.leftOuterJoin(null, joinElementMapping, subclassTables[i], null,
                            subclassIdMapping, null, stmt.getPrimaryTable().getGroupName());

                    SQLExpression subclassIdExpr = factory.newExpression(stmt, sqlTableSubclass, subclassIdMapping);
                    SQLExpression nullExpr = new NullLiteral(stmt, null, null, null);
                    stmt.whereAnd(subclassIdExpr.eq(nullExpr), false);
                }
            }
        }
View Full Code Here

                "StringExpression/CharacterExpression/ParameterLiteral"));
        }

        StringExpression strExpr1 = (StringExpression)expr;
        StringExpression strExpr2 = (StringExpression)args.get(0);
        SQLExpression str1Upper = strExpr1.invoke("toUpperCase", null);
        SQLExpression str2Upper = strExpr2.invoke("toUpperCase", null);
        return str1Upper.eq(str2Upper);
    }
View Full Code Here

        if (args == null || args.size() != 1)
        {
            throw new NucleusUserException("Cannot invoke SQL_numeric() without a string argument");
        }

        SQLExpression expr = (SQLExpression)args.get(0);
        if (!(expr instanceof StringLiteral))
        {
           throw new NucleusUserException("Cannot use SQL_numeric() without string argument");
        }
        String sql = (String)((StringLiteral)expr).getValue();
View Full Code Here

        if (!(expr instanceof TemporalExpression))
        {
            throw new NucleusException(LOCALISER.msg("060001", "getMonth()", expr));
        }

        SQLExpression one = ExpressionUtils.getLiteralForOne(stmt);
        RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
        JavaTypeMapping mapping2 = storeMgr.getMappingManager().getMapping(String.class);
        SQLExpression mm = exprFactory.newLiteral(stmt, mapping2, "month");

        ArrayList funcArgs = new ArrayList();
        funcArgs.add(mm);
        funcArgs.add(expr);
View Full Code Here

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

        SQLExpression expr = (SQLExpression)args.get(0);
        if (expr == null)
        {
            throw new NucleusUserException("Cannot invoke JDOHelper.getVersion on null expression");
        }
        if (expr instanceof SQLLiteral)
        {
            RDBMSStoreManager storeMgr = stmt.getRDBMSManager();
            ApiAdapter api = storeMgr.getApiAdapter();
            Object obj = ((SQLLiteral)expr).getValue();
            if (obj == null || !api.isPersistable(obj))
            {
                return new NullLiteral(stmt, null, null, null);
            }
            else
            {
                Object ver = stmt.getRDBMSManager().getApiAdapter().getVersionForObject(obj);
                JavaTypeMapping m = getMappingForClass(ver.getClass());
                return new ObjectLiteral(stmt, m, ver, null);
            }
        }
        else if (ObjectExpression.class.isAssignableFrom(expr.getClass()))
        {
            if (((ObjectExpression)expr).getJavaTypeMapping() instanceof PersistableMapping)
            {
                NucleusLogger.QUERY.info(">> JDOHelper.getVersion for " + expr + " table=" + expr.getSQLTable() + " mapping=" + expr.getJavaTypeMapping());
                throw new NucleusUserException("Dont currently support JDOHelper.getVersion(ObjectExpression)");
                // TODO Implement this
            }
            return expr;
        }
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.