mirror of https://github.com/apache/openjpa.git
OPENJPA-378 DB2 "FETCH FIRST <n> ROWS ONLY" clause should not be generated in subselect for SELECT COUNT(*) from (subselect ...) s
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@577973 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cea8ab57d1
commit
5d4d50df96
|
@ -148,11 +148,14 @@ public class DB2Dictionary
|
||||||
&& super.supportsRandomAccessResultSet(sel, forUpdate);
|
&& super.supportsRandomAccessResultSet(sel, forUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendSelectRange(SQLBuffer buf, long start, long end) {
|
protected void appendSelectRange(SQLBuffer buf, long start, long end,
|
||||||
|
boolean subselect) {
|
||||||
// appends the literal range string, since DB2 is unable to handle
|
// appends the literal range string, since DB2 is unable to handle
|
||||||
// a bound parameter for it
|
// a bound parameter for it
|
||||||
buf.append(" FETCH FIRST ").append(Long.toString(end)).
|
// do not generate FETCH FIRST clause for subselect
|
||||||
append(" ROWS ONLY");
|
if (!subselect)
|
||||||
|
buf.append(" FETCH FIRST ").append(Long.toString(end)).
|
||||||
|
append(" ROWS ONLY");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel,
|
protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel,
|
||||||
|
|
|
@ -1742,7 +1742,7 @@ public class DBDictionary
|
||||||
from.append("(");
|
from.append("(");
|
||||||
from.append(toSelect(subSelect, null, subFrom, where,
|
from.append(toSelect(subSelect, null, subFrom, where,
|
||||||
sel.getGrouping(), sel.getHaving(), null, sel.isDistinct(),
|
sel.getGrouping(), sel.getHaving(), null, sel.isDistinct(),
|
||||||
false, sel.getStartIndex(), sel.getEndIndex()));
|
false, sel.getStartIndex(), sel.getEndIndex(), true));
|
||||||
from.append(")");
|
from.append(")");
|
||||||
if (requiresAliasForSubselect)
|
if (requiresAliasForSubselect)
|
||||||
from.append(" ").append(Select.FROM_SELECT_ALIAS);
|
from.append(" ").append(Select.FROM_SELECT_ALIAS);
|
||||||
|
@ -2189,6 +2189,19 @@ public class DBDictionary
|
||||||
getForUpdateClause(fetch, forUpdate, null));
|
getForUpdateClause(fetch, forUpdate, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combine the given components into a SELECT statement.
|
||||||
|
*/
|
||||||
|
private 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) {
|
||||||
|
return toOperation(getSelectOperation(fetch), selects, from, where,
|
||||||
|
group, having, order, distinct, start, end,
|
||||||
|
getForUpdateClause(fetch, forUpdate, null), subselect);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combine the given components into a SELECT statement.
|
* Combine the given components into a SELECT statement.
|
||||||
*/
|
*/
|
||||||
|
@ -2233,16 +2246,27 @@ public class DBDictionary
|
||||||
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
|
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
|
||||||
SQLBuffer order, boolean distinct, long start, long end,
|
SQLBuffer order, boolean distinct, long start, long end,
|
||||||
String forUpdateClause) {
|
String forUpdateClause) {
|
||||||
|
return toOperation(op, selects, from, where, group, having, order,
|
||||||
|
distinct, start, end, forUpdateClause, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the SQL for the given selecting operation.
|
||||||
|
*/
|
||||||
|
private SQLBuffer toOperation(String op, SQLBuffer selects,
|
||||||
|
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
|
||||||
|
SQLBuffer order, boolean distinct, long start, long end,
|
||||||
|
String forUpdateClause, boolean subselect) {
|
||||||
SQLBuffer buf = new SQLBuffer(this);
|
SQLBuffer buf = new SQLBuffer(this);
|
||||||
buf.append(op);
|
buf.append(op);
|
||||||
|
|
||||||
boolean range = start != 0 || end != Long.MAX_VALUE;
|
boolean range = start != 0 || end != Long.MAX_VALUE;
|
||||||
if (range && rangePosition == RANGE_PRE_DISTINCT)
|
if (range && rangePosition == RANGE_PRE_DISTINCT)
|
||||||
appendSelectRange(buf, start, end);
|
appendSelectRange(buf, start, end, subselect);
|
||||||
if (distinct)
|
if (distinct)
|
||||||
buf.append(" DISTINCT");
|
buf.append(" DISTINCT");
|
||||||
if (range && rangePosition == RANGE_POST_DISTINCT)
|
if (range && rangePosition == RANGE_POST_DISTINCT)
|
||||||
appendSelectRange(buf, start, end);
|
appendSelectRange(buf, start, end, subselect);
|
||||||
|
|
||||||
buf.append(" ").append(selects).append(" FROM ").append(from);
|
buf.append(" ").append(selects).append(" FROM ").append(from);
|
||||||
|
|
||||||
|
@ -2257,11 +2281,11 @@ public class DBDictionary
|
||||||
if (order != null && !order.isEmpty())
|
if (order != null && !order.isEmpty())
|
||||||
buf.append(" ORDER BY ").append(order);
|
buf.append(" ORDER BY ").append(order);
|
||||||
if (range && rangePosition == RANGE_POST_SELECT)
|
if (range && rangePosition == RANGE_POST_SELECT)
|
||||||
appendSelectRange(buf, start, end);
|
appendSelectRange(buf, start, end, subselect);
|
||||||
if (forUpdateClause != null)
|
if (forUpdateClause != null)
|
||||||
buf.append(" ").append(forUpdateClause);
|
buf.append(" ").append(forUpdateClause);
|
||||||
if (range && rangePosition == RANGE_POST_LOCK)
|
if (range && rangePosition == RANGE_POST_LOCK)
|
||||||
appendSelectRange(buf, start, end);
|
appendSelectRange(buf, start, end, subselect);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2269,7 +2293,8 @@ public class DBDictionary
|
||||||
* If this dictionary can select ranges,
|
* If this dictionary can select ranges,
|
||||||
* use this method to append the range SQL.
|
* use this method to append the range SQL.
|
||||||
*/
|
*/
|
||||||
protected void appendSelectRange(SQLBuffer buf, long start, long end) {
|
protected void appendSelectRange(SQLBuffer buf, long start, long end
|
||||||
|
, boolean subselect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue