db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mz...@apache.org
Subject svn commit: r388087 - in /db/jdo/trunk/tck20/src: conf/ java/org/apache/jdo/tck/ java/org/apache/jdo/tck/lifecycle/ java/org/apache/jdo/tck/pc/lifecycle/ jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/ jdo/datastoreidentity/org/apache/jdo/tck/...
Date Thu, 23 Mar 2006 07:42:28 GMT
Author: mzaun
Date: Wed Mar 22 23:42:26 2006
New Revision: 388087

URL: http://svn.apache.org/viewcvs?rev=388087&view=rev
Log:
JDO-273, JDO-258 : added tests for detachment and persistent-nontransactional-dirty lifecycle

Modified:
    db/jdo/trunk/tck20/src/conf/lifecycle.conf
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/JDO_Test.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/lifecycle/StateTransitions.java
    db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.java
    db/jdo/trunk/tck20/src/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
    db/jdo/trunk/tck20/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo

Modified: db/jdo/trunk/tck20/src/conf/lifecycle.conf
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/conf/lifecycle.conf?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/conf/lifecycle.conf (original)
+++ db/jdo/trunk/tck20/src/conf/lifecycle.conf Wed Mar 22 23:42:26 2006
@@ -18,5 +18,6 @@
 org.apache.jdo.tck.lifecycle.PMReturnsIdenticalInstancesForEqualObjIds \
 org.apache.jdo.tck.lifecycle.PMsCanSharePCClassesButNotPCInstances \
 org.apache.jdo.tck.lifecycle.StateTransitions \
+org.apache.jdo.tck.lifecycle.StateTransitionsReturnedObjects \
 org.apache.jdo.tck.lifecycle.TransientTransactionalStateCommit \
 org.apache.jdo.tck.lifecycle.TransientTransactionalStateRollback 

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/JDO_Test.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/JDO_Test.java?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/JDO_Test.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/JDO_Test.java Wed Mar 22 23:42:26 2006
@@ -56,20 +56,21 @@
 import org.apache.commons.logging.LogFactory;
 
 public abstract class JDO_Test extends TestCase {
-    public static final int TRANSIENT                   = 0;
-    public static final int PERSISTENT_NEW              = 1;
-    public static final int PERSISTENT_CLEAN            = 2;
-    public static final int PERSISTENT_DIRTY            = 3;
-    public static final int HOLLOW                      = 4;
-    public static final int TRANSIENT_CLEAN             = 5;
-    public static final int TRANSIENT_DIRTY             = 6;
-    public static final int PERSISTENT_NEW_DELETED      = 7;
-    public static final int PERSISTENT_DELETED          = 8;
-    public static final int PERSISTENT_NONTRANSACTIONAL = 9;
-    public static final int PERSISTENT_NONTRANSACTIONAL_DIRTY = 10;
-    public static final int DETACHED = 11;
-    public static final int NUM_STATES = 12;
-    public static final int ILLEGAL_STATE = 12;
+    public static final int TRANSIENT                           = 0;
+    public static final int PERSISTENT_NEW                      = 1;
+    public static final int PERSISTENT_CLEAN                    = 2;
+    public static final int PERSISTENT_DIRTY                    = 3;
+    public static final int HOLLOW                              = 4;
+    public static final int TRANSIENT_CLEAN                     = 5;
+    public static final int TRANSIENT_DIRTY                     = 6;
+    public static final int PERSISTENT_NEW_DELETED              = 7;
+    public static final int PERSISTENT_DELETED                  = 8;
+    public static final int PERSISTENT_NONTRANSACTIONAL         = 9;
+    public static final int PERSISTENT_NONTRANSACTIONAL_DIRTY   = 10;
+    public static final int DETACHED_CLEAN                      = 11;
+    public static final int DETACHED_DIRTY                      = 12;
+    public static final int NUM_STATES = 13;
+    public static final int ILLEGAL_STATE = 13;
 
     public static final String[] states = {
         "transient",
@@ -83,7 +84,8 @@
         "persistent-deleted",
         "persistent-nontransactional",
         "persistent-nontransactional-dirty",
-        "detached",
+        "detached-clean",
+        "detached-dirty",
         "illegal"
     };
     private static final int IS_PERSISTENT       = 0;
@@ -132,10 +134,13 @@
         {   true,           false,              false,      false,      false,        false},
 
         // persistent-nontransactional-dirty
-        {   true,           true,               false,      false,      false,        false},
+        {   true,           false,              true,       false,      false,        false},
+
+        // detached_clean
+        {   false,          false,              false,      false,      false,        true},
 
-        // detached
-        {   false,          false,              false,      false,      false,        true}
+        // detached_dirty
+        {   false,          false,              true,       false,      false,        true}
     };
   
     /** identitytype value for applicationidentity. */
@@ -580,7 +585,7 @@
      */
     public void fail(String assertionFailure, String msg) {
         if (debug) logger.debug(msg);
-        fail(assertionFailure + "\n" + msg);
+        fail(assertionFailure + NL + msg);
     }
 
     // Helper methods to check for supported options
@@ -856,6 +861,18 @@
             return i;
         }
         return NUM_STATES;
+    }
+
+    /**
+     * Tests if a found state matches an expected state.
+     */
+    public static boolean compareStates(int found_state, int expected_state)
+    {
+        // status interrogation gives same values for PERSISTENT_NONTRANSACTIONAL and HOLLOW
+        return (expected_state < 0
+                || found_state == expected_state
+                || (found_state == HOLLOW && expected_state == PERSISTENT_NONTRANSACTIONAL)
+                || (found_state == PERSISTENT_NONTRANSACTIONAL && expected_state
== HOLLOW));
     }
 
     /** This method mangles an object by changing all its non-static, 

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/lifecycle/StateTransitions.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/lifecycle/StateTransitions.java?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/lifecycle/StateTransitions.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/lifecycle/StateTransitions.java Wed Mar
22 23:42:26 2006
@@ -16,9 +16,13 @@
  
 package org.apache.jdo.tck.lifecycle;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
 import java.util.Iterator;
 
 import javax.jdo.Extent;
+import javax.jdo.JDOFatalException;
 import javax.jdo.Transaction;
 
 import org.apache.jdo.tck.JDO_Test;
@@ -57,9 +61,9 @@
     private int                         expected_state;
     private int                         new_state;
 
-/**
- * Operations that cause state changes
- */
+    /**
+     * Operations that cause state changes
+     */
     private static final int MAKEPERSISTENT          = 0;
     private static final int DELETEPERSISTENT        = 1;
     private static final int MAKETRANSACTIONAL       = 2;
@@ -79,7 +83,14 @@
     private static final int WRITEINSIDETX           = 16;
     private static final int RETRIEVEOUTSIDETX       = 17;
     private static final int RETRIEVEINSIDETX        = 18;
-
+    private static final int DETACHALLONCOMMIT       = 19;
+    private static final int DETACHCOPYOUTSIDETX     = 20;
+    private static final int DETACHCOPYINSIDETX      = 21;
+    private static final int SERIALIZEOUTSIDETX      = 22;
+    private static final int SERIALIZEINSIDETX       = 23;
+    
+    private static final int NUM_OPERATIONS          = 24;
+    
     private static final String[] operations = {
         "makePersistent",
         "deletePersistent",
@@ -99,13 +110,13 @@
         "write field outside tx",
         "write field with active tx",
         "retrieve outside tx",
-        "retrieve with active tx"
+        "retrieve with active tx",
+        "commit, detachAllOnCommit=true",
+        "detachCopy outside tx",
+        "detachCopy with active tx",
+        "serialize outside tx",
+        "serialize with active tx"
     };
-    private static final int NUM_OPERATIONS = 19;
-
-    private static final boolean[] closes_transaction =
-    { false, false, false, false, false, true, true, true, true, false,
-      false, false, false, false, false, false, false, false, false };
 
     /**
      * Illegal state transitions
@@ -119,82 +130,197 @@
      * State transitions
      */
     public static final int[][] transitions = { // [operation] [current state] = new state
+        //  TRANSIENT,                      PERSISTENT_NEW,                     PERSISTENT_CLEAN,
+        //  PERSISTENT_DIRTY,               HOLLOW,                             TRANSIENT_CLEAN,
+        //  TRANSIENT_DIRTY,                PERSISTENT_NEW_DELETED,             PERSISTENT_DELETED,

+        //  PERSISTENT_NONTRANSACTIONAL,    PERSISTENT_NONTRANSACTIONAL_DIRTY,  DETACHED_CLEAN,

+        //  DETACHED_DIRTY
+        
         // makePersistent
-        { PERSISTENT_NEW, UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_NEW,
-          PERSISTENT_NEW, UNCHANGED, UNCHANGED, UNCHANGED},
+        {   PERSISTENT_NEW,                 UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          PERSISTENT_NEW,
+            PERSISTENT_NEW,                 UNCHANGED,                          UNCHANGED,

+            UNCHANGED,                      UNCHANGED,                          DETACHED_CLEAN,
    
+            DETACHED_DIRTY},
 
         // deletePersistent
-        { ERROR, PERSISTENT_NEW_DELETED, PERSISTENT_DELETED, PERSISTENT_DELETED,
-          PERSISTENT_DELETED, ERROR, ERROR, UNCHANGED, UNCHANGED, PERSISTENT_DELETED},
+        {   ERROR,                          PERSISTENT_NEW_DELETED,             PERSISTENT_DELETED,

+            PERSISTENT_DELETED,             PERSISTENT_DELETED,                 ERROR,
+            ERROR,                          UNCHANGED,                          UNCHANGED,
+            PERSISTENT_DELETED,             PERSISTENT_DELETED,                 ERROR, 
+            ERROR},
 
         // makeTransactional
-        { TRANSIENT_CLEAN, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN,
-          UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN},
+        {   TRANSIENT_CLEAN,                UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_CLEAN,                   UNCHANGED,

+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            PERSISTENT_CLEAN,               PERSISTENT_DIRTY,                   ERROR,
+            ERROR},
     
         // makeNontransactional
-        { ERROR, ERROR, PERSISTENT_NONTRANSACTIONAL, ERROR, UNCHANGED,
-          TRANSIENT, ERROR, ERROR, ERROR, UNCHANGED},
+        {   ERROR,                          ERROR,                              PERSISTENT_NONTRANSACTIONAL,
+            ERROR,                          UNCHANGED,                          TRANSIENT,
+            ERROR,                          ERROR,                              ERROR,
+            UNCHANGED,                      UNCHANGED,                          ERROR,
+            ERROR},
 
         // makeTransient
-        { UNCHANGED, ERROR, TRANSIENT, ERROR, TRANSIENT,
-          UNCHANGED, UNCHANGED, ERROR, ERROR, TRANSIENT},
+        {   UNCHANGED,                      ERROR,                              TRANSIENT,
+            ERROR,                          TRANSIENT,                          UNCHANGED,
+            UNCHANGED,                      ERROR,                              ERROR,
+            TRANSIENT,                      ERROR,                              ERROR,
+            ERROR},
 
         // commit, retainValues = false
-        { UNCHANGED, HOLLOW, HOLLOW, HOLLOW, UNCHANGED, UNCHANGED,
-          TRANSIENT_CLEAN, TRANSIENT, TRANSIENT, UNCHANGED},
+        {   UNCHANGED,                      HOLLOW,                             HOLLOW,
+            HOLLOW,                         UNCHANGED,                          UNCHANGED,
+            TRANSIENT_CLEAN,                TRANSIENT,                          TRANSIENT,
+            UNCHANGED,                      HOLLOW,                             UNCHANGED,
+            UNCHANGED},
 
         // commit, retainValues = true
-        { UNCHANGED, PERSISTENT_NONTRANSACTIONAL, PERSISTENT_NONTRANSACTIONAL,
-          PERSISTENT_NONTRANSACTIONAL, UNCHANGED, UNCHANGED, TRANSIENT_CLEAN,
-          TRANSIENT, TRANSIENT, UNCHANGED},
-
+        {   UNCHANGED,                      PERSISTENT_NONTRANSACTIONAL,        PERSISTENT_NONTRANSACTIONAL,
+            PERSISTENT_NONTRANSACTIONAL,    UNCHANGED,                          UNCHANGED,
+            TRANSIENT_CLEAN,                TRANSIENT,                          TRANSIENT,
+            UNCHANGED,                      PERSISTENT_NONTRANSACTIONAL,        UNCHANGED,
+            UNCHANGED},
+
+        //  TRANSIENT,                      PERSISTENT_NEW,                     PERSISTENT_CLEAN,
+        //  PERSISTENT_DIRTY,               HOLLOW,                             TRANSIENT_CLEAN,
+        //  TRANSIENT_DIRTY,                PERSISTENT_NEW_DELETED,             PERSISTENT_DELETED,

+        //  PERSISTENT_NONTRANSACTIONAL,    PERSISTENT_NONTRANSACTIONAL_DIRTY,  DETACHED_CLEAN,

+        //  DETACHED_DIRTY
+        
         // rollback, restoreValues = false
-        { UNCHANGED, TRANSIENT, HOLLOW, HOLLOW, UNCHANGED, UNCHANGED,
-          TRANSIENT_CLEAN, TRANSIENT, HOLLOW, UNCHANGED},
+        {   UNCHANGED,                      TRANSIENT,                          HOLLOW,
+            HOLLOW,                         UNCHANGED,                          UNCHANGED,
+            TRANSIENT_CLEAN,                TRANSIENT,                          HOLLOW,
+            UNCHANGED,                      HOLLOW,                             UNCHANGED,
 
+            UNCHANGED},
 
         // rollback, restoreValues = true
-        { UNCHANGED, TRANSIENT, PERSISTENT_NONTRANSACTIONAL, PERSISTENT_NONTRANSACTIONAL,
-          UNCHANGED, UNCHANGED, TRANSIENT_CLEAN, TRANSIENT, PERSISTENT_NONTRANSACTIONAL,
UNCHANGED},
+        {   UNCHANGED,                      TRANSIENT,                          PERSISTENT_NONTRANSACTIONAL,
+            PERSISTENT_NONTRANSACTIONAL,    UNCHANGED,                          UNCHANGED,
+            TRANSIENT_CLEAN,                TRANSIENT,                          PERSISTENT_NONTRANSACTIONAL,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
 
         // refresh with active datastore transaction
-        { UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN, UNCHANGED,
-          UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED},
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            PERSISTENT_CLEAN,               UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_NONTRANSACTIONAL,        UNCHANGED,
+            UNCHANGED},
 
         // refresh with active optimistic transaction
-        { UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_NONTRANSACTIONAL, UNCHANGED,
-          UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED},
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            PERSISTENT_NONTRANSACTIONAL,    UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_NONTRANSACTIONAL,        UNCHANGED,
+            UNCHANGED},
 
         // evict
-        { NOT_APPLICABLE, UNCHANGED, HOLLOW, UNCHANGED, UNCHANGED,
-          UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, HOLLOW},
+        {   NOT_APPLICABLE,                 UNCHANGED,                          HOLLOW,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            HOLLOW,                         HOLLOW,                             UNCHANGED,
+            UNCHANGED},
 
         // read field outside transaction
-        { UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, PERSISTENT_NONTRANSACTIONAL,
-          UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, UNCHANGED},
+        {   UNCHANGED,                      IMPOSSIBLE,                         IMPOSSIBLE,
+            IMPOSSIBLE,                     PERSISTENT_NONTRANSACTIONAL,        IMPOSSIBLE,
+            IMPOSSIBLE,                     IMPOSSIBLE,                         IMPOSSIBLE,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
 
         // read field with active optimistic transaction
-        { UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_NONTRANSACTIONAL,
-          UNCHANGED, UNCHANGED, ERROR, ERROR, UNCHANGED},
-
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_NONTRANSACTIONAL,        UNCHANGED,
+            UNCHANGED,                      ERROR,                              ERROR,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
+
+        //  TRANSIENT,                      PERSISTENT_NEW,                     PERSISTENT_CLEAN,
+        //  PERSISTENT_DIRTY,               HOLLOW,                             TRANSIENT_CLEAN,
+        //  TRANSIENT_DIRTY,                PERSISTENT_NEW_DELETED,             PERSISTENT_DELETED,

+        //  PERSISTENT_NONTRANSACTIONAL,    PERSISTENT_NONTRANSACTIONAL_DIRTY,  DETACHED_CLEAN,

+        //  DETACHED_DIRTY
+        
         // read field with active datastore transaction
-        { UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN,
-          UNCHANGED, UNCHANGED, ERROR, ERROR, PERSISTENT_CLEAN},
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_CLEAN,                   UNCHANGED,
+            UNCHANGED,                      ERROR,                              ERROR,
+            PERSISTENT_CLEAN,               UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
 
         // write field outside transaction
-        { UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, PERSISTENT_NONTRANSACTIONAL,
-          UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, UNCHANGED},
+        {   UNCHANGED,                      IMPOSSIBLE,                         IMPOSSIBLE,
+            IMPOSSIBLE,                     PERSISTENT_NONTRANSACTIONAL,        IMPOSSIBLE,
+            IMPOSSIBLE,                     IMPOSSIBLE,                         IMPOSSIBLE,
+            UNCHANGED,                      UNCHANGED,                          DETACHED_DIRTY,
+            UNCHANGED},
     
         // write field with active transaction
-        { UNCHANGED, UNCHANGED, PERSISTENT_DIRTY, UNCHANGED, PERSISTENT_DIRTY,
-          TRANSIENT_DIRTY, UNCHANGED, ERROR, ERROR, PERSISTENT_DIRTY},
-	  
+        {   UNCHANGED,                      UNCHANGED,                          PERSISTENT_DIRTY,
+            UNCHANGED,                      PERSISTENT_DIRTY,                   TRANSIENT_DIRTY,
+            UNCHANGED,                      ERROR,                              ERROR,
+            PERSISTENT_DIRTY,               UNCHANGED,                          DETACHED_DIRTY,
+            UNCHANGED},
+      
         // retrieve outside transaction
-        { UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, PERSISTENT_NONTRANSACTIONAL,
-          UNCHANGED, IMPOSSIBLE, IMPOSSIBLE, IMPOSSIBLE, UNCHANGED},
-	  
+        {   UNCHANGED,                      IMPOSSIBLE,                         IMPOSSIBLE,
+            IMPOSSIBLE,                     PERSISTENT_NONTRANSACTIONAL,        IMPOSSIBLE,
+            IMPOSSIBLE,                     IMPOSSIBLE,                         IMPOSSIBLE,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
+      
         // retrieve with active transaction
-        { UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN,
-          UNCHANGED, UNCHANGED, UNCHANGED, UNCHANGED, PERSISTENT_CLEAN}
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_CLEAN,                   UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            PERSISTENT_CLEAN,               UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
+
+        // commit, detachAllOnCommit = true
+        {   UNCHANGED,                      DETACHED_CLEAN,                     DETACHED_CLEAN,
+            DETACHED_CLEAN,                 DETACHED_CLEAN,                     UNCHANGED,
+            TRANSIENT_CLEAN,                TRANSIENT,                          TRANSIENT,
+            DETACHED_CLEAN,                 DETACHED_CLEAN,                     UNCHANGED,
+            UNCHANGED},
+
+        //  TRANSIENT,                      PERSISTENT_NEW,                     PERSISTENT_CLEAN,
+        //  PERSISTENT_DIRTY,               HOLLOW,                             TRANSIENT_CLEAN,
+        //  TRANSIENT_DIRTY,                PERSISTENT_NEW_DELETED,             PERSISTENT_DELETED,

+        //  PERSISTENT_NONTRANSACTIONAL,    PERSISTENT_NONTRANSACTIONAL_DIRTY,  DETACHED_CLEAN,

+        //  DETACHED_DIRTY
+        
+        // detachCopy outside tx
+        {   ERROR,                          IMPOSSIBLE,                         IMPOSSIBLE,
+            IMPOSSIBLE,                     UNCHANGED,                          IMPOSSIBLE,
+            IMPOSSIBLE,                     IMPOSSIBLE,                         IMPOSSIBLE,
+            UNCHANGED,                      ERROR,                              UNCHANGED,
+            UNCHANGED},
+
+        // detachCopy with active tx
+        {   PERSISTENT_NEW,                 UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          PERSISTENT_NEW,
+            PERSISTENT_NEW,                 ERROR,                              ERROR,
+            UNCHANGED,                      ERROR,                              UNCHANGED,
+            UNCHANGED},
+
+        // serialize outside tx
+        {   UNCHANGED,                      IMPOSSIBLE,                         IMPOSSIBLE,
+            IMPOSSIBLE,                     UNCHANGED,                          IMPOSSIBLE,
+            IMPOSSIBLE,                     IMPOSSIBLE,                         IMPOSSIBLE,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
+
+        // serialize with active tx
+        {   UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            UNCHANGED,                      PERSISTENT_CLEAN,                   UNCHANGED,
+            UNCHANGED,                      UNCHANGED,                          UNCHANGED,
+            PERSISTENT_CLEAN,               UNCHANGED,                          UNCHANGED,
+            UNCHANGED},
     };
 
     private static final int DATASTORE_TX = 0;
@@ -225,7 +351,12 @@
         {   false,         false,       true  },  // write field or makeDirty outside of
a transaction
         {   true,          true,        false },  // write field or makeDirty with active
transaction
         {   false,         true,        true  },  // retrieve outside of a transaction or
with active optimistic transaction
-        {   true,          false,       false }   // retrieve with active datastore transaction
+        {   true,          false,       false },  // retrieve with active datastore transaction
+        {   true,          true,        false },  // commit, DetachAllOnCommit = true
+        {   false,         false,       true },   // detachCopy outside tx
+        {   true,          true,        false },  // detachCopy with active tx
+        {   false,         false,       true },   // serialize outside tx
+        {   true,          true,        false }   // serialize with active tx
     };
 
     /**
@@ -248,6 +379,7 @@
 
         scenario = NO_TX;
         checkTransitions();
+        failOnError();
     }
 
     /** */
@@ -282,12 +414,54 @@
     }
 
     /** */
+    public void prepareTransactionAndJDOSettings(Transaction transaction) {
+        if( scenario != NO_TX ) {
+            transaction.setNontransactionalRead(false);
+            transaction.setNontransactionalWrite(false);
+            
+            if( operation == COMMITNORETAINVALUES )
+                transaction.setRetainValues(false);
+            if( operation == COMMITRETAINVALUES )
+                transaction.setRetainValues(true);
+            if( operation == ROLLBACKNORESTOREVALUES )
+                transaction.setRestoreValues(false);
+            if( operation == ROLLBACKRESTOREVALUES )
+                transaction.setRestoreValues(true);
+            if( operation == DETACHALLONCOMMIT )
+                pm.setDetachAllOnCommit(true);
+            else
+                pm.setDetachAllOnCommit(false);
+
+            transaction.setOptimistic(scenario == OPTIMISTIC_TX);
+            transaction.begin();
+            if( !transaction.isActive() )
+                if (debug)
+                    logger.debug("StateTransitions: Transaction should be active, but it
is not");
+        } else {
+            if( operation == READOUTSIDETX ||
+                operation == RETRIEVEOUTSIDETX ||
+                operation == DETACHCOPYOUTSIDETX ||
+                operation == SERIALIZEOUTSIDETX ) {
+                transaction.setNontransactionalRead(true);
+            }
+            if( operation == WRITEOUTSIDETX ||
+                current_state == PERSISTENT_NONTRANSACTIONAL_DIRTY) {
+                transaction.setNontransactionalWrite(true);
+            }
+        }
+    }
+    
+    /** */
     void checkTransitions()
     {
         for( operation = 0; operation < NUM_OPERATIONS; ++operation ){
             // rule out situations that do not apply
-            if( ! applies_to_scenario[operation][scenario] ) continue;
-            if( operation == READOUTSIDETX && !isNontransactionalReadSupported()
) continue;
+            if( !applies_to_scenario[operation][scenario] ) continue;
+            if( (operation == READOUTSIDETX ||
+                 operation == RETRIEVEOUTSIDETX ||
+                 operation == DETACHCOPYOUTSIDETX ||
+                 operation == SERIALIZEOUTSIDETX) && 
+                 !isNontransactionalReadSupported() ) continue;
             if( operation == WRITEOUTSIDETX && !isNontransactionalWriteSupported()
) continue;
             if( operation == COMMITRETAINVALUES && !isRetainValuesSupported() ) continue;
             if( operation == MAKENONTRANSACTIONAL &&
@@ -302,6 +476,9 @@
                 if( current_state == PERSISTENT_NONTRANSACTIONAL &&
                     !(isNontransactionalReadSupported() || isNontransactionalWriteSupported())
)
                     continue;   // this state is not supported by implementation
+                if( current_state == PERSISTENT_NONTRANSACTIONAL_DIRTY &&
+                        !isNontransactionalWriteSupported() )
+                    continue;
 
                 expected_state = transitions[operation][current_state];
                 if( expected_state == IMPOSSIBLE ) continue;
@@ -315,23 +492,10 @@
                         transaction.rollback();
                     }
 
-                    if( scenario != NO_TX ){
-                        if( operation == COMMITNORETAINVALUES )
-                            transaction.setRetainValues(false);
-                        if( operation == COMMITRETAINVALUES )
-                            transaction.setRetainValues(true);
-                        if( operation == ROLLBACKNORESTOREVALUES )
-                            transaction.setRestoreValues(false);
-                        if( operation == ROLLBACKRESTOREVALUES )
-                            transaction.setRestoreValues(true);
-
-                        transaction.setOptimistic(scenario == OPTIMISTIC_TX);
-                        transaction.begin();
-                        if( !transaction.isActive() )
-                            if (debug)
-                                logger.debug("StateTransitions: Transaction should be active,
but it is not");
-                    }
+                    prepareTransactionAndJDOSettings(transaction);
 
+                    printSituation();
+                    
                     StateTransitionObj obj = getInstanceInState(current_state);
                     if( obj == null ){  // could not get object in state
                         if( transaction.isActive() ) transaction.rollback();
@@ -346,9 +510,12 @@
                         if( excep instanceof javax.jdo.JDOUserException ){
                             e = excep;
                         } else {
-                            printSituation();
-                            fail(ASSERTION_FAILED,
-                                 "StateTransitions: Unexpected exception:" + excep);
+                            appendMessage(ASSERTION_FAILED + NL +
+                                          "StateTransitions: " +
+                                          scenario_string[scenario] +
+                                          "; current state " + states[current_state] + NL
+
+                                          operations[operation] +
+                                          "; unexpected exception:" + excep);
                             continue;
                         }
                     }
@@ -357,37 +524,44 @@
                     new_state = currentState(obj);
                     if( expected_state == ERROR ){
                         if( e == null ){
-                            printSituation();
-                            fail(ASSERTION_FAILED,
-                                 "StateTransitions: JDOUserException should have been thrown");
+                            appendMessage(ASSERTION_FAILED + NL +
+                                          "StateTransitions: " +
+                                          scenario_string[scenario] +
+                                          "; current state " + states[current_state] + NL
+
+                                          operations[operation] +
+                                          "; JDOUserException should have been thrown");
                         } else {
                             if( new_state != current_state ){
-                                printSituation();
-                                fail(ASSERTION_FAILED,
-                                     "StateTransitions: " + 
-                                     " JDOUserException properly thrown, but instance should
remain in current state," +
-                                     "instance changed state to " + states[new_state]);
+                                appendMessage(ASSERTION_FAILED + NL +
+                                              "StateTransitions: " +
+                                              scenario_string[scenario] +
+                                              "; current state " + states[current_state]
+ NL +
+                                              operations[operation] +
+                                              "; JDOUserException properly thrown, but instance
should remain in current state," +
+                                              "instance changed state to " + states[new_state]);
                             }
                         }
                     }
-                    if( expected_state >= 0 && new_state != expected_state &&

-                        !((new_state == HOLLOW && expected_state == PERSISTENT_NONTRANSACTIONAL)
||
-                          (new_state == PERSISTENT_NONTRANSACTIONAL && expected_state
== HOLLOW)) ) { 
-                        // status interrogation gives same values for PERSISTENT_NONTRANSACTIONAL
and HOLLOW
-                        printSituation();
-                        fail(ASSERTION_FAILED,
-                             "StateTransitions: Invalid state transition to " +
-                             states[new_state] + ", new state should be " +
-                             states[expected_state]);
+                    if( !compareStates(new_state, expected_state) ) { 
+                        appendMessage(ASSERTION_FAILED + NL +
+                                      "StateTransitions: " +
+                                      scenario_string[scenario] +
+                                      "; current state " + states[current_state] + NL +
+                                      operations[operation] +
+                                      " transitioned instance to invalid state " + states[new_state]
+ 
+                                      "; expected state " + states[expected_state]);
                     }
                     if( transaction.isActive() ) transaction.rollback();
                 } 
                 catch(Exception unexpected_exception) {
-                    printSituation();
                     if (transaction.isActive()) 
                         transaction.rollback();
-                    fail(ASSERTION_FAILED,
-                         "Unexpected exception caught in StateTransitions " + unexpected_exception);
+                    appendMessage(ASSERTION_FAILED + NL +
+                                  "StateTransitions: " +
+                                  scenario_string[scenario] +
+                                  "; current state " + states[current_state] + NL +
+                                  operations[operation] +
+                                  "; unexpected exception caught: " + unexpected_exception);
                 }
             }
         }
@@ -470,17 +644,17 @@
         }
         case READOUTSIDETX:
         {
-            int val = obj.readField();
+            obj.readField();
             break;
         }
         case READOPTIMISTIC:
         {
-            int val = obj.readField();
+            obj.readField();
             break;
         }
         case READDATASTORE:
         {
-            int val = obj.readField();
+            obj.readField();
             break;
         }
         case WRITEOUTSIDETX:
@@ -501,12 +675,67 @@
         case RETRIEVEINSIDETX:
         {
             pm.retrieve(obj);
-            break;		
+            break;      
+        }
+        case DETACHALLONCOMMIT:
+        {
+            pm.currentTransaction().commit();
+            break;      
+        }
+        case DETACHCOPYOUTSIDETX:
+        {
+            pm.detachCopy(obj);
+            break;      
+        }
+        case DETACHCOPYINSIDETX:
+        {
+            pm.detachCopy(obj);
+            break;      
+        }
+        case SERIALIZEOUTSIDETX:
+        {
+            ObjectOutputStream oos = null;
+            try {
+                oos = new ObjectOutputStream(new ByteArrayOutputStream());
+                oos.writeObject(obj);
+            } catch (IOException e) {
+                throw new JDOFatalException(e.getMessage(), e);
+            } finally {
+                if (oos != null) {
+                    try {
+                        oos.close();
+                    } catch (IOException e) {
+                        throw new JDOFatalException(e.getMessage(), e);
+                    }
+                }
+            }
+            break;      
+        }
+        case SERIALIZEINSIDETX:
+        {
+            ObjectOutputStream oos = null;
+            try {
+                oos = new ObjectOutputStream(new ByteArrayOutputStream());
+                oos.writeObject(obj);
+            } catch (IOException e) {
+                throw new JDOFatalException(e.getMessage(), e);
+            } finally {
+                if (oos != null) {
+                    try {
+                        oos.close();
+                    } catch (IOException e) {
+                        throw new JDOFatalException(e.getMessage(), e);
+                    }
+                }
+            }
+            break;      
         }
         default:
         {
-            fail(ASSERTION_FAILED,
-                 "StateTransitions internal error, illegal operation " + operation);
+            appendMessage(ASSERTION_FAILED + NL +
+                          "StateTransitions: " +
+                          scenario_string[scenario] +
+                          "; internal error, illegal operation: " + operation);
         }
         }
     }
@@ -514,7 +743,7 @@
     /**
      * Get an instance in the specified state.
      */
-    private StateTransitionObj getInstanceInState(int state)
+    public StateTransitionObj getInstanceInState(int state)
     {
         switch(state) {
         case TRANSIENT:
@@ -537,15 +766,19 @@
             return getPersistentDeletedInstance();
         case PERSISTENT_NONTRANSACTIONAL:
             return getPersistentNontransactionalInstance();
+        case PERSISTENT_NONTRANSACTIONAL_DIRTY:
+            return getPersistentNontransactionalDirtyInstance();
+        case DETACHED_CLEAN:
+            return getDetachedCleanInstance();
+        case DETACHED_DIRTY:
+            return getDetachedDirtyInstance();
         default:
-        {
             return null;
         }
-        }
     }
 
     /** */
-    private StateTransitionObj getTransientInstance()
+    public StateTransitionObj getTransientInstance()
     {
         StateTransitionObj obj = new StateTransitionObj(23);
         int curr = currentState(obj);
@@ -554,14 +787,13 @@
                 logger.debug("StateTransitions: Unable to create transient instance, state
is " + 
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
     }
 
     /** */
-    private StateTransitionObj getPersistentNewInstance()
+    public StateTransitionObj getPersistentNewInstance()
     {
         StateTransitionObj obj = getTransientInstance();
         if( obj == null ) return null;
@@ -573,7 +805,6 @@
                              " from transient instance via makePersistent(), state is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -585,7 +816,7 @@
         StateTransitionObj obj = getHollowInstance();
         if( obj == null ) return null;
         StateTransitionObj sto = (StateTransitionObj) obj;
-        int val = sto.readField();
+        sto.readField();
         int curr = currentState(sto);
         if( curr != PERSISTENT_CLEAN ) {
             if (debug) {
@@ -593,7 +824,6 @@
                              " from a hollow instance by reading a field, state is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -613,7 +843,6 @@
                              " from a hollow instance by writing a field, state is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -637,25 +866,10 @@
         if( !transaction.isActive() )
             if (debug)
                 logger.debug("getHollowInstance: Transaction should be active, but it is
not");
-		
+        
         transaction.commit(); // This should put the instance in the HOLLOW state
 
-        if( scenario != NO_TX ){
-            if( operation == COMMITNORETAINVALUES )
-                transaction.setRetainValues(false);
-            if( operation == COMMITRETAINVALUES )
-                transaction.setRetainValues(true);
-            if( operation == ROLLBACKNORESTOREVALUES )
-                transaction.setRestoreValues(false);
-            if( operation == ROLLBACKRESTOREVALUES )
-                transaction.setRestoreValues(true);
-
-            transaction.setOptimistic(scenario == OPTIMISTIC_TX);
-            transaction.begin();
-            if( !transaction.isActive() )
-                if (debug)
-                    logger.debug("getHollowInstance: Transaction should be active, but it
is not");
-        }
+        prepareTransactionAndJDOSettings(transaction);
 
         int curr = currentState(obj);
         if( curr != HOLLOW && curr != PERSISTENT_NONTRANSACTIONAL ){
@@ -663,7 +877,6 @@
                 logger.debug("StateTransition: Attempt to get hollow instance via accessing
extent failed, state is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -682,7 +895,6 @@
                              " from a transient instance via makeTransactional(), state is
" +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -702,7 +914,6 @@
                              " from a transient-clean instance via modifying a field, state
is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -721,7 +932,6 @@
                              " from a persistent-new instance via deletePersistent, state
is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -740,7 +950,6 @@
                              " from a persistent instance via deletePersistent(), state is
" +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
         return obj;
@@ -759,10 +968,63 @@
                              " from a persistent-clean instance via makeNontransactional(),
state is " +
                              states[curr]);
             }
-            printSituation();
             return null;
         }
-        return null;
+        return obj;
     }
 
+    /** */
+    public StateTransitionObj getPersistentNontransactionalDirtyInstance()
+    {
+        StateTransitionObj obj = getPersistentNontransactionalInstance();
+        if( obj == null ) return null;
+        obj.writeField(10000);
+        int curr = currentState(obj);
+        if( curr != PERSISTENT_NONTRANSACTIONAL_DIRTY ) { 
+            if (debug) {
+                logger.debug("StateTransition: Unable to create persistent-nontransactional-dirty
instance" +
+                             " from a persistent-clean instance via makeNontransactional()/JDOHelper.makeDirty,"
+
+                             " state is " + states[curr]);
+            }
+            return null;
+        }
+        return obj;
+    }
+
+    /** */
+    public StateTransitionObj getDetachedCleanInstance()
+    {
+        StateTransitionObj obj = getHollowInstance();
+        if( obj == null ) return null;
+        obj = (StateTransitionObj) pm.detachCopy(obj);
+        int curr = currentState(obj);
+        if( curr != DETACHED_CLEAN ) { 
+            if (debug) {
+                logger.debug("StateTransition: Unable to create detached-clean instance"
+
+                             " from a persistent-clean instance via detachCopy," +
+                             " state is " + states[curr]);
+            }
+            return null;
+        }
+        return obj;
+    }
+
+    /** */
+    public StateTransitionObj getDetachedDirtyInstance()
+    {
+        StateTransitionObj obj = getHollowInstance();
+        if( obj == null ) return null;
+        obj = (StateTransitionObj) pm.detachCopy(obj);
+        obj.writeField(1000);
+        int curr = currentState(obj);
+        if( curr != DETACHED_DIRTY ) { 
+            if (debug) {
+                logger.debug("StateTransition: Unable to create detached-dirty instance"
+
+                             " from a persistent-clean instance via detachCopy/persistent
field modification," +
+                             " state is " + states[curr]);
+            }
+            return null;
+        }
+        return obj;
+    }
 }

Modified: db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.java
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.java?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.java (original)
+++ db/jdo/trunk/tck20/src/java/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.java Wed
Mar 22 23:42:26 2006
@@ -19,7 +19,7 @@
 
 import java.io.Serializable;
 
-public class StateTransitionObj {
+public class StateTransitionObj implements Serializable {
     private static int counter = 0;
     
     private int      id;

Modified: db/jdo/trunk/tck20/src/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
(original)
+++ db/jdo/trunk/tck20/src/jdo/applicationidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
Wed Mar 22 23:42:26 2006
@@ -7,7 +7,8 @@
 
     <class name="StateTransitionObj" 
            identity-type="application"
-           objectid-class="org.apache.jdo.tck.pc.lifecycle.StateTransitionObj$Oid">
+           objectid-class="org.apache.jdo.tck.pc.lifecycle.StateTransitionObj$Oid"
+           detachable="true">
         <field name="id" primary-key="true"/>
     </class>
   </package>

Modified: db/jdo/trunk/tck20/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
URL: http://svn.apache.org/viewcvs/db/jdo/trunk/tck20/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo?rev=388087&r1=388086&r2=388087&view=diff
==============================================================================
--- db/jdo/trunk/tck20/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
(original)
+++ db/jdo/trunk/tck20/src/jdo/datastoreidentity/org/apache/jdo/tck/pc/lifecycle/StateTransitionObj.jdo
Wed Mar 22 23:42:26 2006
@@ -4,6 +4,6 @@
      xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdo 
 	http://java.sun.com/xml/ns/jdo/jdo_2_0.xsd">
   <package name="org.apache.jdo.tck.pc.lifecycle">
-    <class name="StateTransitionObj" identity-type="datastore" />
+    <class name="StateTransitionObj" identity-type="datastore" detachable="true"/>
   </package>
 </jdo>



Mime
View raw message