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

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


        if (args == null || args.size() != 1)
        {
            throw new NucleusException("Incorrect arguments for Array.contains(SQLExpression)");
        }

        ArrayExpression arrExpr = (ArrayExpression)expr;
        SQLExpression elemExpr = (SQLExpression)args.get(0);

        if (elemExpr.isParameter())
        {
            // Element is a parameter so make sure its type is set
            AbstractMemberMetaData mmd = arrExpr.getJavaTypeMapping().getMemberMetaData();
            if (mmd != null)
            {
                stmt.getQueryGenerator().bindParameter(elemExpr.getParameterName(), mmd.getType().getComponentType());
            }
        }

        if (expr instanceof ArrayLiteral)
        {
            if (elemExpr instanceof UnboundExpression)
            {
                Class elemCls = clr.classForName(arrExpr.getJavaTypeMapping().getType()).getComponentType();
                elemExpr = stmt.getQueryGenerator().bindVariable((UnboundExpression)elemExpr, elemCls);
            }

            ArrayLiteral lit = (ArrayLiteral)expr;
            Object array = lit.getValue();
            JavaTypeMapping m = exprFactory.getMappingForType(boolean.class, true);
            if (array == null || Array.getLength(array) == 0)
            {
                return exprFactory.newLiteral(stmt, m, true).eq(exprFactory.newLiteral(stmt, m, false));
            }

            // TODO If elemExpr is a parameter and collExpr is derived from a parameter ?
            BooleanExpression bExpr = null;
            List<SQLExpression> elementExprs = lit.getElementExpressions();
            for (int i=0; i<elementExprs.size(); i++)
            {
                SQLExpression arrElemExpr = elementExprs.get(i);
                if (bExpr == null)
                {
                    bExpr = arrElemExpr.eq(elemExpr);
                }
                else
                {
                    bExpr = bExpr.ior(arrElemExpr.eq(elemExpr));
                }
            }
            bExpr.encloseInParentheses();
            return bExpr;
        }
        else if (arrExpr.getElementExpressions() != null)
        {
            if (elemExpr instanceof UnboundExpression)
            {
                Class elemCls = clr.classForName(arrExpr.getJavaTypeMapping().getType()).getComponentType();
                elemExpr = stmt.getQueryGenerator().bindVariable((UnboundExpression)elemExpr, elemCls);
            }

            // Array defined in query that has some expressions for elements, so just do OR chain
            BooleanExpression bExpr = null;
            List<SQLExpression> elementExprs = arrExpr.getElementExpressions();
            for (int i=0; i<elementExprs.size(); i++)
            {
                SQLExpression arrElemExpr = elementExprs.get(i);
                if (bExpr == null)
                {
View Full Code Here

TOP

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

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.