Package org.apache.cayenne.query

Examples of org.apache.cayenne.query.Ordering


        // case insensitive ordering appends extra columns
        // to the query when query is using DISTINCT...
        // verify that the result is not messed up

        SelectQuery query = new SelectQuery(Artist.class);
        Ordering ordering = new Ordering(
                Artist.ARTIST_NAME_PROPERTY,
                SortOrder.ASCENDING_INSENSITIVE);
        query.addOrdering(ordering);
        query.setDistinct(true);
View Full Code Here


        if (path != null && path.trim().length() == 0) {
            path = null;
        }
        boolean isDescending = "true".equalsIgnoreCase(descending);
        boolean isIgnoringCase = "true".equalsIgnoreCase(ignoreCase);
        orderings.add(new Ordering(path, !isDescending, isIgnoringCase));
    }
View Full Code Here

        if (path != null && path.trim().length() == 0) {
            path = null;
        }
        boolean isDescending = "true".equalsIgnoreCase(descending);
        boolean isIgnoringCase = "true".equalsIgnoreCase(ignoreCase);
        orderings.add(new Ordering(path, !isDescending, isIgnoringCase));
    }
View Full Code Here

        Appendable mainBuffer = this.out;

        try {
            while (it.hasNext()) {
                Ordering ord = it.next();

                // reset buffer to collect SQL for the single column, that we'll be reusing
                this.out = new StringBuilder();

                if (ord.isCaseInsensitive()) {
                    out.append("UPPER(");
                }

                Expression exp = ord.getSortSpec();

                if (exp.getType() == Expression.OBJ_PATH) {
                    appendObjPath(exp);
                }
                else if (exp.getType() == Expression.DB_PATH) {
                    appendDbPath(exp);
                }
                else {
                    throw new CayenneRuntimeException("Unsupported ordering expression: "
                            + exp);
                }

                // Close UPPER() modifier
                if (ord.isCaseInsensitive()) {
                    out.append(")");
                }

                String columnSQL = out.toString();
                mainBuffer.append(columnSQL);
                orderByColumnList.add(columnSQL);

                // "ASC" is a noop, omit it from the query
                if (!ord.isAscending()) {
                    mainBuffer.append(" DESC");
                }

                if (it.hasNext()) {
                    mainBuffer.append(", ");
View Full Code Here

        if (path != null && path.trim().length() == 0) {
            path = null;
        }
        boolean isDescending = "true".equalsIgnoreCase(descending);
        boolean isIgnoringCase = "true".equalsIgnoreCase(ignoreCase);
        orderings.add(new Ordering(path, !isDescending, isIgnoringCase));
    }
View Full Code Here

        if (path != null && path.trim().length() == 0) {
            path = null;
        }
        boolean isDescending = "true".equalsIgnoreCase(descending);
        boolean isIgnoringCase = "true".equalsIgnoreCase(ignoreCase);
        orderings.add(new Ordering(path, !isDescending, isIgnoringCase));
    }
View Full Code Here

        // case insensitive ordering appends extra columns
        // to the query when query is using DISTINCT...
        // verify that the result is not messaged up

        SelectQuery query = new SelectQuery(Artist.class);
        Ordering ordering = new Ordering("artistName", false);
        ordering.setCaseInsensitive(true);
        query.addOrdering(ordering);
        query.setDistinct(true);

        List objects = context.performQuery(query);
        assertEquals(artistCount, objects.size());
View Full Code Here

    }

    public void testSuccessLockingOnMixed() throws Exception {
        createTestData("testLockingOnMixed");
        SelectQuery query = new SelectQuery(SimpleLockingTestEntity.class);
        query.addOrdering(new Ordering("db:LOCKING_TEST_ID", Ordering.ASC));

        List allObjects = context.performQuery(query);
        assertEquals(3, allObjects.size());

        SimpleLockingTestEntity object1 = (SimpleLockingTestEntity) allObjects.get(0);
View Full Code Here

            if (i > 0)
                buf.append(", ");

            StringBuffer ordComp = new StringBuffer();

            Ordering ord = (Ordering) list.get(i);

            //UPPER is (I think) part of the SQL99 standard, and I'm not convinced it's universally available
            // - should the syntax used here be defined by the Db specific adaptor perhaps, or at least
            // possibly specified by the db adaptor (a DB specific OrderingTranslator hook)?
            if (ord.isCaseInsensitive()) {
                ordComp.append("UPPER(");

            }

            Expression exp = ord.getSortSpec();

            if (exp.getType() == Expression.OBJ_PATH) {
                appendObjPath(ordComp, exp);
            } else if (exp.getType() == Expression.DB_PATH) {
                appendDbPath(ordComp, exp);
            } else {
                throw new CayenneRuntimeException(
                    "Unsupported ordering expression: " + exp);
            }

            //Close UPPER() modifier
            if (ord.isCaseInsensitive()) {
                ordComp.append(")");
            }

            orderByColumnList.add(ordComp.toString());
           
            buf.append(ordComp.toString());

            // "ASC" is a noop, omit it from the query
            if (!ord.isAscending()) {
                buf.append(" DESC");
            }
        }

        return buf.length() > 0 ? buf.toString() : null;
View Full Code Here

            if (i > 0)
                buf.append(", ");

            StringBuffer ordComp = new StringBuffer();

            Ordering ord = (Ordering) list.get(i);

            //UPPER is (I think) part of the SQL99 standard, and I'm not convinced it's universally available
            // - should the syntax used here be defined by the Db specific adaptor perhaps, or at least
            // possibly specified by the db adaptor (a DB specific OrderingTranslator hook)?
            if (ord.isCaseInsensitive()) {
                ordComp.append("UPPER(");

            }

            Expression exp = ord.getSortSpec();

            if (exp.getType() == Expression.OBJ_PATH) {
                appendObjPath(ordComp, exp);
            } else if (exp.getType() == Expression.DB_PATH) {
                appendDbPath(ordComp, exp);
            } else {
                throw new CayenneRuntimeException(
                    "Unsupported ordering expression: " + exp);
            }

            //Close UPPER() modifier
            if (ord.isCaseInsensitive()) {
                ordComp.append(")");
            }

            orderByColumnList.add(ordComp.toString());
           
            buf.append(ordComp.toString());

            // "ASC" is a noop, omit it from the query
            if (!ord.isAscending()) {
                buf.append(" DESC");
            }
        }

        return buf.length() > 0 ? buf.toString() : null;
View Full Code Here

TOP

Related Classes of org.apache.cayenne.query.Ordering

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.