Package org.apache.torque.criteria

Examples of org.apache.torque.criteria.PreparedStatementPart


                WhereClauseExpression whereClausePart,
                boolean ignoreCase,
                Adapter adapter)
            throws TorqueException
    {
        PreparedStatementPart result = getObjectOrColumnPsPartBuilder().buildPs(
                whereClausePart.getLValue(), ignoreCase, adapter);
        result.getSql().append(whereClausePart.getOperator());
        result.append(getObjectOrColumnPsPartBuilder().buildPs(
                whereClausePart.getRValue(), ignoreCase, adapter));
        return result;
    }
View Full Code Here


            WhereClauseExpression whereClauseExpression,
            boolean ignoreCase,
            Adapter adapter)
        throws TorqueException
    {
        PreparedStatementPart result
            = getObjectOrColumnPsPartBuilder().buildPs(
                    whereClauseExpression.getLValue(),
                    ignoreCase,
                    adapter);
        result.getSql().append(whereClauseExpression.getOperator());
        result .append(getObjectOrColumnPsPartBuilder().buildPs(
                whereClauseExpression.getRValue(),
                ignoreCase,
                adapter));
        return result;
    }
View Full Code Here

                WhereClauseExpression whereClausePart,
                boolean ignoreCase,
                Adapter adapter)
            throws TorqueException
    {
        PreparedStatementPart result;
        if (whereClausePart.getOperator().equals(SqlEnum.ISNULL)
            || whereClausePart.getOperator().equals(SqlEnum.ISNOTNULL))
        {
            result = getObjectOrColumnPsPartBuilder().buildPs(
                    whereClausePart.getLValue(), ignoreCase, adapter);
            result.getSql().append(whereClausePart.getOperator());
            return result;
        }

        // now we know from isApplicable() that rValue is null or is
        // an ObjectKey containing null
        if (whereClausePart.getOperator().equals(SqlEnum.EQUAL))
        {
            result = getObjectOrColumnPsPartBuilder().buildPs(
                    whereClausePart.getLValue(), ignoreCase, adapter);
            result.getSql().append(SqlEnum.ISNULL);
            return result;
        }
        if (whereClausePart.getOperator().equals(SqlEnum.NOT_EQUAL)
            || whereClausePart.getOperator().equals(
                    SqlEnum.ALT_NOT_EQUAL))
        {
            result = getObjectOrColumnPsPartBuilder().buildPs(
                    whereClausePart.getLValue(), ignoreCase, adapter);
            result.getSql().append(SqlEnum.ISNOTNULL);
            return result;
        }
        throw new IllegalStateException("unknown operator "
                + whereClausePart.getOperator());
    }
View Full Code Here

            sb.append(checkWildcard);
            position++;
        }
        value = sb.toString();

        PreparedStatementPart result;
        if (ignoreCase)
        {
            if (adapter.useIlike() && !replaceWithEquals)
            {
                if (SqlEnum.LIKE.equals(whereClausePart.getOperator()))
                {
                    whereClausePart.setOperator(SqlEnum.ILIKE);
                }
                else if (SqlEnum.NOT_LIKE.equals(whereClausePart.getOperator()))
                {
                    whereClausePart.setOperator(SqlEnum.NOT_ILIKE);
                }
                result = getObjectOrColumnPsPartBuilder().buildPs(
                        whereClausePart.getLValue(), false, adapter);
            }
            else
            {
                // no native case insensitive like is offered by the DB,
                // or the LIKE was replaced with equals.
                // need to ignore case manually.
                result = getObjectOrColumnPsPartBuilder().buildPs(
                        whereClausePart.getLValue(), true, adapter);
            }
        }
        else
        {
            result = getObjectOrColumnPsPartBuilder().buildPs(
                    whereClausePart.getLValue(), ignoreCase, adapter);
        }

        if (replaceWithEquals)
        {
            if (whereClausePart.getOperator().equals(SqlEnum.NOT_LIKE)
                    || whereClausePart.getOperator().equals(SqlEnum.NOT_ILIKE))
            {
                result.getSql().append(SqlEnum.NOT_EQUAL);
            }
            else
            {
                result.getSql().append(SqlEnum.EQUAL);
            }

            // remove escape backslashes from String
            position = 0;
            sb = new StringBuffer();
            while (position < value.length())
            {
                char checkWildcard = value.charAt(position);

                if (checkWildcard == BACKSLASH
                        && position + 1 < value.length())
                {
                    position++;
                    // code below copies escaped character into sb
                    checkWildcard = value.charAt(position);
                }
                sb.append(checkWildcard);
                position++;
            }
            value = sb.toString();
        }
        else
        {
            result.getSql().append(whereClausePart.getOperator());
        }

        String rValueSql = "?";
        // handle ignoreCase if necessary
        if (ignoreCase && (!(adapter.useIlike()) || replaceWithEquals))
        {
            rValueSql = adapter.ignoreCase(rValueSql);
        }
        // handle escape clause if necessary
        if (!replaceWithEquals && adapter.useEscapeClauseForLike())
        {
            rValueSql = rValueSql + SqlEnum.ESCAPE + "'\\'";
        }

        result.getPreparedStatementReplacements().add(value);
        result.getSql().append(rValueSql);
        return result;
    }
View Full Code Here

        {
            throw new TorqueException(
                "rValue must be a String for the operator "
                    + whereClausePart.getOperator());
        }
        PreparedStatementPart result = new PreparedStatementPart();
        result.getSql().append(whereClausePart.getRValue());
        return result;
    }
View Full Code Here

                WhereClauseExpression whereClausePart,
                boolean ignoreCase,
                Adapter adapter)
            throws TorqueException
    {
        PreparedStatementPart result = new PreparedStatementPart();

        boolean ignoreCaseApplied = false;
        List<String> inClause = new ArrayList<String>();
        boolean nullContained = false;
        if (whereClausePart.getRValue() instanceof Iterable)
        {
            for (Object listValue : (Iterable<?>) whereClausePart.getRValue())
            {
                if (listValue == null)
                {
                    nullContained = true;
                    continue;
                }
                result.getPreparedStatementReplacements().add(listValue);
                if (ignoreCase && listValue instanceof String)
                {
                    inClause.add(adapter.ignoreCase("?"));
                    ignoreCaseApplied = true;
                }
                else
                {
                    inClause.add("?");
                }
            }
        }
        else if (whereClausePart.getRValue().getClass().isArray())
        {
            for (Object arrayValue : (Object[]) whereClausePart.getRValue())
            {
                if (arrayValue == null)
                {
                    nullContained = true;
                    continue;
                }
                result.getPreparedStatementReplacements().add(arrayValue);
                if (ignoreCase && arrayValue instanceof String)
                {
                    inClause.add(adapter.ignoreCase("?"));
                    ignoreCaseApplied = true;
                }
                else
                {
                    inClause.add("?");
                }
            }
        }
        else
        {
            throw new IllegalArgumentException(
                    "Unknown rValue type "
                    + whereClausePart.getRValue().getClass().getName()
                    + ". rValue must be an instance of "
                    + " Iterable or Array");
        }

        if (nullContained)
        {
            result.getSql().append('(');
        }

        result.append(getObjectOrColumnPsPartBuilder().buildPs(
                whereClausePart.getLValue(),
                ignoreCaseApplied,
                adapter));

        result.getSql().append(whereClausePart.getOperator())
                .append('(')
                .append(StringUtils.join(inClause.iterator(), ","))
                .append(')');
        if (nullContained)
        {
            if (whereClausePart.getOperator() == SqlEnum.IN)
            {
                result.getSql().append(Criterion.OR);
                result.append(getObjectOrColumnPsPartBuilder().buildPs(
                        whereClausePart.getLValue(),
                        false,
                        adapter));
                result.getSql().append(SqlEnum.ISNULL);
            }
            else if (whereClausePart.getOperator() == SqlEnum.NOT_IN)
            {
                result.getSql().append(Criterion.AND);
                result.append(getObjectOrColumnPsPartBuilder().buildPs(
                        whereClausePart.getLValue(),
                        false,
                        adapter));
                result.getSql().append(SqlEnum.ISNOTNULL);
            }
            result.getSql().append(')');
        }
        return result;
    }
View Full Code Here

                WhereClauseExpression whereClausePart,
                boolean ignoreCase,
                Adapter adapter)
            throws TorqueException
    {
        PreparedStatementPart result = new PreparedStatementPart();
        result.getSql().append(whereClausePart.getSql());
        Object[] replacements
                = whereClausePart.getPreparedStatementReplacements();
        if (replacements != null)
        {
            result.getPreparedStatementReplacements().addAll(
                    Arrays.asList(replacements));
        }
        return result;
    }
View Full Code Here

        addTableToFromClause(
                criterion.getRValue(),
                criteria,
                query);

        PreparedStatementPart whereClausePartOutput
            = processCriterion(criterion, criteria);

        where.append(whereClausePartOutput.getSql());
        query.getWhereClausePreparedStatementReplacements().addAll(
                whereClausePartOutput.getPreparedStatementReplacements());
    }
View Full Code Here

                        criterion.getLValue(),
                        criterion.getComparison(),
                        criterion.getRValue(),
                        criterion.getSql(),
                        criterion.getPreparedStatementReplacements());
        PreparedStatementPart whereClausePartOutput = null;
        for (WhereClausePsPartBuilder builder : whereClausePsPartBuilders)
        {
            if (builder.isApplicable(whereClausePartInput, adapter))
            {
                whereClausePartOutput = builder.buildPs(
View Full Code Here

                        columnName,
                        criterion.getComparison(),
                        criterion.getValue(),
                        null,
                        null);
        PreparedStatementPart whereClausePartOutput
            = buildPs(
                whereClausePartInput,
                ignoreCase,
                adapter);
        sb.append(whereClausePartOutput.getSql());
        query.getWhereClausePreparedStatementReplacements().addAll(
                whereClausePartOutput.getPreparedStatementReplacements());

        for (int i = 0; i < criterion.getClauses().size(); i++)
        {
            sb.append(criterion.getConjunctions().get(i));
            org.apache.torque.util.Criteria.Criterion clause
View Full Code Here

TOP

Related Classes of org.apache.torque.criteria.PreparedStatementPart

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.