Package org.apache.torque.util

Examples of org.apache.torque.util.UniqueList


     * Tests whether replacing the select columns in limit/offset
     * treatment works (double column names must be aliased)
     */
    public void testSelectColumnsForLimitOffset()
    {
        UniqueList input = new UniqueList();
        input.add("c1");
        input.add("c2");
        input.add("c1 a1");
        input.add("c1 a2");
        input.add("t.c1 a4");

        // A list with no duplicates must remain unchanged
        Query query = new Query();
        query.getSelectClause().addAll(input);
        new OracleAdapter().generateLimits(query, 0, 1);
        assertEquals(input, query.getSelectClause());

        // double column names must be aliased
        query = new Query();
        input.set(1, "t.c1");
        query.getSelectClause().addAll(input);
        new OracleAdapter().generateLimits(query, 0, 1);
        UniqueList expected = new UniqueList(input);
        expected.set(1, "t.c1 a0");
        assertEquals(expected, query.getSelectClause());

        // a column name which is the same as an alias name must be replaced
        query = new Query();
        input.set(1, "c2");
        input.set(0, "t.a1");
        query.getSelectClause().addAll(input);
        new OracleAdapter().generateLimits(query, 0, 1);
        expected = new UniqueList(input);
        expected.set(0, "t.a1 a0");
        assertEquals(query.getSelectClause(), expected);

        // triple column names must be made unique
        query = new Query();
        input.set(1, "t2.a1");
        query.getSelectClause().addAll(input);
        new OracleAdapter().generateLimits(query, 0, 1);
        expected = new UniqueList(input);
        expected.set(0, "t.a1 a0");
        expected.set(1, "t2.a1 a3");
        assertEquals(expected, query.getSelectClause());
    }
View Full Code Here


        query.setLimit(null);

        // the query must not contain same column names or aliases.
        // Find double column names and aliases and create unique aliases
        // TODO: does not work for functions yet
        UniqueList selectColumns = query.getSelectClause();
        int replacementSuffix = 0;
        Set columnNames = new HashSet();
        // first pass: only remember aliased columns
        // No replacements need to take place because double aliases
        // are not allowed anyway
        // So alias names will be retained
        for (ListIterator columnIt = selectColumns.listIterator();
                columnIt.hasNext();)
        {
            String selectColumn = (String) columnIt.next();

            // check for sql function
            if ((selectColumn.indexOf('(') != -1)
                || (selectColumn.indexOf(')') != -1))
            {
                // Sql function. Disregard.
                continue;
            }

            // check if alias name exists
            int spacePos = selectColumn.lastIndexOf(' ');
            if (spacePos == -1)
            {
                // no alias, disregard for now
                continue;
            }

            String aliasName = selectColumn.substring(spacePos + 1);
            columnNames.add(aliasName);
        }

        // second pass. Regard ordinary columns only
        for (ListIterator columnIt = selectColumns.listIterator();
                columnIt.hasNext();)
        {
            String selectColumn = (String) columnIt.next();

            // check for sql function
View Full Code Here

     * treatment works (double column names must be aliased)
     */
    public void testSelectColumnsForLimitOffset()
    {
        Query query = new Query();
        UniqueList input = new UniqueList();
        input.add("c1");
        input.add("c2");
        input.add("c1 a1");
        input.add("c1 a2");
        input.add("t.c1 a4");

        // A list with no duplicates must remain unchanged
        query.setSelectClause(new UniqueList(input));
        new DBOracle().generateLimits(query, 0, 1);
        assertEquals(input, query.getSelectClause());

        // double column names must be aliased
        input.set(1, "t.c1");
        query.setSelectClause(new UniqueList(input));
        new DBOracle().generateLimits(query, 0, 1);
        UniqueList expected = new UniqueList(input);
        expected.set(1, "t.c1 a0");
        assertEquals(expected, query.getSelectClause());

        // a column name which is the same as an alias name must be replaced
        input.set(1, "c2");
        input.set(0, "t.a1");
        query.setSelectClause(new UniqueList(input));
        new DBOracle().generateLimits(query, 0, 1);
        expected = new UniqueList(input);
        expected.set(0, "t.a1 a0");
        assertEquals(query.getSelectClause(), expected);

        // triple column names must be made unique
        input.set(1, "t2.a1");
        query.setSelectClause(new UniqueList(input));
        new DBOracle().generateLimits(query, 0, 1);
        expected = new UniqueList(input);
        expected.set(0, "t.a1 a0");
        expected.set(1, "t2.a1 a3");
        assertEquals(expected, query.getSelectClause());
    }
View Full Code Here

TOP

Related Classes of org.apache.torque.util.UniqueList

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.