01: package org.apache.torque.adapter;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: * Tests whether replacing the select columns in limit/offset
30: * treatment works (double column names must be aliased)
31: */
32: public void testSelectColumnsForLimitOffset() {
33: Query query = new Query();
34: UniqueList input = new UniqueList();
35: input.add("c1");
36: input.add("c2");
37: input.add("c1 a1");
38: input.add("c1 a2");
39: input.add("t.c1 a4");
40:
41: // A list with no duplicates must remain unchanged
42: query.setSelectClause(new UniqueList(input));
43: new DBOracle().generateLimits(query, 0, 1);
44: assertEquals(input, query.getSelectClause());
45:
46: // double column names must be aliased
47: input.set(1, "t.c1");
48: query.setSelectClause(new UniqueList(input));
49: new DBOracle().generateLimits(query, 0, 1);
50: UniqueList expected = new UniqueList(input);
51: expected.set(1, "t.c1 a0");
52: assertEquals(expected, query.getSelectClause());
53:
54: // a column name which is the same as an alias name must be replaced
55: input.set(1, "c2");
56: input.set(0, "t.a1");
57: query.setSelectClause(new UniqueList(input));
58: new DBOracle().generateLimits(query, 0, 1);
59: expected = new UniqueList(input);
60: expected.set(0, "t.a1 a0");
61: assertEquals(query.getSelectClause(), expected);
62:
63: // triple column names must be made unique
64: input.set(1, "t2.a1");
65: query.setSelectClause(new UniqueList(input));
66: new DBOracle().generateLimits(query, 0, 1);
67: expected = new UniqueList(input);
68: expected.set(0, "t.a1 a0");
69: expected.set(1, "t2.a1 a3");
70: assertEquals(expected, query.getSelectClause());
71: }
72:
73: }
|