diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java index 52897c274..b5602fe17 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/TableJDBCSeq.java @@ -461,8 +461,9 @@ public class TableJDBCSeq String tableName = resolveTableName(mapping, _seqColumn.getTable()); SQLBuffer tables = new SQLBuffer(dict).append(tableName); - SQLBuffer select = dict.toSelect(sel, null, tables, where, null, - null, null, false, dict.supportsSelectForUpdate, 0, Long.MAX_VALUE); + SQLBuffer select = dict.toSelect(sel, null, tables, where, null, null, + null, false, dict.supportsSelectForUpdate, 0, Long.MAX_VALUE, + false, true); PreparedStatement stmnt = select.prepareStatement(conn); ResultSet rs = null; 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 087dcca77..e6b4a6cfd 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 @@ -2192,7 +2192,7 @@ public class DBDictionary /** * Combine the given components into a SELECT statement. */ - private SQLBuffer toSelect(SQLBuffer selects, JDBCFetchConfiguration fetch, + 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, @@ -2201,6 +2201,16 @@ public class DBDictionary group, having, order, distinct, start, end, getForUpdateClause(fetch, forUpdate, null), subselect); } + + 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, + boolean subselect, boolean checkTableForUpdate) { + return toOperation(getSelectOperation(fetch), selects, from, where, + group, having, order, distinct, start, end, + getForUpdateClause(fetch, forUpdate, null), subselect, checkTableForUpdate); + } /** * Combine the given components into a SELECT statement. @@ -2242,13 +2252,24 @@ public class DBDictionary /** * Return the SQL for the given selecting operation. */ - protected SQLBuffer toOperation(String op, SQLBuffer selects, + public SQLBuffer toOperation(String op, SQLBuffer selects, SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having, SQLBuffer order, boolean distinct, long start, long end, String forUpdateClause) { return toOperation(op, selects, from, where, group, having, order, distinct, start, end, forUpdateClause, false); } + + /** + * Return the SQL for the given selecting operation. + */ + public 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) { + return toOperation(op, selects, from, where, group, having, order, + distinct, start, end, forUpdateClause, subselect, false); + } /** * Return the SQL for the given selecting operation. @@ -2256,7 +2277,7 @@ public class DBDictionary 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) { + String forUpdateClause, boolean subselect, boolean checkTableForUpdate) { SQLBuffer buf = new SQLBuffer(this); buf.append(op); @@ -2270,6 +2291,12 @@ public class DBDictionary buf.append(" ").append(selects).append(" FROM ").append(from); + if (checkTableForUpdate + && (StringUtils.isEmpty(forUpdateClause) && !StringUtils + .isEmpty(tableForUpdateClause))) { + buf.append(" ").append(tableForUpdateClause); + } + if (where != null && !where.isEmpty()) buf.append(" WHERE ").append(where); if (group != null && !group.isEmpty()) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java index 96e354af4..9a241a518 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java @@ -193,7 +193,7 @@ public class HSQLDictionary return buf.toString(); } - protected SQLBuffer toOperation(String op, SQLBuffer selects, + public SQLBuffer toOperation(String op, SQLBuffer selects, SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having, SQLBuffer order, boolean distinct, long start, long end, String forUpdateClause) {