diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java index a65b490d4..04115b5eb 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java @@ -313,12 +313,12 @@ public class DB2Dictionary * updateClause and isolationLevel hints */ protected String getForUpdateClause(JDBCFetchConfiguration fetch, - boolean isForUpdate) { + boolean isForUpdate, Select sel) { int isolationLevel; // For db2UDBV81OrEarlier and db2ISeriesV5R3OrEarlier: // "optimize for" clause appears before "for update" clause. StringBuffer forUpdateString = new StringBuffer( - getOptimizeClause(fetch)); + getOptimizeClause(sel)); try { // Determine the isolationLevel; the fetch // configuration data overrides the persistence.xml value @@ -464,7 +464,7 @@ public class DB2Dictionary } } - protected String getOptimizeClause(JDBCFetchConfiguration fetch) { + protected String getOptimizeClause(Select sel) { if (sel != null && sel.getExpectedResultCount() > 0) { StringBuffer buf = new StringBuffer(); buf.append(" ").append(optimizeClause).append(" ") diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index 3ac0f2610..782ccdb51 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -60,7 +60,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.HashMap; import javax.sql.DataSource; import org.apache.commons.lang.StringUtils; @@ -70,8 +69,6 @@ import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.kernel.exps.ExpContext; import org.apache.openjpa.jdbc.kernel.exps.ExpState; import org.apache.openjpa.jdbc.kernel.exps.FilterValue; -import org.apache.openjpa.jdbc.kernel.exps.Lit; -import org.apache.openjpa.jdbc.kernel.exps.Param; import org.apache.openjpa.jdbc.kernel.exps.Val; import org.apache.openjpa.jdbc.meta.ClassMapping; import org.apache.openjpa.jdbc.meta.FieldMapping; @@ -88,7 +85,6 @@ import org.apache.openjpa.jdbc.schema.Sequence; import org.apache.openjpa.jdbc.schema.Table; import org.apache.openjpa.jdbc.schema.Unique; import org.apache.openjpa.kernel.Filters; -import org.apache.openjpa.kernel.exps.Path; import org.apache.openjpa.lib.conf.Configurable; import org.apache.openjpa.lib.conf.Configuration; import org.apache.openjpa.lib.jdbc.ConnectionDecorator; @@ -325,7 +321,6 @@ public class DBDictionary private Method _setBytes = null; private Method _setString = null; private Method _setCharStream = null; - protected transient Select sel = null; public DBDictionary() { fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{ @@ -1989,7 +1984,6 @@ public class DBDictionary */ public SQLBuffer toSelect(Select sel, boolean forUpdate, JDBCFetchConfiguration fetch) { - this.sel = sel; sel.addJoinClassConditions(); boolean update = forUpdate && sel.getFromSelect() == null; SQLBuffer select = getSelects(sel, false, update); @@ -2004,7 +1998,7 @@ public class DBDictionary SQLBuffer where = getWhere(sel, update); return toSelect(select, fetch, from, where, sel.getGrouping(), sel.getHaving(), ordering, sel.isDistinct(), forUpdate, - sel.getStartIndex(), sel.getEndIndex()); + sel.getStartIndex(), sel.getEndIndex(), sel); } /** @@ -2192,7 +2186,20 @@ public class DBDictionary boolean distinct, boolean forUpdate, long start, long end) { return toOperation(getSelectOperation(fetch), selects, from, where, group, having, order, distinct, start, end, - getForUpdateClause(fetch, forUpdate)); + getForUpdateClause(fetch, forUpdate, null)); + } + + /** + * Combine the given components into a SELECT statement. + */ + public SQLBuffer toSelect(SQLBuffer selects, JDBCFetchConfiguration fetch, + SQLBuffer from, SQLBuffer where, SQLBuffer group, + SQLBuffer having, SQLBuffer order, + boolean distinct, boolean forUpdate, long start, long end + , Select sel) { + return toOperation(getSelectOperation(fetch), selects, from, where, + group, having, order, distinct, start, end, + getForUpdateClause(fetch, forUpdate, sel)); } /** @@ -2200,7 +2207,7 @@ public class DBDictionary * updateClause and isolationLevel hints */ protected String getForUpdateClause(JDBCFetchConfiguration fetch, - boolean isForUpdate) { + boolean isForUpdate, Select sel) { if (fetch != null && fetch.getIsolation() != -1) { throw new InvalidStateException(_loc.get( "isolation-level-config-not-supported", getClass().getName()));