OPENJPA-182. forUpdateClause is now used even if forUpdate is false, to allow for read-only optimizations. Changed JDBCFetchPlan.setIsolationLevel and JDBCFetchConfiguration.setIsolationLevel to just JDBCFetchXXX.setIsolation.

git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@526266 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2007-04-06 19:50:53 +00:00
parent 31c7a575e7
commit bd93bfa284
9 changed files with 31 additions and 35 deletions

View File

@ -241,17 +241,17 @@ public class DelegatingJDBCFetchConfiguration
} }
} }
public int getIsolationLevel() { public int getIsolation() {
try { try {
return getJDBCDelegate().getIsolationLevel(); return getJDBCDelegate().getIsolation();
} catch (RuntimeException re) { } catch (RuntimeException re) {
throw translate(re); throw translate(re);
} }
} }
public JDBCFetchConfiguration setIsolationLevel(int level) { public JDBCFetchConfiguration setIsolation(int level) {
try { try {
getJDBCDelegate().setIsolationLevel(level); getJDBCDelegate().setIsolation(level);
return this; return this;
} catch (RuntimeException re) { } catch (RuntimeException re) {
throw translate(re); throw translate(re);

View File

@ -186,7 +186,7 @@ public interface JDBCFetchConfiguration
* *
* @since 0.9.7 * @since 0.9.7
*/ */
public int getIsolationLevel(); public int getIsolation();
/** /**
* <p>The isolation level for queries issued to the database. This overrides * <p>The isolation level for queries issued to the database. This overrides
@ -203,5 +203,5 @@ public interface JDBCFetchConfiguration
* *
* @since 0.9.7 * @since 0.9.7
*/ */
public JDBCFetchConfiguration setIsolationLevel(int level); public JDBCFetchConfiguration setIsolation(int level);
} }

View File

@ -322,11 +322,11 @@ public class JDBCFetchConfigurationImpl
return (JDBCConfiguration) conf; return (JDBCConfiguration) conf;
} }
public int getIsolationLevel() { public int getIsolation() {
return _state.isolationLevel; return _state.isolationLevel;
} }
public JDBCFetchConfiguration setIsolationLevel(int level) { public JDBCFetchConfiguration setIsolation(int level) {
if (level != -1 && level != DEFAULT if (level != -1 && level != DEFAULT
&& level != Connection.TRANSACTION_NONE && level != Connection.TRANSACTION_NONE
&& level != Connection.TRANSACTION_READ_UNCOMMITTED && level != Connection.TRANSACTION_READ_UNCOMMITTED

View File

@ -24,7 +24,6 @@ import java.util.StringTokenizer;
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
import org.apache.openjpa.jdbc.schema.Sequence; import org.apache.openjpa.jdbc.schema.Sequence;
import org.apache.openjpa.util.OpenJPAException; import org.apache.openjpa.util.OpenJPAException;
import org.apache.openjpa.kernel.LockLevels;
/** /**
* Dictionary for IBM DB2 database. * Dictionary for IBM DB2 database.
@ -238,8 +237,8 @@ public class DB2Dictionary
try { try {
// Determine the isolationLevel; the fetch // Determine the isolationLevel; the fetch
// configuration data overrides the persistence.xml value // configuration data overrides the persistence.xml value
if (fetch != null && fetch.getIsolationLevel() != -1) if (fetch != null && fetch.getIsolation() != -1)
isolationLevel = fetch.getIsolationLevel(); isolationLevel = fetch.getIsolation();
else else
isolationLevel = conf.getTransactionIsolationConstant(); isolationLevel = conf.getTransactionIsolationConstant();

View File

@ -2145,7 +2145,7 @@ public class DBDictionary
SQLBuffer having, SQLBuffer order, SQLBuffer having, SQLBuffer order,
boolean distinct, boolean forUpdate, long start, long end) { boolean distinct, boolean forUpdate, long start, long end) {
return toOperation(getSelectOperation(fetch), selects, from, where, return toOperation(getSelectOperation(fetch), selects, from, where,
group, having, order, distinct, forUpdate, start, end, group, having, order, distinct, start, end,
getForUpdateClause(fetch, forUpdate)); getForUpdateClause(fetch, forUpdate));
} }
@ -2155,12 +2155,16 @@ public class DBDictionary
*/ */
protected String getForUpdateClause(JDBCFetchConfiguration fetch, protected String getForUpdateClause(JDBCFetchConfiguration fetch,
boolean forUpdate) { boolean forUpdate) {
if (fetch != null && fetch.getIsolationLevel() != -1) if (fetch != null && fetch.getIsolation() != -1) {
throw new IllegalStateException(_loc.get( throw new IllegalStateException(_loc.get(
"isolation-level-config-not-supported", getClass().getName()) "isolation-level-config-not-supported", getClass().getName())
.getMessage()); .getMessage());
else } else if (forUpdate && !simulateLocking) {
assertSupport(supportsSelectForUpdate, "SupportsSelectForUpdate");
return forUpdateClause; return forUpdateClause;
} else {
return null;
}
} }
/** /**
@ -2175,8 +2179,8 @@ public class DBDictionary
*/ */
protected SQLBuffer toOperation(String op, SQLBuffer selects, protected SQLBuffer toOperation(String op, SQLBuffer selects,
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having, SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
SQLBuffer order, boolean distinct, boolean forUpdate, long start, SQLBuffer order, boolean distinct, long start, long end,
long end, String forUpdateClause) { String forUpdateClause) {
SQLBuffer buf = new SQLBuffer(this); SQLBuffer buf = new SQLBuffer(this);
buf.append(op); buf.append(op);
@ -2202,12 +2206,8 @@ public class DBDictionary
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);
if (forUpdateClause != null)
if (forUpdate && !simulateLocking) { buf.append(" ").append(forUpdateClause);
assertSupport(supportsSelectForUpdate, "SupportsSelectForUpdate");
if (forUpdateClause != null)
buf.append(" ").append(forUpdateClause);
}
if (range && rangePosition == RANGE_POST_LOCK) if (range && rangePosition == RANGE_POST_LOCK)
appendSelectRange(buf, start, end); appendSelectRange(buf, start, end);
return buf; return buf;

View File

@ -192,14 +192,14 @@ public class HSQLDictionary
protected SQLBuffer toOperation(String op, SQLBuffer selects, protected SQLBuffer toOperation(String op, SQLBuffer selects,
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having, SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
SQLBuffer order, boolean distinct, boolean forUpdate, long start, SQLBuffer order, boolean distinct, long start, long end,
long end, String forUpdateClause) { String forUpdateClause) {
// hsql requires ordering when limit is used // hsql requires ordering when limit is used
if ((start != 0 || end != Long.MAX_VALUE) if ((start != 0 || end != Long.MAX_VALUE)
&& (order == null || order.isEmpty())) && (order == null || order.isEmpty()))
order = _oneBuffer; order = _oneBuffer;
return super.toOperation(op, selects, from, where, group, having, return super.toOperation(op, selects, from, where, group, having,
order, distinct, forUpdate, start, end, forUpdateClause); order, distinct, start, end, forUpdateClause);
} }
public Column[] getColumns(DatabaseMetaData meta, String catalog, public Column[] getColumns(DatabaseMetaData meta, String catalog,

View File

@ -132,7 +132,7 @@ public interface JDBCFetchPlan
* *
* @since 0.9.7 * @since 0.9.7
*/ */
public int getIsolationLevel(); public int getIsolation();
/** /**
* <p>The isolation level for queries issued to the database. This overrides * <p>The isolation level for queries issued to the database. This overrides
@ -149,5 +149,5 @@ public interface JDBCFetchPlan
* *
* @since 0.9.7 * @since 0.9.7
*/ */
public JDBCFetchPlan setIsolationLevel(int level); public JDBCFetchPlan setIsolation(int level);
} }

View File

@ -103,12 +103,12 @@ public class JDBCFetchPlanImpl
return this; return this;
} }
public int getIsolationLevel() { public int getIsolation() {
return _fetch.getIsolationLevel(); return _fetch.getIsolation();
} }
public JDBCFetchPlan setIsolationLevel(int level) { public JDBCFetchPlan setIsolation(int level) {
_fetch.setIsolationLevel(level); _fetch.setIsolation(level);
return this; return this;
} }
} }

View File

@ -16,14 +16,11 @@
package org.apache.openjpa.persistence.jdbc; package org.apache.openjpa.persistence.jdbc;
import java.sql.Connection; import java.sql.Connection;
import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import javax.persistence.PersistenceException; import javax.persistence.PersistenceException;
import org.apache.openjpa.persistence.test.SQLListenerTestCase; import org.apache.openjpa.persistence.test.SQLListenerTestCase;
import org.apache.openjpa.persistence.simple.AllFieldTypes; import org.apache.openjpa.persistence.simple.AllFieldTypes;
import org.apache.openjpa.persistence.OpenJPAPersistence; import org.apache.openjpa.persistence.OpenJPAPersistence;
import org.apache.openjpa.persistence.FetchPlan;
import org.apache.openjpa.persistence.OpenJPAEntityManager; import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.jdbc.sql.DB2Dictionary; import org.apache.openjpa.jdbc.sql.DB2Dictionary;
@ -53,7 +50,7 @@ public class TestIsolationLevelOverride
try { try {
em.getTransaction().begin(); em.getTransaction().begin();
((JDBCFetchPlan) em.getFetchPlan()) ((JDBCFetchPlan) em.getFetchPlan())
.setIsolationLevel(Connection.TRANSACTION_SERIALIZABLE); .setIsolation(Connection.TRANSACTION_SERIALIZABLE);
em.find(AllFieldTypes.class, 0); em.find(AllFieldTypes.class, 0);
if (dict instanceof DB2Dictionary) { if (dict instanceof DB2Dictionary) {