OpenJPA-1002: fixed select range for Oracle drivers, patch submitted by Amy Yang and Ravi Palacherla

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@769505 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Ezzio 2009-04-28 19:14:40 +00:00
parent d86b15e30d
commit 09859699f9
4 changed files with 138 additions and 34 deletions

View File

@ -1883,7 +1883,7 @@ public class DBDictionary
from.append("(");
from.append(toSelect(subSelect, null, subFrom, where,
sel.getGrouping(), sel.getHaving(), null, sel.isDistinct(),
false, sel.getStartIndex(), sel.getEndIndex(), true));
false, sel.getStartIndex(), sel.getEndIndex(), true, sel));
from.append(")");
if (requiresAliasForSubselect)
from.append(" ").append(Select.FROM_SELECT_ALIAS);
@ -2371,11 +2371,12 @@ public class DBDictionary
/**
* Combine the given components into a SELECT statement.
*/
public SQLBuffer toSelect(SQLBuffer selects, JDBCFetchConfiguration fetch,
protected SQLBuffer toSelect(SQLBuffer selects,
JDBCFetchConfiguration fetch,
SQLBuffer from, SQLBuffer where, SQLBuffer group,
SQLBuffer having, SQLBuffer order,
boolean distinct, boolean forUpdate, long start, long end,
boolean subselect) {
boolean subselect, Select sel) {
return toOperation(getSelectOperation(fetch), selects, from, where,
group, having, order, distinct, start, end,
getForUpdateClause(fetch, forUpdate, null), subselect);
@ -2395,7 +2396,8 @@ public class DBDictionary
/**
* Combine the given components into a SELECT statement.
*/
public SQLBuffer toSelect(SQLBuffer selects, JDBCFetchConfiguration fetch,
protected SQLBuffer toSelect(SQLBuffer selects,
JDBCFetchConfiguration fetch,
SQLBuffer from, SQLBuffer where, SQLBuffer group,
SQLBuffer having, SQLBuffer order,
boolean distinct, boolean forUpdate, long start, long end,

View File

@ -360,7 +360,16 @@ public class OracleDictionary
return buf;
}
public SQLBuffer toSelect(SQLBuffer select, JDBCFetchConfiguration fetch,
protected SQLBuffer toSelect(SQLBuffer select, JDBCFetchConfiguration fetch,
SQLBuffer tables, SQLBuffer where, SQLBuffer group,
SQLBuffer having, SQLBuffer order,
boolean distinct, boolean forUpdate, long start, long end,
boolean subselect, Select sel) {
return toSelect(select, fetch, tables, where, group, having, order,
distinct, forUpdate, start, end, sel);
}
protected SQLBuffer toSelect(SQLBuffer select, JDBCFetchConfiguration fetch,
SQLBuffer tables, SQLBuffer where, SQLBuffer group,
SQLBuffer having, SQLBuffer order,
boolean distinct, boolean forUpdate, long start, long end,

View File

@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.openjpa.persistence.jdbc.meta;
import java.util.*;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.kernel.jpql.JPQLParser;
import org.apache.openjpa.persistence.FetchPlan;
import org.apache.openjpa.persistence.OpenJPAQuery;
import org.apache.openjpa.persistence.jdbc.common.apps.*;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.jdbc.common.apps.EagerOuterJoinPC;
public class TestRangeQuery extends
org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest {
/** Creates a new instance of TestRangeQuery */
public TestRangeQuery(String name) {
super(name);
}
public boolean skipTest() {
DBDictionary dict = ((JDBCConfiguration) getConfiguration()).
getDBDictionaryInstance();
return !dict.supportsSubselect;
}
public void setUp() {
deleteAll(HelperPC.class);
deleteAll(EagerOuterJoinPC2.class);
deleteAll(EagerOuterJoinPC.class);
}
public void testQueryRange() {
insertManyStringList();
OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
FetchPlan fetch = (FetchPlan) em.getFetchPlan();
fetch.addField(EagerOuterJoinPC.class, "stringList");
fetch.setFetchBatchSize(3);
OpenJPAQuery q = em.createQuery(JPQLParser.LANG_JPQL,
"select x from EagerOuterJoinPC x order by x.name asc");
q.setFirstResult(5).setMaxResults(15);
List results = (List) q.getResultList();
assertEquals(5, results.size());
for (int i = 0; i < results.size(); i++) {
EagerOuterJoinPC pc = (EagerOuterJoinPC) results.get(i);
assertEquals(String.valueOf(i + 5), pc.getName());
}
q.closeAll();
em.close();
}
@SuppressWarnings("unchecked")
private void insertManyStringList() {
OpenJPAEntityManager em =(OpenJPAEntityManager)currentEntityManager();
startTx(em);;
for (int i = 0; i < 10; i++) {
EagerOuterJoinPC pc = new EagerOuterJoinPC();
pc.setName(String.valueOf(i));
pc.getStringList().add(i + ".1");
pc.getStringList().add(i + ".2");
em.persist(pc);
}
endTx(em);;
em.close();
}
}

View File

@ -39,5 +39,6 @@
<class>org.apache.openjpa.persistence.jdbc.common.apps.HelperPC4</class>
<class>org.apache.openjpa.persistence.jdbc.common.apps.InvertA</class>
<class>org.apache.openjpa.persistence.jdbc.common.apps.InvertB</class>
<class>org.apache.openjpa.persistence.jdbc.common.apps.EagerOuterJoinPC</class>
</persistence-unit>
</persistence>