mirror of https://github.com/apache/openjpa.git
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:
parent
31c7a575e7
commit
bd93bfa284
|
@ -241,17 +241,17 @@ public class DelegatingJDBCFetchConfiguration
|
|||
}
|
||||
}
|
||||
|
||||
public int getIsolationLevel() {
|
||||
public int getIsolation() {
|
||||
try {
|
||||
return getJDBCDelegate().getIsolationLevel();
|
||||
return getJDBCDelegate().getIsolation();
|
||||
} catch (RuntimeException re) {
|
||||
throw translate(re);
|
||||
}
|
||||
}
|
||||
|
||||
public JDBCFetchConfiguration setIsolationLevel(int level) {
|
||||
public JDBCFetchConfiguration setIsolation(int level) {
|
||||
try {
|
||||
getJDBCDelegate().setIsolationLevel(level);
|
||||
getJDBCDelegate().setIsolation(level);
|
||||
return this;
|
||||
} catch (RuntimeException re) {
|
||||
throw translate(re);
|
||||
|
|
|
@ -186,7 +186,7 @@ public interface JDBCFetchConfiguration
|
|||
*
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public int getIsolationLevel();
|
||||
public int getIsolation();
|
||||
|
||||
/**
|
||||
* <p>The isolation level for queries issued to the database. This overrides
|
||||
|
@ -203,5 +203,5 @@ public interface JDBCFetchConfiguration
|
|||
*
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public JDBCFetchConfiguration setIsolationLevel(int level);
|
||||
public JDBCFetchConfiguration setIsolation(int level);
|
||||
}
|
||||
|
|
|
@ -322,11 +322,11 @@ public class JDBCFetchConfigurationImpl
|
|||
return (JDBCConfiguration) conf;
|
||||
}
|
||||
|
||||
public int getIsolationLevel() {
|
||||
public int getIsolation() {
|
||||
return _state.isolationLevel;
|
||||
}
|
||||
|
||||
public JDBCFetchConfiguration setIsolationLevel(int level) {
|
||||
public JDBCFetchConfiguration setIsolation(int level) {
|
||||
if (level != -1 && level != DEFAULT
|
||||
&& level != Connection.TRANSACTION_NONE
|
||||
&& level != Connection.TRANSACTION_READ_UNCOMMITTED
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.StringTokenizer;
|
|||
import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
|
||||
import org.apache.openjpa.jdbc.schema.Sequence;
|
||||
import org.apache.openjpa.util.OpenJPAException;
|
||||
import org.apache.openjpa.kernel.LockLevels;
|
||||
|
||||
/**
|
||||
* Dictionary for IBM DB2 database.
|
||||
|
@ -238,8 +237,8 @@ public class DB2Dictionary
|
|||
try {
|
||||
// Determine the isolationLevel; the fetch
|
||||
// configuration data overrides the persistence.xml value
|
||||
if (fetch != null && fetch.getIsolationLevel() != -1)
|
||||
isolationLevel = fetch.getIsolationLevel();
|
||||
if (fetch != null && fetch.getIsolation() != -1)
|
||||
isolationLevel = fetch.getIsolation();
|
||||
else
|
||||
isolationLevel = conf.getTransactionIsolationConstant();
|
||||
|
||||
|
|
|
@ -2145,7 +2145,7 @@ public class DBDictionary
|
|||
SQLBuffer having, SQLBuffer order,
|
||||
boolean distinct, boolean forUpdate, long start, long end) {
|
||||
return toOperation(getSelectOperation(fetch), selects, from, where,
|
||||
group, having, order, distinct, forUpdate, start, end,
|
||||
group, having, order, distinct, start, end,
|
||||
getForUpdateClause(fetch, forUpdate));
|
||||
}
|
||||
|
||||
|
@ -2155,12 +2155,16 @@ public class DBDictionary
|
|||
*/
|
||||
protected String getForUpdateClause(JDBCFetchConfiguration fetch,
|
||||
boolean forUpdate) {
|
||||
if (fetch != null && fetch.getIsolationLevel() != -1)
|
||||
if (fetch != null && fetch.getIsolation() != -1) {
|
||||
throw new IllegalStateException(_loc.get(
|
||||
"isolation-level-config-not-supported", getClass().getName())
|
||||
.getMessage());
|
||||
else
|
||||
} else if (forUpdate && !simulateLocking) {
|
||||
assertSupport(supportsSelectForUpdate, "SupportsSelectForUpdate");
|
||||
return forUpdateClause;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2175,8 +2179,8 @@ public class DBDictionary
|
|||
*/
|
||||
protected SQLBuffer toOperation(String op, SQLBuffer selects,
|
||||
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
|
||||
SQLBuffer order, boolean distinct, boolean forUpdate, long start,
|
||||
long end, String forUpdateClause) {
|
||||
SQLBuffer order, boolean distinct, long start, long end,
|
||||
String forUpdateClause) {
|
||||
SQLBuffer buf = new SQLBuffer(this);
|
||||
buf.append(op);
|
||||
|
||||
|
@ -2202,12 +2206,8 @@ public class DBDictionary
|
|||
buf.append(" ORDER BY ").append(order);
|
||||
if (range && rangePosition == RANGE_POST_SELECT)
|
||||
appendSelectRange(buf, start, end);
|
||||
|
||||
if (forUpdate && !simulateLocking) {
|
||||
assertSupport(supportsSelectForUpdate, "SupportsSelectForUpdate");
|
||||
if (forUpdateClause != null)
|
||||
buf.append(" ").append(forUpdateClause);
|
||||
}
|
||||
if (forUpdateClause != null)
|
||||
buf.append(" ").append(forUpdateClause);
|
||||
if (range && rangePosition == RANGE_POST_LOCK)
|
||||
appendSelectRange(buf, start, end);
|
||||
return buf;
|
||||
|
|
|
@ -192,14 +192,14 @@ public class HSQLDictionary
|
|||
|
||||
protected SQLBuffer toOperation(String op, SQLBuffer selects,
|
||||
SQLBuffer from, SQLBuffer where, SQLBuffer group, SQLBuffer having,
|
||||
SQLBuffer order, boolean distinct, boolean forUpdate, long start,
|
||||
long end, String forUpdateClause) {
|
||||
SQLBuffer order, boolean distinct, long start, long end,
|
||||
String forUpdateClause) {
|
||||
// hsql requires ordering when limit is used
|
||||
if ((start != 0 || end != Long.MAX_VALUE)
|
||||
&& (order == null || order.isEmpty()))
|
||||
order = _oneBuffer;
|
||||
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,
|
||||
|
|
|
@ -132,7 +132,7 @@ public interface JDBCFetchPlan
|
|||
*
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public int getIsolationLevel();
|
||||
public int getIsolation();
|
||||
|
||||
/**
|
||||
* <p>The isolation level for queries issued to the database. This overrides
|
||||
|
@ -149,5 +149,5 @@ public interface JDBCFetchPlan
|
|||
*
|
||||
* @since 0.9.7
|
||||
*/
|
||||
public JDBCFetchPlan setIsolationLevel(int level);
|
||||
public JDBCFetchPlan setIsolation(int level);
|
||||
}
|
||||
|
|
|
@ -103,12 +103,12 @@ public class JDBCFetchPlanImpl
|
|||
return this;
|
||||
}
|
||||
|
||||
public int getIsolationLevel() {
|
||||
return _fetch.getIsolationLevel();
|
||||
public int getIsolation() {
|
||||
return _fetch.getIsolation();
|
||||
}
|
||||
|
||||
public JDBCFetchPlan setIsolationLevel(int level) {
|
||||
_fetch.setIsolationLevel(level);
|
||||
public JDBCFetchPlan setIsolation(int level) {
|
||||
_fetch.setIsolation(level);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,11 @@
|
|||
package org.apache.openjpa.persistence.jdbc;
|
||||
|
||||
import java.sql.Connection;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.LockModeType;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
|
||||
import org.apache.openjpa.persistence.simple.AllFieldTypes;
|
||||
import org.apache.openjpa.persistence.OpenJPAPersistence;
|
||||
import org.apache.openjpa.persistence.FetchPlan;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||
import org.apache.openjpa.jdbc.sql.DBDictionary;
|
||||
import org.apache.openjpa.jdbc.sql.DB2Dictionary;
|
||||
|
@ -53,7 +50,7 @@ public class TestIsolationLevelOverride
|
|||
try {
|
||||
em.getTransaction().begin();
|
||||
((JDBCFetchPlan) em.getFetchPlan())
|
||||
.setIsolationLevel(Connection.TRANSACTION_SERIALIZABLE);
|
||||
.setIsolation(Connection.TRANSACTION_SERIALIZABLE);
|
||||
em.find(AllFieldTypes.class, 0);
|
||||
|
||||
if (dict instanceof DB2Dictionary) {
|
||||
|
|
Loading…
Reference in New Issue