1   package org.apache.torque.adapter;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  
24  import org.apache.torque.util.Query;
25  import org.apache.torque.util.UniqueList;
26  
27  public class DBOracleTest extends TestCase
28  {
29      /***
30       * Tests whether replacing the select columns in limit/offset
31       * treatment works (double column names must be aliased)
32       */
33      public void testSelectColumnsForLimitOffset()
34      {
35          Query query = new Query();
36          UniqueList input = new UniqueList();
37          input.add("c1");
38          input.add("c2");
39          input.add("c1 a1");
40          input.add("c1 a2");
41          input.add("t.c1 a4");
42  
43          // A list with no duplicates must remain unchanged
44          query.setSelectClause(new UniqueList(input));
45          new DBOracle().generateLimits(query, 0, 1);
46          assertEquals(input, query.getSelectClause());
47  
48          // double column names must be aliased
49          input.set(1, "t.c1");
50          query.setSelectClause(new UniqueList(input));
51          new DBOracle().generateLimits(query, 0, 1);
52          UniqueList expected = new UniqueList(input);
53          expected.set(1, "t.c1 a0");
54          assertEquals(expected, query.getSelectClause());
55  
56          // a column name which is the same as an alias name must be replaced
57          input.set(1, "c2");
58          input.set(0, "t.a1");
59          query.setSelectClause(new UniqueList(input));
60          new DBOracle().generateLimits(query, 0, 1);
61          expected = new UniqueList(input);
62          expected.set(0, "t.a1 a0");
63          assertEquals(query.getSelectClause(), expected);
64  
65          // triple column names must be made unique
66          input.set(1, "t2.a1");
67          query.setSelectClause(new UniqueList(input));
68          new DBOracle().generateLimits(query, 0, 1);
69          expected = new UniqueList(input);
70          expected.set(0, "t.a1 a0");
71          expected.set(1, "t2.a1 a3");
72          assertEquals(expected, query.getSelectClause());
73      }
74  
75  }