openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [31/39] - in /openjpa/trunk: openjpa-lib/src/test/java/org/apache/openjpa/lib/test/ openjpa-persistence-jdbc/ openjpa-persistence-jdbc/src/test/java/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/ openjpa-per...
Date Fri, 15 Feb 2008 09:20:40 GMT
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSerialize.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSerialize.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSerialize.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSerialize.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,93 @@
+/*
+ * TestSerialize.java
+ *
+ * Created on October 13, 2006, 5:13 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.openjpa.persistence.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestSerialize extends BaseKernelTest {
+
+    private int _oid = 0;
+    private Object _oid2 = null;
+
+    /**
+     * Creates a new instance of TestSerialize
+     */
+    public TestSerialize() {
+    }
+
+    public TestSerialize(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        RuntimeTest1 a = new RuntimeTest1("1NAME", 1);
+        a.setSelfOneOne(new RuntimeTest1("2NAME", 2));
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(a);
+        _oid = a.getIntField();
+
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testConfigurationSerializable()
+        throws Exception {
+        // validate that the hashCode() and equals() method hold true
+        // for the round-trip.
+        roundtrip(getConfiguration(), true);
+    }
+
+    public void testSerialize()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM();
+        //FIXME jthomas
+        /*pm.getFetchPlan().setDetachmentOptions
+                (FetchPlan.DETACH_ALL_FIELDS);
+         */
+        RuntimeTest1 a = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
+
+        assertEquals("1NAME", a.getStringField());
+        assertEquals(1, a.getIntField());
+        assertNotNull(a.getSelfOneOne());
+        assertEquals("2NAME", a.getSelfOneOne().getStringField());
+        assertEquals(2, a.getSelfOneOne().getIntField());
+
+        a = (RuntimeTest1) roundtrip(a, false);
+
+        assertEquals("1NAME", a.getStringField());
+        assertEquals(1, a.getIntField());
+        assertNotNull(a.getSelfOneOne());
+        assertEquals("2NAME", a.getSelfOneOne().getStringField());
+        assertEquals(2, a.getSelfOneOne().getIntField());
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSimple.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSimple.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSimple.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSimple.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,136 @@
+/*
+ * TestSimple.java
+ *
+ * Created on October 13, 2006, 5:03 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.openjpa.persistence.kernel;
+
+import java.util.List;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestSimple extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestSimple
+     */
+    public TestSimple(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+    }
+
+    public void testSimple() {
+        // test create
+        {
+            OpenJPAEntityManager pm = getPM();
+            startTx(pm);
+            pm.persist(new RuntimeTest1("testSimple", 12));
+            endTx(pm);
+            endEm(pm);
+        }
+
+        // test Query
+        {
+            OpenJPAEntityManager pm = getPM();
+            startTx(pm);
+            String theQuery =
+                "SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
+            OpenJPAQuery query = pm.createQuery(theQuery);
+            List list = query.getResultList();
+            assertSize(1, list);
+            endTx(pm);
+            endEm(pm);
+        }
+
+        // test Update
+        {
+            OpenJPAEntityManager pm = getPM();
+            startTx(pm);
+            String theQuery =
+                "SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
+            OpenJPAQuery query = pm.createQuery(theQuery);
+            RuntimeTest1 toUpdate = (RuntimeTest1) query.getSingleResult();
+            toUpdate.setStringField("testSimple2");
+            endTx(pm);
+            endEm(pm);
+
+            pm = getPM();
+            startTx(pm);
+            String query1 =
+                "SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple\'";
+            String query2 =
+                "SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
+            OpenJPAQuery q1 = pm.createQuery(query1);
+            OpenJPAQuery q2 = pm.createQuery(query2);
+            assertSize(0, q1.getResultList());
+            assertSize(1, q2.getResultList());
+            endTx(pm);
+            endEm(pm);
+        }
+
+        // test Extent
+        {
+            OpenJPAEntityManager pm = getPM();
+            startTx(pm);
+            Extent e = pm.createExtent(RuntimeTest1.class, true);
+            assertTrue(e.iterator().hasNext());
+            assertEquals("testSimple2", ((RuntimeTest1) e.iterator().next()).
+                getStringField());
+            endTx(pm);
+            endEm(pm);
+        }
+
+        // test delete
+        {
+            OpenJPAEntityManager pm = getPM();
+            startTx(pm);
+            String delete =
+                "DELETE FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
+            OpenJPAQuery deleteQuery = pm.createQuery(delete);
+            int deleted = deleteQuery.executeUpdate();
+            endTx(pm);
+            endEm(pm);
+
+            pm = getPM();
+            startTx(pm);
+            String select =
+                "SELECT r FROM RuntimeTest1 r WHERE r.stringField = \'testSimple2\'";
+            OpenJPAQuery selectQuery = pm.createQuery(select);
+
+            assertSize(0, selectQuery.getResultList());
+
+            endTx(pm);
+            endEm(pm);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,315 @@
+/*
+ * TestSpecialNumbers.java
+ *
+ * Created on October 13, 2006, 4:56 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.openjpa.persistence.kernel;
+
+import java.math.BigInteger;
+import java.util.Collection;
+import java.util.EnumSet;
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestSpecialNumbers extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestSpecialNumbers
+     */
+    public TestSpecialNumbers() {
+    }
+
+    public TestSpecialNumbers(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        try {
+            deleteAll(AllFieldTypesTest.class);
+        } catch (Exception e) {
+            // catch errors when deleting ... PostgreSQL has
+            // a couple problems with some of the values that
+            // try to get inserted.
+        }
+    }
+
+    public void testShortMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestshort(Short.MAX_VALUE);
+        saveAndQuery(aftt, "testshort == param", new Short(Short.MAX_VALUE));
+    }
+
+    public void testShortMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestshort(Short.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testshort == param",
+                new Short(Short.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.EMPRESS, 889, t,
+                "Empress cannot store min values");
+        }
+    }
+
+    public void testLongMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestlong(Long.MAX_VALUE);
+        saveAndQuery(aftt, "testlong == param", new Long(Long.MAX_VALUE));
+    }
+
+    public void testLongMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestlong(Long.MIN_VALUE);
+            saveAndQuery(aftt, "testlong == param", new Long(Long.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.HYPERSONIC, 474, t,
+                "Some databases cannot store Long.MIN_VALUE");
+        }
+    }
+
+    public void testIntegerMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestint(Integer.MAX_VALUE);
+        saveAndQuery(aftt, "testint == param",
+            new Integer(Integer.MAX_VALUE));
+    }
+
+    public void testIntegerMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestint(Integer.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testint == param",
+                new Integer(Integer.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.EMPRESS, 889, t,
+                "Empress cannot store min values");
+        }
+    }
+
+    public void testFloatMax() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.MAX_VALUE);
+            saveAndQuery(aftt, "testfloat == param",
+                new Float(Float.MAX_VALUE));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.MYSQL,
+                AbstractTestCase.Platform.DERBY), 494, e,
+                "Some datastores cannot store Float.MAX_VALUE");
+        }
+    }
+
+    public void testFloatMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.MIN_VALUE);
+            saveAndQuery(aftt, "testfloat == param",
+                new Float(Float.MIN_VALUE));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.SQLSERVER,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY), 494, e,
+                "Some databases cannot store Float.MIN_VALUE");
+        } catch (AssertionFailedError e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.MYSQL,
+                AbstractTestCase.Platform.SQLSERVER), 494, e,
+                "Some databases cannot store Float.MIN_VALUE");
+        }
+    }
+
+    public void testFloatNaN() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.NaN);
+            saveAndQuery(aftt, "testfloat == param", new Float(Float.NaN));
+        } catch (Throwable t) {
+            bug(461, t, "NaN problems");
+        }
+    }
+
+    public void testFloatNegativeInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.NEGATIVE_INFINITY);
+            saveAndQuery(aftt, "testfloat == param",
+                new Float(Float.NEGATIVE_INFINITY));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.MYSQL,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.ORACLE,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY,
+                AbstractTestCase.Platform.SQLSERVER), 494, e,
+                "Some databases cannot store Float.NEGATIVE_INFINITY");
+        }
+    }
+
+    public void testFloatPostivieInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.POSITIVE_INFINITY);
+            saveAndQuery(aftt, "testfloat == param",
+                new Float(Float.POSITIVE_INFINITY));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.MYSQL,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.ORACLE,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY,
+                AbstractTestCase.Platform.SQLSERVER), 494, e,
+                "Some databases cannot store Float.POSITIVE_INFINITY");
+        }
+    }
+
+    public void testDoubleMax() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.MAX_VALUE);
+            saveAndQuery(aftt, "testdouble == param",
+                new Double(Double.MAX_VALUE));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
+                AbstractTestCase.Platform.MYSQL,
+                AbstractTestCase.Platform.ORACLE,
+                AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.EMPRESS,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY), 494, e,
+                "Some databases cannot store Double.MAX_VALUE");
+        }
+    }
+
+    public void testDoubleMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.MIN_VALUE);
+            saveAndQuery(aftt, "testdouble == param",
+                new Double(Double.MIN_VALUE));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.SQLSERVER,
+                AbstractTestCase.Platform.ORACLE,
+                AbstractTestCase.Platform.EMPRESS,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY), 494, e,
+                "Some databases cannot store Double.MIN_VALUE");
+        } catch (AssertionFailedError e) {
+            bug(AbstractTestCase.Platform.MYSQL, 494, e,
+                "Some databases cannot store Double.MIN_VALUE");
+        }
+    }
+
+    public void testDoubleNaN() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.NaN);
+            saveAndQuery(aftt, "testdouble == param", new Double(Double.NaN));
+        } catch (Throwable t) {
+            bug(461, t, "NaN problems");
+        }
+    }
+
+    public void testDoubleNegativeInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.NEGATIVE_INFINITY);
+            saveAndQuery(aftt, "testdouble == param",
+                new Double(Double.NEGATIVE_INFINITY));
+        } catch (Throwable t) {
+            bug(461, t, "infinity problems");
+        }
+    }
+
+    public void testDoublePostivieInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.POSITIVE_INFINITY);
+            saveAndQuery(aftt, "testdouble == param",
+                new Double(Double.POSITIVE_INFINITY));
+        } catch (Throwable t) {
+            bug(461, t, "infinity problems");
+        }
+    }
+
+    public void testByteMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestbyte(Byte.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testbyte == param", new Byte(Byte.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.EMPRESS, 889, t,
+                "Empress cannot store min values");
+        }
+    }
+
+    public void testByteMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestbyte(Byte.MAX_VALUE);
+        saveAndQuery(aftt, "testbyte == param", new Byte(Byte.MAX_VALUE));
+    }
+
+    public void testZeroBigInteger() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestBigInteger(BigInteger.ZERO);
+        saveAndQuery(aftt, "testBigInteger == param", BigInteger.ZERO);
+    }
+
+    public void testOneBigInteger() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestBigInteger(BigInteger.ONE);
+        saveAndQuery(aftt, "testBigInteger == param", BigInteger.ONE);
+    }
+
+    private void saveAndQuery(Object obj, String query, Object param) {
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(obj);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        OpenJPAQuery q = pm.createNativeQuery(query, obj.getClass());
+        //FIXME jthomas
+        //q.declareParameters("Object param");
+        Collection c = (Collection) q.getResultList();
+        assertSize(1, c);
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSpecialNumbers2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,285 @@
+/*
+ * 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.openjpa.persistence.kernel;
+
+import java.util.Collection;
+import java.util.EnumSet;
+import java.math.BigInteger;
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldTypesTest;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+/**
+ * Test various special numbers, such as Double.NaN.
+ *
+ * @author <a href="mailto:marc@solarmetric.com">Marc Prud'hommeaux</a>
+ */
+public class TestSpecialNumbers2 extends BaseKernelTest {
+
+    public TestSpecialNumbers2(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        try {
+            deleteAll(AllFieldTypesTest.class);
+        }
+        catch (Exception e) {
+            // catch errors when deleting ... PostgreSQL has
+            // a couple problems with some of the values that
+            // try to get inserted.
+        }
+    }
+
+    public void testShortMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestshort(Short.MAX_VALUE);
+        saveAndQuery(aftt, "testshort =", new Short(Short.MAX_VALUE));
+    }
+    
+    public void testShortMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestshort(Short.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testshort =",
+                    new Short(Short.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.EMPRESS, 889, t,
+                    "Empress cannot store min values");
+        }
+    }
+    
+    public void testLongMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestlong(Long.MAX_VALUE);
+        saveAndQuery(aftt, "testlong =", new Long(Long.MAX_VALUE));
+    }
+    
+    public void testLongMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestlong(Long.MIN_VALUE);
+            saveAndQuery(aftt, "testlong =", new Long(Long.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.HYPERSONIC, 474, t,
+                    "Some databases cannot store Long.MIN_VALUE");
+        }
+    }
+    
+    public void testIntegerMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestint(Integer.MAX_VALUE);
+        saveAndQuery(aftt, "testint =",
+                new Integer(Integer.MAX_VALUE));
+    }
+    
+    public void testIntegerMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestint(Integer.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testint =",
+                    new Integer(Integer.MIN_VALUE));
+        } catch (Throwable t) {
+            bug(AbstractTestCase.Platform.EMPRESS, 889, t,
+                    "Empress cannot store min values");
+        }
+    }
+    
+    public void testFloatMax() {
+        try {
+        	AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.MAX_VALUE);
+            saveAndQuery(aftt, "testfloat =",
+                    new Float(Float.MAX_VALUE));
+        } catch (Exception e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some datastores cannot store Float.MAX_VALUE");
+        }
+    }
+    
+    public void testFloatMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.MIN_VALUE);
+            saveAndQuery(aftt, "testfloat =",
+                    new Float(Float.MIN_VALUE));
+        } catch (Exception e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some databases cannot store Float.MIN_VALUE");
+        } catch (AssertionFailedError e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some databases cannot store Float.MIN_VALUE");
+        }
+    }
+    
+    public void testFloatNaN() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.NaN);
+            saveAndQuery(aftt, "testfloat =", new Float(Float.NaN));
+        } catch (Throwable t) {
+            bug(461, t, "NaN problems");
+        }
+    }
+    
+    public void testFloatNegativeInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.NEGATIVE_INFINITY);
+            saveAndQuery(aftt, "testfloat =",
+                    new Float(Float.NEGATIVE_INFINITY));
+        } catch (Exception e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some databases cannot store Float.NEGATIVE_INFINITY");
+        }
+    }
+    
+    public void testFloatPostivieInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestfloat(Float.POSITIVE_INFINITY);
+            saveAndQuery(aftt, "testfloat =",
+                    new Float(Float.POSITIVE_INFINITY));
+        } catch (Exception e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some databases cannot store Float.POSITIVE_INFINITY");
+        }
+    }
+    
+    public void testDoubleMax() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.MAX_VALUE);
+            saveAndQuery(aftt, "testdouble =",
+                    new Double(Double.MAX_VALUE));
+        } catch (Exception e) {
+            bug(getCurrentPlatform(), 494, e,
+                    "Some databases cannot store Double.MAX_VALUE");
+        }
+    }
+    
+    public void testDoubleMin() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.MIN_VALUE);
+            saveAndQuery(aftt, "testdouble =",
+                    new Double(Double.MIN_VALUE));
+        } catch (Exception e) {
+            bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
+                AbstractTestCase.Platform.SQLSERVER,
+                AbstractTestCase.Platform.ORACLE,
+                AbstractTestCase.Platform.EMPRESS,
+                AbstractTestCase.Platform.DB2,
+                AbstractTestCase.Platform.INFORMIX,
+                AbstractTestCase.Platform.DERBY), 494, e,
+                "Some databases cannot store Double.MIN_VALUE");
+        } catch (AssertionFailedError e) {
+            bug(AbstractTestCase.Platform.MYSQL, 494, e,
+                    "Some databases cannot store Double.MIN_VALUE");
+        }
+    }
+    
+    public void testDoubleNaN() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.NaN);
+            saveAndQuery(aftt, "testdouble =", new Double(Double.NaN));
+        } catch (Throwable t) {
+            bug(461, t, "NaN problems");
+        }
+    }
+    
+    public void testDoubleNegativeInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.NEGATIVE_INFINITY);
+            saveAndQuery(aftt, "testdouble =",
+                    new Double(Double.NEGATIVE_INFINITY));
+        } catch (Throwable t) {
+            bug(461, t, "infinity problems");
+        }
+    }
+    
+    public void testDoublePostivieInfinity() {
+        try {
+            AllFieldTypesTest aftt = new AllFieldTypesTest();
+            aftt.setTestdouble(Double.POSITIVE_INFINITY);
+            saveAndQuery(aftt, "testdouble =",
+                    new Double(Double.POSITIVE_INFINITY));
+        } catch (Throwable t) {
+            bug(461, t, "infinity problems");
+        }
+    }
+
+    public void testByteMin() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestbyte(Byte.MIN_VALUE);
+        try {
+            saveAndQuery(aftt, "testbyte =", new Byte(Byte.MIN_VALUE));
+        } catch (Throwable t) {
+            //bug(AbstractTestCase.Platform.EMPRESS, 889, t, "Empress cannot store min values");
+            Assert.fail(
+                "Exception was thrown while storing Byte.MIN_VALUE : \n" +
+                    getStackTrace(t));
+        }
+    }
+
+    public void testByteMax() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestbyte(Byte.MAX_VALUE);
+        saveAndQuery(aftt, "testbyte =", new Byte(Byte.MAX_VALUE));
+    }
+    
+    public void testZeroBigInteger() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestBigInteger(BigInteger.ZERO);
+        saveAndQuery(aftt, "testBigInteger =", BigInteger.ZERO);
+    }
+    
+    public void testOneBigInteger() {
+        AllFieldTypesTest aftt = new AllFieldTypesTest();
+        aftt.setTestBigInteger(BigInteger.ONE);
+        saveAndQuery(aftt, "testBigInteger =", BigInteger.ONE);
+    }
+    
+    private void saveAndQuery(Object obj, String query, Object param) {
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        pm.persist(obj);
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM(false, false);
+//        Query q = pm.newQuery(obj.getClassquery);
+//        q.declareParameters("Object param");
+//        Collection c = (Collection) q.execute(param);
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT a FROM AllFieldTypesTest a WHERE a." + query + " " + param);
+        Collection c = (Collection) q.getResultList();
+        assertSize(1, c);
+        pm.close();
+    }
+}
+
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStateManagerImplData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStateManagerImplData.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStateManagerImplData.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStateManagerImplData.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,193 @@
+/*
+ * TestStateManagerImplData.java
+ *
+ * Created on October 13, 2006, 5:40 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+/*
+ * 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.openjpa.persistence.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestStateManagerImplData extends BaseKernelTest {
+
+    ClassMetaData _meta;
+
+    Boolean _f1;
+
+    Boolean _f3;
+
+    /**
+     * Creates a new instance of TestStateManagerImplData
+     */
+    public TestStateManagerImplData() {
+    }
+
+    public TestStateManagerImplData(String test) {
+        super(test);
+    }
+
+    public void setUpMetaData(ClassMetaData meta) {
+        _meta = meta;
+        _f1 = _meta.getField(1).usesImplData();
+        _f3 = _meta.getField(3).usesImplData();
+        _meta.getField(1).setUsesImplData(Boolean.TRUE);
+        _meta.getField(3).setUsesImplData(null);
+    }
+
+    public void tearDownMetaData() {
+        _meta.getField(1).setUsesImplData(_f1);
+        _meta.getField(3).setUsesImplData(_f3);
+    }
+
+    public void testImplData() {
+        ModRuntimeTest1 pc = new ModRuntimeTest1();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        pm.persist(pc);
+        OpenJPAStateManager sm = getStateManager(pc, pm);
+        setUpMetaData(sm.getMetaData());
+        try {
+            // test instance level
+            Object inst = new Object();
+            assertNull(sm.getImplData());
+            assertNull(sm.setImplData(inst, true));
+            assertEquals(inst, sm.getImplData());
+            assertTrue(sm.isImplDataCacheable());
+            assertEquals(inst, sm.setImplData(null, false));
+            assertNull(sm.getImplData());
+            assertFalse(sm.isImplDataCacheable());
+            sm.setImplData(inst, false);
+            assertFalse(sm.isImplDataCacheable());
+
+            // test field level
+            Object f1 = new Object();
+            Object f3 = new Object();
+
+            assertNull(sm.getImplData(1));
+            assertFalse(sm.isImplDataCacheable(1));
+            assertNull(sm.setImplData(1, f1));
+            assertEquals(f1, sm.getImplData(1));
+            assertTrue(!sm.isImplDataCacheable(1));
+            assertEquals(f1, sm.setImplData(1, null));
+            assertNull(sm.getImplData(1));
+            assertFalse(sm.isImplDataCacheable(1));
+            sm.setImplData(1, f1);
+
+            assertNull(sm.setImplData(3, f3));
+            assertEquals(f3, sm.getImplData(3));
+            assertTrue(sm.isImplDataCacheable(3));
+            assertEquals(f1, sm.getImplData(1));
+
+            // this should clear field data
+            endTx(pm);
+
+            assertEquals(inst, sm.getImplData());
+            assertNull(sm.getImplData(1));
+            assertNull(sm.getImplData(3));
+
+            endEm(pm);
+        } finally {
+            tearDownMetaData();
+        }
+    }
+
+    public void testNotClearedIfRetainValues() {
+        deleteAll(ModRuntimeTest1.class);
+        notClearedIfRetainValuesTest(true);
+        notClearedIfRetainValuesTest(false);
+    }
+
+    private void notClearedIfRetainValuesTest(boolean optimistic) {
+        ModRuntimeTest1 pc = new ModRuntimeTest1("pc", 1);
+        int key = 1;
+        Object value = new Object();
+
+        // make instance persistent
+        OpenJPAEntityManager pm = getPM(optimistic, true);
+        startTx(pm);
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+
+        OpenJPAStateManager sm = getStateManager(pc, pm);
+        assertNotNull(sm);
+        setUpMetaData(sm.getMetaData());
+        try {
+            // set impl data
+            sm.setImplData(key, value);
+            assertEquals(value, sm.getImplData(key));
+            endTx(pm);
+
+            // test in nontransactional setting
+            assertEquals(value, sm.getImplData(key));
+
+            // test in next transaction
+            startTx(pm);
+            pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
+            sm = getStateManager(pc, pm);
+            assertNotNull(sm);
+            if (pm.getOptimistic())
+                assertEquals(value, sm.getImplData(key));
+            else
+                assertNull(sm.getImplData(key));
+            endTx(pm);
+            endEm(pm);
+        } finally {
+            tearDownMetaData();
+        }
+
+        // test in another pm for good measure
+        pm = getPM(optimistic, true);
+        pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
+        sm = getStateManager(pc, pm);
+        assertNotNull(sm);
+        setUpMetaData(sm.getMetaData());
+        try {
+            sm.setImplData(key, value);
+            assertEquals(value, sm.getImplData(key));
+
+            // test in transaction; re-lookup pc to be sure it enters the trans
+            startTx(pm);
+            pc = (ModRuntimeTest1) pm.find(ModRuntimeTest1.class, oid);
+            if (pm.getOptimistic())
+                assertEquals(value, sm.getImplData(key));
+            else {
+                assertNull(sm.getImplData(key));
+                sm.setImplData(key, value);
+            }
+            endTx(pm);
+
+            // test outside of transaction
+            assertEquals(value, sm.getImplData(key));
+            endEm(pm);
+        } finally {
+            tearDownMetaData();
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStaticInnerClasses.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStaticInnerClasses.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStaticInnerClasses.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStaticInnerClasses.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,140 @@
+/*
+ * TestStaticInnerClasses.java
+ *
+ * Created on October 13, 2006, 5:45 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * 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.openjpa.persistence.kernel;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.persistence.Entity;
+
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestStaticInnerClasses extends BaseKernelTest {
+
+    private Object _oid = null;
+
+    /**
+     * Creates a new instance of TestStaticInnerClasses
+     */
+    public TestStaticInnerClasses() {
+    }
+
+    public TestStaticInnerClasses(String name) {
+        super(name);
+    }
+
+    public void setUp()
+        throws Exception {
+        Inner inner = new Inner("foo");
+        inner.addTwin();
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(inner);
+        _oid = pm.getObjectId(inner);
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testGetById() {
+        OpenJPAEntityManager pm = getPM();
+        Inner inner = (Inner) pm.find(Inner.class, _oid);
+        assertNotNull(inner);
+        assertEquals("foo", inner.getString());
+        endEm(pm);
+    }
+
+    public void testGetByQuery() {
+//        OpenJPAEntityManager pm = getPM();
+//
+//        OpenJPAQuery q = pm.createNativeQuery("",Inner.class);
+//        //FIXME jthomas
+//        /*
+//        q.ssetCandidates(pm.createExtent(Inner.class, false));
+//        q.declareVariables(Inner.class.getName() + " inner;");
+//        q.setFilter("twins.contains (inner) && inner.string == \"foo\"");
+//        q.setOrdering("string ascending, num descending");
+//        Iterator iter = null;
+//        try {
+//            iter = ((Collection) q.execute()).iterator();
+//        } catch (JDOException jdoe) {
+//            if (jdoe.getMessage().indexOf("is ambiguous") != -1)
+//                bug(AbstractTestCase.Platform.POSTGRESQL, 74, jdoe,
+//                        "Sorts in PostgreSQL may result"
+//                        + "in \"ORDER BY 'my_sort_key' is ambiguous\"");
+//            else
+//                throw jdoe;
+//        }
+//
+//        assertNotNull(iter);
+//        assertTrue(iter.hasNext());
+//        assertEquals("foo", ((Inner) iter.next()).getString());
+//        */
+//        endEm(pm,());
+        /*OpenJPAEntityManager pm = getPM();
+          OpenJPAQuery q = pm.createQuery("SELECT c FROM TestStaticInnerClasses.Inner c WHERE c.string = 'foo' ORDER BY c.string ASC");
+          q.setCandidateCollection((Collection)pm.createExtent(TestStaticInnerClasses.Inner.class, false));
+
+          try
+          {
+              Iterator iter = ((Collection) q.getResultList()).iterator();
+          }
+          catch (Exception jdoe)
+          {
+              if (jdoe.getMessage().indexOf("is ambiguous") != -1)
+                  bug(AbstractTestCase.Platform.POSTGRESQL, 74, jdoe,
+                          "Sorts in PostgreSQL may result"
+                          + "in \"ORDER BY 'my_sort_key' is ambiguous\"");
+              else
+                  throw jdoe;
+          }*/
+
+    }
+
+    @Entity
+    public static class Inner {
+
+        private int num = 0;
+        private String string = null;
+        private List twins = new LinkedList();
+
+        protected Inner() {
+        }
+
+        public Inner(String string) {
+            this.string = string;
+        }
+
+        public void addTwin() {
+            twins.add(new Inner(string));
+        }
+
+        public String getString() {
+            return string;
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStoreBlob.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStoreBlob.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStoreBlob.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestStoreBlob.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,86 @@
+/*
+ * TestStoreBlob.java
+ *
+ * Created on October 13, 2006, 5:50 PM
+ *
+ * To change this template, choose Tools | Template Manager
+ * and open the template in the editor.
+ */
+
+/*
+ * 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.openjpa.persistence.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.BlobTest;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestStoreBlob extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestStoreBlob
+     */
+    public TestStoreBlob() {
+    }
+
+    public TestStoreBlob(String name) {
+        super(name);
+    }
+
+    public void testStoreBlob() {
+        OpenJPAEntityManager pm;
+
+        pm = getPM(false, false);
+        startTx(pm);
+        BlobTest blob = new BlobTest();
+        byte[] bytes = new byte[2048];
+        for (int i = 0; i < bytes.length; i++)
+            bytes[i] = randomByte().byteValue();
+
+        blob.setBlob(bytes);
+        pm.persist(blob);
+        int id = blob.getId();
+        endTx(pm);
+
+        byte[] b1 = blob.getBlob();
+        endEm(pm);
+
+        pm = getPM(false, false);
+        startTx(pm);
+        BlobTest blob2 = pm.find(BlobTest.class, id);
+
+        byte[] b2 = blob2.getBlob();
+
+        assertNotNull("Original blob was null", b1);
+        assertNotNull("Retrieved blob was null", b2);
+        assertEquals("Blob length was not the same", b1.length, b2.length);
+        assertBytesEquals("Blob contents did not match", b1, b2);
+
+        endTx(pm);
+    }
+
+    private void assertBytesEquals(String str,
+        byte[] a, byte[] b) {
+        for (int i = 0; i < a.length; i++) {
+            assertEquals(str + " [" + i + "]", a[i], b[i]);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestTransition2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestTransition2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestTransition2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestTransition2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,994 @@
+/*
+ * 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.openjpa.persistence.kernel;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest1;
+import org.apache.openjpa.persistence.kernel.common.apps.ModRuntimeTest2;
+import org.apache.openjpa.persistence.kernel.common.apps.PersistenceAware;
+
+import org.apache.openjpa.enhance.PersistenceCapable;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.RestoreStateType;
+
+public class TestTransition2 extends BaseKernelTest {
+
+    private boolean supportsPessimistic = true;
+
+    private int _id = 0;
+
+    /**
+     * Creates a new instance of TestTransitions
+     */
+    public TestTransition2() {
+    }
+
+    public TestTransition2(String name) {
+        super(name);
+    }
+
+    public void setUp() throws Exception {
+        try {
+            OpenJPAEntityManager pm = getPM(false, false);
+            supportsPessimistic = !pm.getOptimistic();
+            pm.close();
+        }
+        catch (Exception e) {
+            supportsPessimistic = false;
+        }
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+
+        ModRuntimeTest2 b = createTest2();
+        pm.persist(b);
+        _id = b.getId();
+
+        endTx(pm);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions from transient to
+     * persistent-transactional and back to transient after rollback.
+     */
+    public void testFlagTransitions1()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+        assertTransient(b);
+        assertTransient(b.getSelfOneOne());
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        pm.persist(b);
+
+        assertPersistent(b, true, true, false, true);
+
+        rollbackTx(pm);
+
+        assertTransient(b);
+        assertTransient(b.getSelfOneOne());
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions from transient to
+     * persistent-transactional to persistent-nontransactional after commit.
+     */
+    public void testFlagTransitions2()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+        assertTransient(b);
+        assertTransient(b.getSelfOneOne());
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        pm.persist(b);
+
+        assertPersistent(b, true, true, false, true);
+
+        endTx(pm);
+
+        assertPersistent(b, false, false, false, false);
+        assertPersistent(b.getSelfOneOne(), false, false, false, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions when finding a transactional instance by
+     * id, then committing.
+     */
+    public void testFlagTransitions3() throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertPersistent(b, true, false, false, false);
+        assertPersistent(b.getSelfOneOne(), true, false, false, false);
+
+        endTx(pm);
+
+        assertPersistent(b, false, false, false, false);
+        assertPersistent(b.getSelfOneOne(), false, false, false, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testFlagTransitions4()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertPersistent(b, true, false, false, false);
+        assertPersistent(b.getSelfOneOne(), true, false, false, false);
+
+        rollbackTx(pm);
+        //pm.getTransaction().rollback();
+
+        assertPersistent(b, false, false, false, false);
+        assertPersistent(b.getSelfOneOne(), false, false, false, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions when finding a non-transactional
+     * instance by id.
+     */
+    public void testFlagTransitions5()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+
+        assertPersistent(b, false, false, false, false);
+        assertPersistent(b.getSelfOneOne(), false, false, false, false);
+
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions from persistent-transactional
+     * to transient after delete and commit.
+     */
+    public void testFlagTransitions6()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+        pm.remove(b);
+        assertPersistent(b, true, false, true, true);
+        assertPersistent(parent, true, false, false, false);
+
+        endTx(pm);
+
+        assertTransient(b);
+        assertPersistent(parent, false, false, false, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic jdo flag transitions from persistent-transactional
+     * to persistent-nontransactional after delete and rollback.
+     */
+    public void testFlagTransitions7()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+        pm.remove(b);
+        assertPersistent(b, true, false, true, true);
+        assertPersistent(parent, true, false, false, false);
+
+        rollbackTx(pm);
+
+        assertPersistent(b, false, false, false, false);
+        assertPersistent(parent, false, false, false, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional and back to transient after rollback.
+     */
+    public void testStateTransitions1()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        pm.persist(b);
+        pm.persist(b.getSelfOneOne());
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional to persistent-nontransactional after commit.
+     */
+    public void testStateTransitions2()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        pm.persist(b);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then committing.
+     */
+    public void testStateTransitions3()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then committing.
+     */
+    public void testStateTransitions3a()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testStateTransitions4()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testStateTransitions4a()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to transient after delete and commit.
+     */
+    public void testStateTransitions5()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+        assertNotNull("parent is null", parent);
+        pm.remove(b);
+
+        endTx(pm);
+
+        // parent should be valid
+        assertEquals("PARENT", parent.getStringField());
+
+        // 'b' should be cleared
+        assertNull(b.getStringField());
+        assertEquals(0, b.getIntField());
+        assertNull(b.getSelfOneOne());
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to persistent-nontransactional after delete and rollback.
+     */
+    public void testStateTransitions6()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        pm.remove(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional and back to transient after rollback.
+     */
+    public void testOptStateTransitions1()
+        throws Exception {
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        pm.persist(b);
+        pm.persist(b.getSelfOneOne());
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional to persistent-nontransactional after commit.
+     */
+    public void testOptStateTransitions2()
+        throws Exception {
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        pm.persist(b);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then committing.
+     */
+    public void testOptStateTransitions3()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testOptStateTransitions4()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to transient after delete and commit.
+     */
+    public void testOptStateTransitions5()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+        assertNotNull("parent is null", parent);
+        pm.remove(b);
+
+        endTx(pm);
+
+        // parent should be valid
+        assertEquals("PARENT", parent.getStringField());
+
+        // 'b' should be cleared
+        assertNull(b.getStringField());
+        assertEquals(0, b.getIntField());
+        assertNull(b.getSelfOneOne());
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to persistent-nontransactional after delete and rollback.
+     */
+    public void testOptStateTransitions6()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, false);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        pm.remove(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional and back to transient after rollback.
+     */
+    public void testOptRetainStateTransitions1()
+        throws Exception {
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        pm.persist(b);
+        pm.persist(b.getSelfOneOne());
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional to persistent-nontransactional after commit.
+     */
+    public void testOptRetainStateTransitions2()
+        throws Exception {
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        pm.persist(b);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, true);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then committing.
+     */
+    public void testOptRetainStateTransitions3()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, true);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testOptRetainStateTransitions4()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to transient after delete and commit.
+     */
+    public void testOptRetainStateTransitions5()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+
+        assertNotNull("parent is null", parent);
+        pm.remove(b);
+
+        endTx(pm);
+
+        // parent should be valid
+        assertEquals("PARENT", parent.getStringField());
+
+        // 'b' should be cleared
+        assertNull(b.getStringField());
+        assertEquals(0, b.getIntField());
+        assertNull(b.getSelfOneOne());
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to persistent-nontransactional after delete and rollback.
+     */
+    public void testOptRetainStateTransitions6()
+        throws Exception {
+        OpenJPAEntityManager pm = getPM(true, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        pm.remove(b);
+
+        rollbackTx(pm);
+
+        if (pm.getRestoreState() != RestoreStateType.NONE)
+            assertTest2Orig(b);
+        else
+            assertNull(b.getStringField());
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional and back to transient after rollback.
+     */
+    public void testRetainStateTransitions1()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        pm.persist(b);
+        pm.persist(b.getSelfOneOne());
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * persistent-transactional to persistent-nontransactional after commit.
+     */
+    public void testRetainStateTransitions2()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        pm.persist(b);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, true);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then committing.
+     */
+    public void testRetainStateTransitions3()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, true);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions when finding a transactional
+     * instance by id, then rolling back.
+     */
+    public void testRetainStateTransitions4()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        assertTest2Orig(b);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to transient after delete and commit.
+     */
+    public void testRetainStateTransitions5() throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b = (ModRuntimeTest2) pm.find(ModRuntimeTest2.class,
+            _id);
+        ModRuntimeTest1 parent = b.getSelfOneOne();
+        assertNotNull("parent is null", parent);
+        pm.remove(b);
+
+        endTx(pm);
+
+        // parent should be valid
+        assertEquals("PARENT", parent.getStringField());
+
+        // 'b' should be cleared
+        assertNull(b.getStringField());
+        assertEquals(0, b.getIntField());
+        assertNull(b.getSelfOneOne());
+    }
+
+    /**
+     * Tests basic state transitions from persistent-transactional
+     * to persistent-nontransactional after delete and rollback.
+     */
+    public void testRetainStateTransitions6()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        OpenJPAEntityManager pm = getPM(false, true);
+        startTx(pm);
+
+        ModRuntimeTest2 b =
+            (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, _id);
+        pm.remove(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * transient-dirty and back to transient after rollback.
+     */
+    public void testTransientStateTransitions1()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        pm.transactional(b, true);
+        pm.transactional(b.getSelfOneOne(), true);
+        changeTest2(b);
+
+        rollbackTx(pm);
+
+        assertTest2Orig(b);
+        endEm(pm);
+    }
+
+    /**
+     * Tests basic state transitions from transient to
+     * transient-transactional and stick on commit.
+     */
+    public void testTransientStateTransitions2()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+
+        pm.transactional(b, true);
+        pm.transactional(b.getSelfOneOne(), true);
+        changeTest2(b);
+
+        endTx(pm);
+
+        assertTest2Changed(b, false);
+        endEm(pm);
+    }
+
+    /**
+     * Tests state transitions from PClean to transient.
+     */
+    public void testTransientStateTransitions3()
+        throws Exception {
+        if (!supportsPessimistic)
+            return;
+
+        ModRuntimeTest2 b = createTest2();
+
+        OpenJPAEntityManager pm = getPM(false, false);
+        startTx(pm);
+        pm.persist(b);
+        int oid = b.getId();
+        endTx(pm);
+        endEm(pm);
+
+        pm = getPM(false, false);
+        //FIXME jthomas
+        b = (ModRuntimeTest2) pm.find(ModRuntimeTest2.class, oid);
+        pm.retrieve(b);
+        //FIXME jthomas
+        endEm(pm);
+
+        // note that at this point, parent is not transient, just retrieved.
+        assertNotNull("b is null", b.getSelfOneOne());
+    }
+
+    private ModRuntimeTest2 createTest2() {
+        return createTest2("NAME", 50);
+    }
+
+    private ModRuntimeTest2 createTest2(String str, int i) {
+        return createTest2(new ModRuntimeTest2(str, i));
+    }
+
+    private ModRuntimeTest2 createTest2(ModRuntimeTest2 b) {
+        ModRuntimeTest1 parent = new ModRuntimeTest1("PARENT", 70);
+        b.setSelfOneOne(parent);
+        return b;
+    }
+
+    private void changeTest2(ModRuntimeTest2 b) {
+        PersistenceAware.setModTransString(b, "999");
+        b.setStringField("CHANGED");
+        b.setIntField(1000);
+        b.getSelfOneOne().setStringField("PCHANGED");
+        b.setSelfOneOne(null);
+    }
+
+    private void assertTest2Changed(ModRuntimeTest2 b, boolean retainValues) {
+        if (retainValues)
+            assertEquals("999", PersistenceAware.getModTransString(b));
+        assertEquals("CHANGED", b.getStringField());
+        assertEquals(1000, b.getIntField());
+        assertNull(b.getSelfOneOne());
+    }
+
+    private void assertTest2Orig(ModRuntimeTest2 b) {
+        assertEquals("NAME", b.getStringField());
+        assertEquals(50, b.getIntField());
+        assertNotNull(b.getSelfOneOne());
+        assertEquals("PARENT", b.getSelfOneOne().getStringField());
+
+        assertEquals(
+            "transactional field 'transString' was not the "
+                + "same as it was originally. Ensure that "
+                + "openjpa.kernel.PersistenceAware is enhanced. "
+                +
+                "It is persistence-aware, so will not be enhanced by commands "
+                + "like jdoc $(find test -name '*.jdo').", null,
+            PersistenceAware.getModTransString(b));
+    }
+
+    /**
+     * Assert that the given object is persistent.
+     */
+    public void assertTransient(Object a) {
+        OpenJPAEntityManager pm = currentEntityManager();
+        assertTrue(!pm.isPersistent(a));
+        assertTrue(!pm.isTransactional(a));
+        assertTrue(!pm.isNewlyPersistent(a));
+        assertTrue(!pm.isDirty(a));
+        assertTrue(!pm.isRemoved(a));
+        assertNull(pm.getObjectId(a));
+        assertNull(OpenJPAPersistence.getEntityManager(a));
+        endEm(pm);
+    }
+
+    /**
+     * Assert that the given object is persistent and is in the given state.
+     */
+    public void assertPersistent(Object a, boolean isTrans, boolean isNew,
+        boolean isDeleted, boolean isDirty) {
+        OpenJPAEntityManager pm =
+            (OpenJPAEntityManager) currentEntityManager();
+        assertTrue(pm.isPersistent(a));
+
+        PersistenceCapable xman = (PersistenceCapable) a;
+
+        assertEquals(isTrans, pm.isTransactional(a));
+		assertEquals(isNew, pm.isNewlyPersistent(a));
+		assertEquals(isDeleted, pm.isRemoved(a));
+		assertEquals(isDirty || isNew || isDeleted, pm.isDirty(a));
+		assertNotNull(pm.getObjectId(a));
+		assertNotNull(OpenJPAPersistence.getEntityManager(a));
+
+		endEm(pm);
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AImplB.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AImplB.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AImplB.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AImplB.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,115 @@
+/*
+ * 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.openjpa.persistence.kernel.common.apps;
+
+import java.io.Serializable;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "aimplb")
+@IdClass(AImplB.Idkey.class)
+public class AImplB implements AIntf {
+
+    private String name;
+    @Id
+    private int pk1;
+    @Id
+    private String pk2;
+
+    protected AImplB() {
+    }
+
+    public AImplB(String name, int pk1, String pk2) {
+        setName(name);
+        this.pk1 = pk1;
+        this.pk2 = pk2;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public void setPK1(int pk1) {
+        this.pk1 = pk1;
+    }
+
+    public int getPK1() {
+        return this.pk1;
+    }
+
+    public void setPK2(String pk2) {
+        this.pk2 = pk2;
+    }
+
+    public String getPK2() {
+        return this.pk2;
+    }
+
+    public static class Idkey implements Serializable {
+
+        public int pk1;
+        public String pk2;
+
+        public Idkey() {
+        }
+
+        public Idkey(String str) {
+            int index = str.indexOf("/");
+            if (index != -1) {
+                pk1 = Integer.parseInt(str.substring(0, index));
+                pk2 = str.substring(index + 1);
+            }
+        }
+
+        public String toString() {
+            return pk1 + "/" + pk2;
+        }
+
+        @Override
+        public boolean equals(Object other) {
+            if (!(other instanceof Idkey))
+                return false;
+
+            Idkey id = (Idkey) other;
+            if (pk2 == null && id.pk2 != null)
+                return false;
+            if (pk2 != null && id.pk2 == null)
+                return false;
+            if (!(pk1 == id.pk1))
+                return false;
+            if (!(pk2.equals(id.pk2)))
+                return false;
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            return (pk1 + pk2).hashCode();
+        }
+    }
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AIntf.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AIntf.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AIntf.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AIntf.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.openjpa.persistence.kernel.common.apps;
+
+/**
+ * Interface inplemented by {@link A}, used for interface
+ * testing.
+ *
+ * @author <a href="mailto:marc@solarmetric.com">Marc Prud'hommeaux</a>
+ */
+public interface AIntf {
+
+    public String getName();
+
+    public void setName(String name);
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AbstractMappedAppIdSuper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AbstractMappedAppIdSuper.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AbstractMappedAppIdSuper.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/AbstractMappedAppIdSuper.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,37 @@
+/*
+ * 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.openjpa.persistence.kernel.common.apps;
+
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+@MappedSuperclass
+public abstract class AbstractMappedAppIdSuper {
+
+    @Id
+    private String pk;
+
+    public String getPk() {
+        return this.pk;
+    }
+
+    public void setPk(String pk) {
+        this.pk = pk;
+    }
+}



Mime
View raw message