Examples of BooleanExpression


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

        }

        if (candidateCollection != null)
        {
            // Restrict to the supplied candidate ids
            BooleanExpression candidateExpr = null;
            Iterator iter = candidateCollection.iterator();
            JavaTypeMapping idMapping = stmt.getPrimaryTable().getTable().getIdMapping();
            while (iter.hasNext())
            {
                Object candidate = iter.next();
                SQLExpression idExpr = stmt.getSQLExpressionFactory().newExpression(stmt, stmt.getPrimaryTable(),
                    idMapping);
                SQLExpression idVal = stmt.getSQLExpressionFactory().newLiteral(stmt, idMapping, candidate);
                if (candidateExpr == null)
                {
                    candidateExpr = idExpr.eq(idVal);
                }
                else
                {
                    candidateExpr = candidateExpr.ior(idExpr.eq(idVal));
                }
            }
            stmt.whereAnd(candidateExpr, true);
        }
View Full Code Here

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

        if (hasDiscriminator && restrictDiscriminator)
        {
            // Add the discriminator expression to restrict accepted values
            boolean multipleCandidates = false;
            BooleanExpression discExpr = null;
            if (candidates != null)
            {
                // Multiple candidates
                if (candidates.length > 1)
                {
                    multipleCandidates = true;
                }
                for (int i=0;i<candidates.length;i++)
                {
                    BooleanExpression discExprCandidate =
                        SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt,
                            candidates[i].getName(), dismd, discMapping, discrimSqlTbl, clr);
                    if (discExpr != null)
                    {
                        discExpr = discExpr.ior(discExprCandidate);
                    }
                    else
                    {
                        discExpr = discExprCandidate;
                    }
                    if (includeSubclasses)
                    {
                        HashSet<String> subclassNames = storeMgr.getSubClassesForClass(candidateType.getName(), true, clr);
                        Iterator<String> subclassIter = subclassNames.iterator();
                        if (!multipleCandidates)
                        {
                            multipleCandidates = (subclassNames.size() > 0);
                        }
                        while (subclassIter.hasNext())
                        {
                            String subclassName = subclassIter.next();
                            BooleanExpression discExprSub =
                                SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt, subclassName,
                                    dismd, discMapping, discrimSqlTbl, clr);
                            discExpr = discExpr.ior(discExprSub);
                        }
                    }
                }
            }
            else
            {
                // Single candidate
                discExpr = SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt,
                    candidateType.getName(), dismd, discMapping, discrimSqlTbl, clr);
                if (includeSubclasses)
                {
                    HashSet<String> subclassNames = storeMgr.getSubClassesForClass(candidateType.getName(), true, clr);
                    Iterator<String> subclassIter = subclassNames.iterator();
                    multipleCandidates = (subclassNames.size() > 0);
                    while (subclassIter.hasNext())
                    {
                        String subclassName = subclassIter.next();
                        BooleanExpression discExprCandidate =
                            SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt, subclassName,
                                dismd, discMapping, discrimSqlTbl, clr);
                        discExpr = discExpr.ior(discExprCandidate);
                    }
                }
            }

            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

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

        // Add the table to the referenced tables for this statement
        tables.put(targetTable.alias.getIdentifierName(), targetTable);

        // Generate the join condition to use
        BooleanExpression joinCondition = getJoinConditionForJoin(sourceTable, sourceMapping, sourceParentMapping,
            targetTable, targetMapping, targetParentMapping, discrimValues);

        if (rdbmsMgr.getDatastoreAdapter().supportsOption(RDBMSAdapter.ANSI_JOIN_SYNTAX))
        {
            // "ANSI-92" style join
View Full Code Here

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

    protected BooleanExpression getJoinConditionForJoin(
            SQLTable sourceTable, JavaTypeMapping sourceMapping, JavaTypeMapping sourceParentMapping,
            SQLTable targetTable, JavaTypeMapping targetMapping, JavaTypeMapping targetParentMapping,
            Object[] discrimValues)
    {
        BooleanExpression joinCondition = null;
        if (sourceMapping != null && targetMapping != null)
        {
            // Join condition(s) - INNER, LEFT OUTER, RIGHT OUTER joins
            if (sourceMapping.getNumberOfDatastoreMappings() != targetMapping.getNumberOfDatastoreMappings())
            {
                throw new NucleusException("Cannot join from " + sourceMapping + " to " + targetMapping +
                    " since they have different numbers of datastore columns!");
            }

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

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

        JavaTypeMapping discriminatorMapping = table.getDiscriminatorMapping(false);
        DiscriminatorMetaData discriminatorMetaData = table.getDiscriminatorMetaData();
        if (discriminatorMapping != null && discriminatorMetaData.getStrategy() != DiscriminatorStrategy.NONE)
        {
            // Restrict to valid discriminator value where we have a discriminator specified on this table
            BooleanExpression discExpr = SQLStatementHelper.getExpressionForDiscriminatorForClass(stmt,
                className, discriminatorMetaData, discriminatorMapping, stmt.getPrimaryTable(), clr);
            stmt.whereAnd(discExpr, false);
        }

        // Eliminate any subclasses (catered for in separate UNION statement)
View Full Code Here

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

                return new BooleanLiteral(stmt, expr.getJavaTypeMapping(), Boolean.FALSE);
            }

            // TODO If valExpr is a parameter and mapExpr is derived from a parameter ?
            MapValueLiteral mapValueLiteral = lit.getValueLiteral();
            BooleanExpression bExpr = null;
            List<SQLExpression> elementExprs = mapValueLiteral.getValueExpressions();
            for (int i=0; i<elementExprs.size(); i++)
            {
                if (bExpr == null)
                {
                    bExpr = (elementExprs.get(i)).eq(valExpr);
                }
                else
                {
                    bExpr = bExpr.ior((elementExprs.get(i)).eq(valExpr));
                }
            }
            bExpr.encloseInParentheses();
            return bExpr;
        }
        else
        {
            if (stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.FILTER)
View Full Code Here

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

    }

    protected BooleanExpression getBooleanLikeExpression(SQLExpression expr, SQLExpression regExpr,
            SQLExpression escapeExpr)
    {
        BooleanExpression similarToExpr = new BooleanExpression(stmt,
            exprFactory.getMappingForType(boolean.class, false));
        SQLText sql = similarToExpr.toSQLText();
        sql.clearStatement();
        if (OP_SIMILAR_TO.isHigherThanLeftSide(expr.getLowestOperator()))
        {
            sql.append("(").append(expr).append(")");
        }
View Full Code Here

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

                return new BooleanLiteral(stmt, m, Boolean.FALSE);
            }

            // TODO If keyExpr is a parameter and mapExpr is derived from a parameter ?
            MapKeyLiteral mapKeyLiteral = lit.getKeyLiteral();
            BooleanExpression bExpr = null;
            List<SQLExpression> elementExprs = mapKeyLiteral.getKeyExpressions();
            for (int i=0; i<elementExprs.size(); i++)
            {
                if (bExpr == null)
                {
                    bExpr = (elementExprs.get(i)).eq(keyExpr);
                }
                else
                {
                    bExpr = bExpr.ior((elementExprs.get(i)).eq(keyExpr));
                }
            }
            bExpr.encloseInParentheses();
            return bExpr;
        }
        else
        {
            if (stmt.getQueryGenerator().getCompilationComponent() == CompilationComponent.FILTER)
View Full Code Here

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

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

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

            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));
            }
            else
            {
                funcArgs.add(substrExpr);
                funcArgs.add(expr);
                return new BooleanExpression(
                    new StringExpression(stmt, getMappingForClass(int.class), "LOCATE", funcArgs), Expression.OP_EQ, one);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.