Index: api2/src/schema/javax/jdo/jdoconfig_2_2.xsd =================================================================== --- api2/src/schema/javax/jdo/jdoconfig_2_2.xsd (revision 693180) +++ api2/src/schema/javax/jdo/jdoconfig_2_2.xsd (working copy) @@ -129,6 +129,8 @@ + + Index: api2/src/schema/javax/jdo/jdoconfig_2_2.dtd =================================================================== --- api2/src/schema/javax/jdo/jdoconfig_2_2.dtd (revision 693180) +++ api2/src/schema/javax/jdo/jdoconfig_2_2.dtd (working copy) @@ -33,6 +33,7 @@ + Index: api2/src/java/javax/jdo/Constants.java =================================================================== --- api2/src/java/javax/jdo/Constants.java (revision 693180) +++ api2/src/java/javax/jdo/Constants.java (working copy) @@ -21,6 +21,7 @@ * Constant values used in JDO. * * @since 2.1 + * @version 2.2 */ public interface Constants { @@ -611,6 +612,53 @@ static String PROPERTY_MULTITHREADED = "javax.jdo.option.Multithreaded"; /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL + = "javax.jdo.option.TransactionIsolationLevel"; + /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @see PersistenceManagerFactory#supportedOptions() + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_UNCOMMITTED + = "javax.jdo.option.TransactionIsolationLevel.read-uncommitted"; + /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @see PersistenceManagerFactory#supportedOptions() + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_COMMITTED + = "javax.jdo.option.TransactionIsolationLevel.read-committed"; + /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @see PersistenceManagerFactory#supportedOptions() + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ + = "javax.jdo.option.TransactionIsolationLevel.repeatable-read"; + /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @see PersistenceManagerFactory#supportedOptions() + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_SNAPSHOE + = "javax.jdo.option.TransactionIsolationLevel.snapshot"; + /** + * "javax.jdo.option.TransactionIsolationLevel" + * + * @see PersistenceManagerFactory#supportedOptions() + * @since 2.2 + */ + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_SERIALIZABLE + = "javax.jdo.option.TransactionIsolationLevel.serializable"; + /** * "javax.jdo.option.DetachAllOnCommit" * * @see PersistenceManagerFactory#getDetachAllOnCommit() @@ -877,5 +925,45 @@ */ static String ANONYMOUS_PERSISTENCE_MANAGER_FACTORY_NAME = ""; + + /** + * Transaction isolation level representing the ability to read + * uncommitted data. + * @see PersistenceManagerFactory#getTransactionIsolationLevel() + * @since 2.2 + */ + public static final String TX_READ_UNCOMMITTED = "read-uncommitted"; + + /** + * Transaction isolation level representing the requirement to read + * committed data only. + * @see PersistenceManagerFactory#getTransactionIsolationLevel() + * @since 2.2 + */ + public static final String TX_READ_COMMITTED = "read-committed"; + + /** + * Transaction isolation level representing the requirement to read + * the same data in the same transaction. + * @see PersistenceManagerFactory#getTransactionIsolationLevel() + * @since 2.2 + */ + public static final String TX_REPEATABLE_READ = "repeatable-read"; + + /** + * Transaction isolation level representing the requirement to keep + * a snapshot for reading data. + * @see PersistenceManagerFactory#getTransactionIsolationLevel() + * @since 2.2 + */ + public static final String TX_SNAPSHOT = "snapshot"; + + /** + * Transaction isolation level representing the requirement to serialize + * transactions. + * @see PersistenceManagerFactory#getTransactionIsolationLevel() + * @since 2.2 + */ + public static final String TX_SERIALIZABLE = "serializable"; + } - Index: api2/src/java/javax/jdo/Transaction.java =================================================================== --- api2/src/java/javax/jdo/Transaction.java (revision 693180) +++ api2/src/java/javax/jdo/Transaction.java (working copy) @@ -38,7 +38,7 @@ * environment. When used in a managed environment, transaction initiation * and completion methods may only be used with bean-managed transaction * semantics. - * @version 2.0 + * @version 2.2 */ public interface Transaction @@ -166,6 +166,31 @@ */ boolean getOptimistic(); + /** Get the value for transaction isolation level for this transaction. + * @return the transaction isolation level + * @since 2.2 + */ + String getIsolationLevel(); + + /** Set the value for transaction isolation level for this transaction. + * Transaction isolation levels are defined in javax.jdo.Constants. + * If the requested level is not available, but a higher level is + * available, the higher level is silently used. + * If the requested level is not available, and no higher level is + * available, then JDOUnsupportedOptionException is thrown. + * Five standard isolation levels are defined. Other isolation levels + * might be supported by an implementation but are not standard. + * @param level the transaction isolation level + * @see #getIsolationLevel() + * @see Constants#TX_READ_UNCOMMITTED + * @see Constants#TX_READ_COMMITTED + * @see Constants#TX_REPEATABLE_READ + * @see Constants#TX_SNAPSHOT + * @see Constants#TX_SERIALIZABLE + * @since 2.2 + */ + void setIsolationLevel(String level); + /** The user can specify a Synchronization instance to be * notified on transaction completions. The beforeCompletion * method is called prior to flushing instances to the data store. Index: api2/src/java/javax/jdo/PersistenceManagerFactory.java =================================================================== --- api2/src/java/javax/jdo/PersistenceManagerFactory.java (revision 693266) +++ api2/src/java/javax/jdo/PersistenceManagerFactory.java (working copy) @@ -488,6 +488,24 @@ */ void setReadOnly(boolean flag); + /** Get the value for transaction isolation level for this PMF. + * @return the transaction isolation level + * @since 2.2 + */ + String getTransactionIsolationLevel(); + + /** Set the value for transaction isolation level for this PMF. + * Transaction isolation levels are defined in javax.jdo.Constants. + * If the requested level is not available, but a higher level is + * available, the higher level is silently used. + * If the requested level is not available, and no higher level is + * available, then JDOUnsupportedOptionException is thrown. + * @param level the transaction isolation level + * @see #getTransactionIsolationLevel() + * @since 2.2 + */ + void setTransactionIsolationLevel(String level); + /** Return non-configurable properties of this * PersistenceManagerFactory. * Properties with keys VendorName and Index: tck2/src/conf/jdo-2_2-signatures.txt =================================================================== --- tck2/src/conf/jdo-2_2-signatures.txt (revision 693276) +++ tck2/src/conf/jdo-2_2-signatures.txt (working copy) @@ -162,6 +162,8 @@ = "javax.jdo.option.NontransactionalWrite"; static String PROPERTY_MULTITHREADED = "javax.jdo.option.Multithreaded"; + static String PROPERTY_TRANSACTION_ISOLATION_LEVEL + = "javax.jdo.option.TransactionIsolationLevel"; static String PROPERTY_DETACH_ALL_ON_COMMIT = "javax.jdo.option.DetachAllOnCommit"; static String PROPERTY_COPY_ON_ATTACH @@ -222,6 +224,11 @@ = "javax/jdo/jdoquery_2_2.xsd"; static String ANONYMOUS_PERSISTENCE_MANAGER_FACTORY_NAME = ""; + public static final String TX_READ_UNCOMMITTED = "read-uncommitted"; + public static final String TX_READ_COMMITTED = "read-committed"; + public static final String TX_REPEATABLE_READ = "repeatable-read"; + public static final String TX_SNAPSHOT = "snapshot"; + public static final String TX_SERIALIZABLE = "serializable"; } public interface javax.jdo.datastore.DataStoreCache { @@ -803,6 +810,8 @@ public void setTransactionType(java.lang.String); public void setReadOnly(boolean flag); public boolean getReadOnly(); + public void setTransactionIsolationLevel(java.lang.String); + public java.lang.String getTransactionIsolationLevel(); public java.util.Properties getProperties(); public java.util.Collection supportedOptions(); public javax.jdo.datastore.DataStoreCache getDataStoreCache(); @@ -1088,6 +1097,8 @@ public boolean getRestoreValues(); public void setOptimistic(boolean optimistic); public boolean getOptimistic(); + void setIsolationLevel(String level); + String getIsolationLevel(); public void setSynchronization(javax.transaction.Synchronization sync); public javax.transaction.Synchronization getSynchronization(); public javax.jdo.PersistenceManager getPersistenceManager(); Index: tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java =================================================================== --- tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java (revision 0) +++ tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java (revision 0) @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.transactions; + +import org.apache.jdo.tck.api.persistencemanagerfactory.*; +import javax.jdo.Constants; +import javax.jdo.JDOUserException; +import javax.jdo.Transaction; +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title:Set isolation level of transaction + *
+ *Keywords: persistencemanagerfactory + *
+ *Assertion IDs: A11.1-xxxx, A11.1-xxxx. + *
+ *Assertion Description: + * Transaction.getIsolationLevel() returns the value + * of the isolation level. + * Transaction.setIsolationLevel(String) sets the value + * of the isolation level. + */ + +public class SetIsolationLevel extends JDO_Test + implements Constants { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A13.4.2-xxx (setIsolationLevel) failed: "; + + /** All specified isolation levels */ + private static final String[] isolationLevels = new String[] { + TX_READ_UNCOMMITTED, + TX_READ_COMMITTED, + TX_REPEATABLE_READ, + TX_SNAPSHOT, + TX_SERIALIZABLE + }; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetIsolationLevel.class); + } + + /** */ + protected void localSetUp() { + pm = getPM(); + } + + /** Set IsolationLevel to all values. */ + public void test() { + // iterate through all possible IsolationLevels + for (int i = 0; i < isolationLevels.length; ++i) { + String isolationLevel = isolationLevels[i]; + setIsolationLevel(isolationLevel); + } + closePMF(pmf); + failOnError(); + } + + /** */ + private void setIsolationLevel(String level) { + Transaction tx = pm.currentTransaction(); + String property = PROPERTY_TRANSACTION_ISOLATION_LEVEL + "." + level; + if (isSupported(property)) { + tx.setIsolationLevel(level); + String actual = tx.getIsolationLevel(); + if (!level.equals(actual)) { + appendMessage(ASSERTION_FAILED + + "\nIsolationLevel set to " + + level + + "; value returned by PMF is " + + actual); + } + } else { + try { + tx.setIsolationLevel(level); + } catch (JDOUserException ex) { + // good catch + return; + } catch (Throwable t) { + appendMessage(ASSERTION_FAILED + + "\nThe expected JDOUserException was not thrown, but " + + t + " was thrown instead."); + return; + } + // no exception thrown; bad + appendMessage(ASSERTION_FAILED + + "\nThe expected JDOUserException was not thrown."); + } + } +} Property changes on: tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java ___________________________________________________________________ Name: svn:eol-style + LF Index: tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java =================================================================== --- tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java (revision 0) +++ tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java (revision 0) @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jdo.tck.api.persistencemanagerfactory; + +import javax.jdo.Constants; +import javax.jdo.JDOUserException; +import org.apache.jdo.tck.JDO_Test; +import org.apache.jdo.tck.util.BatchTestRunner; + + +/** + *Title:Set transaction isolation level of persistencemanagerfactory + *
+ *Keywords: persistencemanagerfactory + *
+ *Assertion IDs: A11.1-xxxx, A11.1-xxxx. + *
+ *Assertion Description: + * PersistenceManagerFactory.getTransactionIsolationLevel() returns the value + * of the transaction isolation level. + * PersistenceManagerFactory.setTransactionIsolationLevel(String) sets the value + * of the transaction isolation level. + */ + +public class SetTransactionIsolationLevel extends JDO_Test + implements Constants { + + /** */ + private static final String ASSERTION_FAILED = + "Assertion A11.1-1, A11.1-2 (setTransactionIsolationLevel) failed: "; + + /** All specified transaction isolation levels */ + private static final String[] transactionIsolationLevels = new String[] { + TX_READ_UNCOMMITTED, + TX_READ_COMMITTED, + TX_REPEATABLE_READ, + TX_SNAPSHOT, + TX_SERIALIZABLE + }; + + /** + * The main is called when the class + * is directly executed from the command line. + * @param args The arguments passed to the program. + */ + public static void main(String[] args) { + BatchTestRunner.run(SetTransactionIsolationLevel.class); + } + + /** */ + protected void localSetUp() { + closePMF(); + pmf = getUnconfiguredPMF(); + } + + /** Set TransactionIsolationLevel to all values. */ + public void test() { + String readCommitted = PROPERTY_TRANSACTION_ISOLATION_LEVEL + + "." + TX_READ_COMMITTED; + // make sure read committed is supported + if (!isSupported(readCommitted)) { + appendMessage(ASSERTION_FAILED + + "\nSupportedOptions does not include " + + readCommitted + + "."); + } + // iterate through all possible TransactionIsolationLevels + for (int i = 0; i < transactionIsolationLevels.length; ++i) { + String transactionIsolationLevel = transactionIsolationLevels[i]; + setTransactionIsolationLevel(transactionIsolationLevel); + } + closePMF(pmf); + failOnError(); + } + + /** */ + private void setTransactionIsolationLevel(String level) { + String property = PROPERTY_TRANSACTION_ISOLATION_LEVEL + level; + if (isSupported(property)) { + pmf.setTransactionIsolationLevel(level); + String actual = pmf.getTransactionIsolationLevel(); + if (!level.equals(actual)) { + appendMessage(ASSERTION_FAILED + + "\nTransactionIsolationLevel set to " + + level + + "; value returned by PMF is " + + actual); + } + } else { + try { + pmf.setTransactionIsolationLevel(level); + } catch (JDOUserException ex) { + // good catch + return; + } catch (Throwable t) { + appendMessage(ASSERTION_FAILED + + "\nThe expected JDOUserException was not thrown, but " + + t + " was thrown instead."); + return; + } + // no exception thrown; bad + appendMessage(ASSERTION_FAILED + + "\nThe expected JDOUserException was not thrown."); + } + } +} Property changes on: tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java ___________________________________________________________________ Name: svn:eol-style + LF Index: tck2/src/java/org/apache/jdo/tck/JDO_Test.java =================================================================== --- tck2/src/java/org/apache/jdo/tck/JDO_Test.java (revision 693180) +++ tck2/src/java/org/apache/jdo/tck/JDO_Test.java (working copy) @@ -858,7 +858,12 @@ return getPMF().supportedOptions().contains( "javax.jdo.option.GetDataStoreConnection"); } - + + /** Reports whether a feature is supported */ + public boolean isSupported(String option) { + return getPMF().supportedOptions().contains(option); + } + /** * Determine if a class is loadable in the current environment. */