db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r695066 - in /db/jdo/trunk: api2/src/java/javax/jdo/ api2/src/schema/javax/jdo/ tck2/src/conf/ tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/ tck2/src/java/org/apache/jdo/tck/transactions/
Date Sat, 13 Sep 2008 23:32:22 GMT
Author: clr
Date: Sat Sep 13 16:32:21 2008
New Revision: 695066

URL: http://svn.apache.org/viewvc?rev=695066&view=rev
Log:
Add get/set isolation methods to Transaction and PersistenceManagerFactory
New test cases for Transaction and PersistenceManagerFactory isolation level
New jdoconfig attributes for isolation level
Updated signatures for new methods


Added:
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java
  (with props)
    db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java   (with
props)
Modified:
    db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java
    db/jdo/trunk/api2/src/java/javax/jdo/Transaction.java
    db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.dtd
    db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd
    db/jdo/trunk/tck2/src/conf/jdo-2_2-signatures.txt

Modified: db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java?rev=695066&r1=695065&r2=695066&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/PersistenceManagerFactory.java Sat Sep 13 16:32:21
2008
@@ -488,6 +488,37 @@
      */
     void setReadOnly(boolean flag);
 
+    /** Get the value for transaction isolation level for this PMF.
+     * @return the transaction isolation level
+     * @see #setTransactionIsolationLevel(String)
+     * @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.
+     * Standard values in order from low to high are:
+     * <ul><li>read-uncommitted
+     * </li><li>read-committed
+     * </li><li>repeatable-read
+     * </li><li>snapshot
+     * </li><li>serializable
+     * </li></ul>
+     * @param level the transaction isolation level
+     * @see #getTransactionIsolationLevel()
+     * @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 setTransactionIsolationLevel(String level);
+
     /** Return non-configurable properties of this 
      * <code>PersistenceManagerFactory</code>.
      * Properties with keys <code>VendorName</code> and 
@@ -500,7 +531,7 @@
     /** The application can determine from the results of this
      * method which optional features, and which query languages 
      * are supported by the JDO implementation.
-     * <P>Each supported JDO optional feature is represented by a
+     * <P>Each supported JDO feature is represented by a
      * <code>String</code> with one of the following values:
      *
      * <P><code>javax.jdo.option.TransientTransactional
@@ -510,7 +541,7 @@
      * <BR>javax.jdo.option.Optimistic
      * <BR>javax.jdo.option.ApplicationIdentity
      * <BR>javax.jdo.option.DatastoreIdentity
-     * <BR>javax.jdo.option.NonDatastoreIdentity
+     * <BR>javax.jdo.option.NonDurableIdentity
      * <BR>javax.jdo.option.ArrayList
      * <BR>javax.jdo.option.HashMap
      * <BR>javax.jdo.option.Hashtable
@@ -526,6 +557,11 @@
      * <BR>javax.jdo.option.BinaryCompatibility
      * <BR>javax.jdo.option.GetDataStoreConnection
      * <BR>javax.jdo.option.UnconstrainedQueryVariables
+     * <BR>javax.jdo.option.TransactionIsolationLevel.read-uncommitted
+     * <BR>javax.jdo.option.TransactionIsolationLevel.read-committed
+     * <BR>javax.jdo.option.TransactionIsolationLevel.repeatable-read
+     * <BR>javax.jdo.option.TransactionIsolationLevel.snapshot
+     * <BR>javax.jdo.option.TransactionIsolationLevel.serializable
      * <BR>javax.jdo.query.SQL
      * <BR>javax.jdo.query.JDOQL
      * </code>

Modified: db/jdo/trunk/api2/src/java/javax/jdo/Transaction.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/java/javax/jdo/Transaction.java?rev=695066&r1=695065&r2=695066&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/java/javax/jdo/Transaction.java (original)
+++ db/jdo/trunk/api2/src/java/javax/jdo/Transaction.java Sat Sep 13 16:32:21 2008
@@ -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,39 @@
      */
     boolean getOptimistic();
     
+    /** Get the value for transaction isolation level for this transaction.
+     * @return the transaction isolation level
+     * @see #setIsolationLevel(String)
+     * @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.
+     * <p>Standard values in order of low to high are:
+     * <ul><li>read-uncommitted
+     * </li><li>read-committed
+     * </li><li>repeatable-read
+     * </li><li>snapshot
+     * </li><li>serializable
+     * </li></ul>
+     * @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 <code>Synchronization</code> instance to be 
      * notified on transaction completions.  The <code>beforeCompletion</code>

      * method is called prior to flushing instances to the data store.

Modified: db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.dtd
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.dtd?rev=695066&r1=695065&r2=695066&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.dtd (original)
+++ db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.dtd Sat Sep 13 16:32:21 2008
@@ -33,6 +33,7 @@
 <!ATTLIST persistence-manager-factory nontransactional-read (true|false) CDATA #IMPLIED>
 <!ATTLIST persistence-manager-factory nontransactional-write (true|false) CDATA #IMPLIED>
 <!ATTLIST persistence-manager-factory multithreaded (true|false) CDATA #IMPLIED>
+<!ATTLIST persistence-manager-factory transaction-isolation-level CDATA #IMPLIED>
 <!ATTLIST persistence-manager-factory connection-driver-name CDATA #IMPLIED>
 <!ATTLIST persistence-manager-factory connection-user-name CDATA #IMPLIED>
 <!ATTLIST persistence-manager-factory connection-password CDATA #IMPLIED>

Modified: db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd
URL: http://svn.apache.org/viewvc/db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd?rev=695066&r1=695065&r2=695066&view=diff
==============================================================================
--- db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd (original)
+++ db/jdo/trunk/api2/src/schema/javax/jdo/jdoconfig_2_2.xsd Sat Sep 13 16:32:21 2008
@@ -129,6 +129,8 @@
     <xs:attribute name="nontransactional-write" use="optional"/>
     <!-- Corresponds to standard JDO property javax.jdo.option.Multithreaded. -->
     <xs:attribute name="multithreaded" use="optional"/>
+    <!-- Corresponds to standard JDO property javax.jdo.option.TransactionIsolationLevel.
-->
+    <xs:attribute name="transaction-isolation-level" use="optional"/>
     <!-- Corresponds to standard JDO property javax.jdo.option.ConnectionDriverName. -->
     <xs:attribute name="connection-driver-name" use="optional"/>
     <!-- Corresponds to standard JDO property javax.jdo.option.ConnectionUserName. -->

Modified: db/jdo/trunk/tck2/src/conf/jdo-2_2-signatures.txt
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/conf/jdo-2_2-signatures.txt?rev=695066&r1=695065&r2=695066&view=diff
==============================================================================
--- db/jdo/trunk/tck2/src/conf/jdo-2_2-signatures.txt (original)
+++ db/jdo/trunk/tck2/src/conf/jdo-2_2-signatures.txt Sat Sep 13 16:32:21 2008
@@ -162,6 +162,18 @@
         = "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_TRANSACTION_ISOLATION_LEVEL_READ_UNCOMMITTED
+        = "javax.jdo.option.TransactionIsolationLevel.read-uncommitted";
+    static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_COMMITTED
+        = "javax.jdo.option.TransactionIsolationLevel.read-committed";
+    static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ
+        = "javax.jdo.option.TransactionIsolationLevel.repeatable-read";
+    static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_SNAPSHOT
+        = "javax.jdo.option.TransactionIsolationLevel.snapshot";
+    static String PROPERTY_TRANSACTION_ISOLATION_LEVEL_SERIALIZABLE
+        = "javax.jdo.option.TransactionIsolationLevel.serializable";
     static String PROPERTY_DETACH_ALL_ON_COMMIT
         = "javax.jdo.option.DetachAllOnCommit";
     static String PROPERTY_COPY_ON_ATTACH
@@ -222,6 +234,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 +820,8 @@
     public void setTransactionType(java.lang.String);
     public void setReadOnly(boolean flag);
     public boolean getReadOnly();
+    public void setTransactionIsolationLevel(String);
+    public String getTransactionIsolationLevel();
     public java.util.Properties getProperties();
     public java.util.Collection supportedOptions();
     public javax.jdo.datastore.DataStoreCache getDataStoreCache();
@@ -1088,6 +1107,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();

Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java?rev=695066&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java
(added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java
Sat Sep 13 16:32:21 2008
@@ -0,0 +1,185 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import javax.jdo.Constants;
+import javax.jdo.JDOHelper;
+import javax.jdo.JDOUnsupportedOptionException;
+import javax.jdo.PersistenceManager;
+import javax.jdo.PersistenceManagerFactory;
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+
+/**
+ *<B>Title:</B>Set transaction isolation level of persistencemanagerfactory 

+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A11.1-xxxx, A11.1-xxxx.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * 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
+    };
+
+    private PersistenceManagerFactory pmf2;
+
+    /**
+     * The <code>main</code> 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() {
+        // setUp gets a PMF that needs to be closed
+        closePMF();
+    }
+
+    /** Set TransactionIsolationLevel to all values via API. */ 
+    public void testSetTransactionIsolationLevelByAPI() {
+        // iterate through all possible TransactionIsolationLevels
+        for (int i = 0; i < transactionIsolationLevels.length; ++i) {
+            String transactionIsolationLevel = transactionIsolationLevels[i];
+            setTransactionIsolationLevelByAPI(transactionIsolationLevel);
+        }
+        failOnError();
+    }
+
+    /** Set TransactionIsolationLevel to all values from properties. */ 
+    public void testSetTransactionIsolationLevelFromProperties() {
+        // iterate through all possible TransactionIsolationLevels
+        for (int i = 0; i < transactionIsolationLevels.length; ++i) {
+            String transactionIsolationLevel = transactionIsolationLevels[i];
+            getPMFsetTransactionIsolationLevelFromProperties(transactionIsolationLevel);
+        }
+        failOnError();
+    }
+
+    /** Set TransactionIsolationLevel to all values. */ 
+    public void testTransactionIsolationLevelReadCommittedSupported() {
+        // this test depends on setUp initializing supportedOptions
+        String readCommitted = 
+                PROPERTY_TRANSACTION_ISOLATION_LEVEL_READ_COMMITTED;
+        // make sure read committed is supported
+        if (!isSupported(readCommitted)) {
+                appendMessage(ASSERTION_FAILED
+                    + "\nSupportedOptions does not include "
+                    + readCommitted 
+                    + ".");            
+        }
+        failOnError();
+    }
+
+    /** */
+    private void setTransactionIsolationLevelByAPI(String level) {
+        pmf = getUnconfiguredPMF();
+        String property = PROPERTY_TRANSACTION_ISOLATION_LEVEL + "." + level;
+        if (isSupported(property)) {
+            pmf.setTransactionIsolationLevel(level);
+            String actual = pmf.getTransactionIsolationLevel();
+            if (!validLevelSubstitution(level, actual)) {
+                appendMessage(ASSERTION_FAILED +
+                        "\nTransactionIsolationLevel set to " + level +
+                        "; value returned by PMF is " + actual);
+            }
+        } else {
+            try {
+                pmf.setTransactionIsolationLevel(level);
+                // no exception thrown; bad
+                appendMessage(ASSERTION_FAILED +
+                        "\nThe expected JDOUnsupportedOptionException was not " +
+                        "thrown for unsupported isolation level " + level + ".");       
    
+            } catch (JDOUnsupportedOptionException ex) {
+                // good catch
+            } catch (Throwable t) {
+                appendMessage(ASSERTION_FAILED +
+                        "\nThe expected JDOUnsupportedOptionException was not " +
+                        "thrown for unsupported isolation level " + level +
+                        " but unexpected exception:\n" + t);
+            }
+        }
+        closePMF();
+        return;
+    }
+    /** */
+    private void getPMFsetTransactionIsolationLevelFromProperties(String level) {
+        String property = PROPERTY_TRANSACTION_ISOLATION_LEVEL + "." + level;
+        Map modifiedProps = new HashMap(PMFPropertiesObject);
+        modifiedProps.put(PROPERTY_TRANSACTION_ISOLATION_LEVEL, level);
+        if (isSupported(property)) {
+            pmf2 = JDOHelper.getPersistenceManagerFactory(modifiedProps);
+            String actual = pmf2.getTransactionIsolationLevel();
+            if (!validLevelSubstitution(level, actual)) {
+                appendMessage(ASSERTION_FAILED +
+                        "\nTransactionIsolationLevel set to " + level +
+                        "; value returned by PMF is " + actual);
+            }
+            PersistenceManager pm2 = pmf2.getPersistenceManager();
+            actual = pm2.currentTransaction().getIsolationLevel();
+            if (!validLevelSubstitution(level, actual)) {
+                appendMessage(ASSERTION_FAILED +
+                        "\nTransactionIsolationLevel set to " + level +
+                        "; value returned by Transaction is " + actual);
+            }
+        } else {
+            try {
+                pmf2 = JDOHelper.getPersistenceManagerFactory(modifiedProps);
+                // no exception thrown; bad
+                appendMessage(ASSERTION_FAILED +
+                        "\nThe expected JDOUserException was not thrown for " +
+                        "JDOHelper.getPersistenceManagerFactory " +
+                        "for unsupported isolation level " + level + ".");            
+            } catch (JDOUnsupportedOptionException ex) {
+                // good catch
+            } catch (Throwable t) {
+                appendMessage(ASSERTION_FAILED +
+                        "\nThe expected JDOUserException was not thrown for " +
+                        "JDOHelper.getPersistenceManagerFactory " +
+                        "for unsupported isolation level " + level + 
+                        "but unexpected exception:\n" + t);
+            }
+        }
+        closePMF(pmf2);
+        return;
+    }
+}

Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/api/persistencemanagerfactory/SetTransactionIsolationLevel.java
------------------------------------------------------------------------------
    svn:eol-style = LF

Added: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java
URL: http://svn.apache.org/viewvc/db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java?rev=695066&view=auto
==============================================================================
--- db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java (added)
+++ db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java Sat
Sep 13 16:32:21 2008
@@ -0,0 +1,167 @@
+/*
+ * 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 javax.jdo.Constants;
+import javax.jdo.JDOUnsupportedOptionException;
+import javax.jdo.Transaction;
+import org.apache.jdo.tck.JDO_Test;
+import org.apache.jdo.tck.util.BatchTestRunner;
+
+
+/**
+ *<B>Title:</B>Set  isolation level of transaction  
+ *<BR>
+ *<B>Keywords:</B> persistencemanagerfactory
+ *<BR>
+ *<B>Assertion IDs:</B> A11.1-xxxx, A11.1-xxxx.
+ *<BR>
+ *<B>Assertion Description: </B>
+ * 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_29_FAILED = 
+        "Assertion A13.4.2-29 (setIsolationLevel) failed: ";
+    /** */
+    private static final String ASSERTION_25_FAILED = 
+        "Assertion A13.4.2-25 (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 <code>main</code> 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 testSetIsolationLevelOutsideTransaction() {
+        // iterate through all possible IsolationLevels
+        for (int i = 0; i < isolationLevels.length; ++i) {
+            String isolationLevel = isolationLevels[i];
+            setIsolationLevel(isolationLevel);
+        }
+        closePMF(pmf);
+        failOnError();
+    }
+
+    /** Set IsolationLevel to all values within datastore transaction. */ 
+    public void testSetIsolationLevelWithActiveDataStoreTransaction() {
+        pm.currentTransaction().setOptimistic(false);
+        pm.currentTransaction().begin();
+        // iterate through all possible IsolationLevels
+        for (int i = 0; i < isolationLevels.length; ++i) {
+            String isolationLevel = isolationLevels[i];
+            try {
+                pm.currentTransaction().setIsolationLevel(isolationLevel);
+                appendMessage(ASSERTION_25_FAILED + 
+                        "active datastore transaction; no exception thrown for "
+                        + "setIsolationLevel(" + isolationLevel + ").");
+            } catch (JDOUnsupportedOptionException ex) {
+                // good catch
+            } catch (Throwable t) {
+                appendMessage(ASSERTION_25_FAILED + 
+                        "active datastore transaction; " +
+                        "JDOUnsupportedOptionException not thrown for " +
+                        "setIsolationLevel(" + isolationLevel +
+                        "). Unexpected exception: \n" + t);
+                
+            }
+        }
+        pm.currentTransaction().commit();
+        closePMF(pmf);
+        failOnError();
+    }
+
+    /** Set IsolationLevel to all values within optimistic transaction. */ 
+    public void testSetIsolationLevelWithActiveOptimisticTransaction() {
+        if (!isOptimisticSupported()) {
+            printUnsupportedOptionalFeatureNotTested(
+                    "testSetIsolationLevelWithActiveOptimisticTransaction",
+                    "Optimistic");
+            return;
+        }
+        pm.currentTransaction().setOptimistic(true);
+        pm.currentTransaction().begin();
+        // iterate through all possible IsolationLevels
+        for (int i = 0; i < isolationLevels.length; ++i) {
+            String isolationLevel = isolationLevels[i];
+            setIsolationLevel(isolationLevel);
+        }
+        pm.currentTransaction().commit();
+        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 (!validLevelSubstitution(level, actual)) {
+                appendMessage(ASSERTION_29_FAILED
+                        + "\nIsolationLevel set to "
+                        + level
+                        + "; value returned by Transaction is "
+                        + actual);
+            }
+        } else {
+            try {
+                tx.setIsolationLevel(level);
+                // no exception thrown; bad
+                appendMessage(ASSERTION_29_FAILED
+                        + "\nThe expected JDOUserException was not thrown.");           

+            } catch (JDOUnsupportedOptionException ex) {
+                // good catch
+                return;
+            } catch (Throwable t) {
+                // wrong exception thrown; bad
+                appendMessage(ASSERTION_29_FAILED +
+                        "active datastore transaction; " +
+                        "JDOUnsupportedOptionException not thrown for " +
+                        "setIsolationLevel(" + level +
+                        "). Unexpected exception: \n" + t);
+                return;
+            }
+        }
+    }
+}

Propchange: db/jdo/trunk/tck2/src/java/org/apache/jdo/tck/transactions/SetIsolationLevel.java
------------------------------------------------------------------------------
    svn:eol-style = LF



Mime
View raw message