openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [26/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/TestEJBInterfaces.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBInterfaces.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.InterfaceHolder;
+import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl1;
+import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl2;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+/**
+ * Test for persistent interfaces.
+ *
+ * @author <a href="mailto:marc@solarmetric.com">Marc Prud'hommeaux</a>
+ */
+public class TestEJBInterfaces extends AbstractTestCase {
+
+    public TestEJBInterfaces(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    @SuppressWarnings("unchecked")
+    public void testInterfaceField() {
+        try {
+            deleteAll(InterfaceTestImpl1.class);
+            deleteAll(InterfaceTestImpl2.class);
+            deleteAll(InterfaceHolder.class);
+        }
+        catch (Exception e) {
+        }
+
+        EntityManager em2 = currentEntityManager();
+        startTx(em2);
+
+        em2.flush();
+        endTx(em2);
+        endEm(em2);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+        InterfaceHolder holder = new InterfaceHolder(1);
+        em.persist(holder);
+        holder.setIntf(new InterfaceTestImpl1("intf-1-field"));
+        assertEquals("intf-1-field", holder.getIntf().getStringField());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        InterfaceHolder hold =
+            (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        assertNotNull(hold.getIntf());
+        assertEquals("intf-1-field", hold.getIntf().getStringField());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        hold.setIntf(null);
+        assertNull(hold.getIntf());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        assertNull(hold.getIntf());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        hold.setIntf(new InterfaceTestImpl2("intf-2-field"));
+        assertEquals("intf-2-field", hold.getIntf().getStringField());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        assertNotNull(hold.getIntf());
+        assertEquals("intf-2-field", hold.getIntf().getStringField());
+        endTx(em);
+        endEm(em);
+
+        em = currentEntityManager();
+        startTx(em);
+        hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1);
+        hold.getIntfs().add(new InterfaceTestImpl1("intf-1-set"));
+        endTx(em);
+        endEm(em);
+
+//		em = currentEntityManager();
+//		startTx(em);
+//		hold = (InterfaceHolder)em.find(InterfaceHolder.class, 1);
+//		assertEquals (1, hold.getIntfs ().size ());
+//		assertEquals ("intf-1-set", ((InterfaceTest) hold.getIntfs ().iterator ().next ()).getStringField ());
+//		endTx(em);
+//		endEm(em);
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLobs.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLobs.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLobs.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLobs.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,175 @@
+/*
+ * 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.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBLobs extends AbstractTestCase {
+
+    private EntityManager _pm = null;
+    private Inner _inner = null;
+
+    public TestEJBLobs(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() throws Exception {
+        deleteAll(Inner.class);
+        deleteAll(Inner2.class);
+
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        endTx(em);
+        endEm(em);
+
+        Inner inner = new Inner();
+        inner.setString("string");
+        inner.setClob("clobField");
+        inner.setEBlob("eblob");
+
+        Inner2 inner2 = new Inner2();
+        inner2.string = "inner2";
+        inner.setBlob(inner2);
+
+        _pm = currentEntityManager();
+        startTx(_pm);
+        _pm.persist(inner);
+        try {
+            endTx(_pm);
+        }
+        catch (Exception jdoe) {
+            System.out.println(
+                "An exception was thrown while persisting the entity : \n" +
+                    getStackTrace(jdoe));
+        }
+        endEm(_pm);
+
+        _pm = currentEntityManager();
+        _inner = (Inner) _pm.find(Inner.class, "string");
+    }
+
+    public void testOtherFields() {
+        assertEquals("string", _inner.getString());
+    }
+
+    public void testClob() {
+        assertEquals("clobField", _inner.getClob());
+    }
+
+    public void testBlob() {
+        assertNotNull(_inner.getBlob());
+        assertEquals("inner2", _inner.getBlob().string);
+    }
+
+    public void testSetNull() {
+        startTx(_pm);
+        _inner.setClob(null);
+        _inner.setBlob(null);
+        endTx(_pm);
+
+        assertEquals(null, _inner.getBlob());
+        assertEquals(null, _inner.getClob());
+    }
+
+    public void testDelete() {
+        deleteAll(Inner.class);
+    }
+
+    public void testUpdate() {
+        startTx(_pm);
+        _inner.setClob("newvalue");
+        Inner2 inner2 = new Inner2();
+        inner2.string = "newinner2";
+        _inner.setBlob(inner2);
+        endTx(_pm);
+
+        assertEquals("newvalue", _inner.getClob());
+        assertEquals("newinner2", _inner.getBlob().string);
+    }
+
+    @Entity
+    @Table(name = "inntable")
+    public static class Inner {
+
+        @Id
+        private String string = null;
+        private String clobField = null;
+        private Object eblob = null;
+
+        @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+        private Inner2 blobField = null;
+
+        public String getString() {
+            return string;
+        }
+
+        public void setString(String val) {
+            string = val;
+        }
+
+        public String getClob() {
+            return clobField;
+        }
+
+        public void setClob(String val) {
+            clobField = val;
+        }
+
+        public String getEBlob() {
+            return ((String) eblob);
+        }
+
+        public void setEBlob(String val) {
+            eblob = val;
+        }
+
+        public Inner2 getBlob() {
+            return blobField;
+        }
+
+        public void setBlob(Inner2 val) {
+            blobField = val;
+        }
+    }
+
+    @SuppressWarnings("serial")
+    @Entity
+    public static class Inner2 implements Serializable {
+
+        @Id
+        public String string = null;
+
+        public String getString() {
+            return string;
+        }
+
+        public void setString(String string) {
+            this.string = string;
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBLocales.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,80 @@
+/*
+ * 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.Iterator;
+import java.util.List;
+import java.util.Locale;
+import javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBLocales extends AbstractTestCase {
+
+    public TestEJBLocales(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+    }
+
+    public void testLocales() {
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        RuntimeTest1 t1 = new RuntimeTest1(1);
+        t1.setLocaleField(new Locale(Locale.FRANCE.getCountry(),
+            Locale.FRENCH.getLanguage()));
+        pm.persist(t1);
+        pm.persist(new RuntimeTest1(2));
+        endTx(pm);
+        endEm(pm);
+
+        pm = currentEntityManager();
+        List c = findAll(RuntimeTest1.class, pm);
+        assertEquals(2, c.size());
+
+        boolean foundNull = false;
+        boolean foundFrance = false;
+        Locale locale;
+
+        for (Iterator iter = c.iterator(); iter.hasNext();) {
+            t1 = (RuntimeTest1) iter.next();
+            locale = t1.getLocaleField();
+            if (locale == null)
+                foundNull = true;
+            else if (
+                (locale.getCountry().equals(Locale.FRANCE.getCountry())) &&
+                    (locale.getLanguage().equals(Locale.FRANCE.getLanguage())))
+                foundFrance = true;
+        }
+
+        assertTrue(foundNull);
+        assertTrue(foundFrance);
+        endEm(pm);
+    }
+
+    public List findAll(Class c, EntityManager em) {
+        List l = em.createQuery("Select object(o) from RuntimeTest1 o")
+            .getResultList();
+        return l;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBManagedInverses.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBManagedInverses.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBManagedInverses.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBManagedInverses.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,93 @@
+/*
+ * 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 javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.InverseA;
+import org.apache.openjpa.persistence.kernel.common.apps.InverseB;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBManagedInverses extends AbstractTestCase {
+
+    public TestEJBManagedInverses(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(InverseA.class);
+        deleteAll(InverseB.class);
+    }
+
+    public void testOneOne() {
+        oneOneTest(true);
+    }
+
+    public void testOneOneWithPreStore() {
+        oneOneTest(false);
+    }
+
+    private void oneOneTest(boolean flush) {
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        InverseA a = new InverseA();
+        InverseA a2 = new InverseA();
+        InverseA a3 = new InverseA();
+        a.setOneOne(a2);
+        a.setOneOneOwner(a2);
+        pm.persist(a);
+        pm.persist(a3);
+
+//		assertEquals (a, a2.getOneOne ());
+//		assertEquals (a, a2.getOneOneOwner ());
+        assertEquals("a.getOneOne is not a2", a2, a.getOneOne());
+        assertEquals("a.getOneOneOwner is not a2", a2, a.getOneOneOwner());
+        endTx(pm);
+
+        startTx(pm);
+        a2.setOneOne(a3);
+        a2.setOneOneOwner(a3);
+
+//		assertEquals (a2, a3.getOneOne ());
+//		assertEquals (a2, a3.getOneOneOwner ());
+        assertEquals(a3, a2.getOneOne());
+        assertEquals(a3, a2.getOneOneOwner());
+        endTx(pm);
+
+        // make sure commit doesn't retrigger changes
+//		assertEquals (a2, a3.getOneOne ());
+//		assertEquals (a2, a3.getOneOneOwner ());
+        assertEquals(a3, a2.getOneOne());
+        assertEquals(a3, a2.getOneOneOwner());
+
+        // test persistent -> dirty
+        startTx(pm);
+        a2.setOneOne(null);
+        a2.setOneOneOwner(null);
+//		if (flush)
+//			pm.flush ();
+//		else
+//			pm.setFlushMode(FlushModeType.AUTO);
+//		assertNull (a3.getOneOne ());
+//		assertNull (a3.getOneOneOwner ());
+        endTx(pm);
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNoPersistentFields.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNoPersistentFields.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNoPersistentFields.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNoPersistentFields.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,106 @@
+/*
+ * 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.io.Serializable;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.EntityManager;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBNoPersistentFields extends AbstractTestCase {
+
+    private Nholder holder;
+
+    public TestEJBNoPersistentFields(String test) {
+        super(test, "kernelcactusapp");
+    }
+
+    public void setUp() throws Exception {
+        deleteAll(Nholder.class);
+    }
+
+    public void testNoPersistentFields() {
+        EntityManager em = currentEntityManager();
+        startTx(em);
+
+        holder = new Nholder();
+        holder.setNpf(new NoPersistentFieldsPC());
+        holder.setIdKey(1);
+
+        em.persist(holder);
+        endTx(em);
+
+        Nholder holder2 = em.find(Nholder.class, 1);
+        assertEquals(1, holder2.getIdKey());
+        assertNotNull(holder2);
+        assertNotNull(holder2.getNpf());
+
+        endEm(em);
+    }
+
+    @SuppressWarnings("serial")
+    @Entity
+    @Table(name = "nholder2")
+    public static class Nholder implements Serializable {
+
+        @Id
+        private int idkey;
+
+        @OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
+        private NoPersistentFieldsPC npf;
+
+        public Nholder() {
+        }
+
+        public Nholder(NoPersistentFieldsPC npf, int idkey) {
+            this.npf = npf;
+            this.idkey = idkey;
+        }
+
+        public void setNpf(NoPersistentFieldsPC npf) {
+            this.npf = npf;
+        }
+
+        public NoPersistentFieldsPC getNpf() {
+            return this.npf;
+        }
+
+        public int getIdKey() {
+            return idkey;
+        }
+
+        public void setIdKey(int idkey) {
+            this.idkey = idkey;
+        }
+    }
+
+    @SuppressWarnings("serial")
+    @Entity
+    @Table(name = "npfp")
+    public static class NoPersistentFieldsPC implements Serializable {
+
+        public transient int blankInt;
+        public transient String blankString;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBNullValues.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,51 @@
+/*
+ * 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 javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.Inner;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBNullValues extends AbstractTestCase {
+
+    public TestEJBNullValues(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(Inner.class);
+    }
+
+    public void testException() {
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        pm.persist(new Inner());
+        try {
+            endTx(pm);
+            fail("Null value allowed");
+        }
+        catch (Exception jfe) {
+            System.out
+                .println("Exception expected...Null value not allowed...");
+        }
+        endEm(pm);
+    }
+}
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBObjectCollections.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBObjectCollections.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBObjectCollections.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBObjectCollections.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,76 @@
+/*
+ * 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.Arrays;
+import java.util.HashSet;
+import javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldsTypeTest;
+import org.apache.openjpa.persistence.kernel.common.apps.ObjectCollectionHolder;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+/**
+ * Tests that Collections of type {@link Object} can hold all
+ * sorts of stuff (heterogeneous classes, persistent classes).
+ *
+ * @author <a href="mailto:marc@solarmetric.com">Marc Prud'hommeaux</a>
+ */
+public class TestEJBObjectCollections extends AbstractTestCase {
+
+    public TestEJBObjectCollections(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void testHashSet() {
+        assertEquals(1, add(new Object[]{ "Foo" }, 1).getHashSet().size());
+        assertEquals(1, add(new Object[]{ "Foo" }, 2).getHashSet().size());
+
+        assertEquals(2, add(
+            new Object[]{ "Foo", new AllFieldsTypeTest() }, 3)
+            .getHashSet().size());
+    }
+
+    public void setUp() {
+        deleteAll(ObjectCollectionHolder.class);
+        deleteAll(AllFieldsTypeTest.class);
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    @SuppressWarnings("unchecked")
+    public ObjectCollectionHolder add(Object[] objects, int id) {
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        ObjectCollectionHolder holder = new ObjectCollectionHolder();
+        holder.setId(id);
+        pm.persist(holder);
+        holder.setHashSet(new HashSet(Arrays.asList(objects)));
+        endTx(pm);
+        endEm(pm);
+
+        pm = currentEntityManager();
+        startTx(pm);
+        return (ObjectCollectionHolder) pm
+            .find(ObjectCollectionHolder.class, id);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBRetainValues.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBRetainValues.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBRetainValues.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBRetainValues.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,87 @@
+/*
+ * 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 javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBRetainValues extends AbstractTestCase {
+
+    public TestEJBRetainValues(String testName) {
+        super(testName, "kernelcactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+    }
+
+    /**
+     * tests the behavior of the same object being viewed from
+     * different PersistenceManagers with RetainValues set to true
+     */
+    public void testRetainValues() {
+        // persist the object with field == "x"
+        RuntimeTest1 test = new RuntimeTest1();
+        test.setStringField("x");
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        pm.persist(test);
+        endTx(pm);
+
+        //	find the object in a different PM
+        EntityManager pm2 = currentEntityManager();
+        List l = (buildSelectQuery(pm2, "x"));
+        assertNotNull("l is null in testRetainValues", l);
+        RuntimeTest1 sameThing = (RuntimeTest1) l.iterator().next();
+
+        assertEquals("x", sameThing.getStringField());
+        assertEquals("x", test.getStringField());
+
+        //	set the second object field to "y"
+        startTx(pm2);
+        sameThing.setStringField("y");
+        endTx(pm2);
+        assertEquals("y", sameThing.getStringField());
+        assertEquals("x", test.getStringField());
+
+        //	do some searching in the first PM
+        List l2 = buildSelectQuery(pm, "x");
+        assertEquals(0,
+            l2.size());  //should be zero if retainvalue is set to true but that is kodo specific.
+
+        List l3 = buildSelectQuery(pm, "y");
+        assertEquals(1, l3.size());
+        assertEquals(test, l3.iterator().next());
+        assertEquals("x", test.getStringField());
+
+        endEm(pm2);
+        endEm(pm);
+    }
+
+    public static List buildSelectQuery(EntityManager em, String param) {
+        return em.createQuery(
+            "SELECT c FROM RuntimeTest1 c where c.stringField = :username")
+            .setParameter("username", param)
+            .getResultList();
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBState.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.BigDecimal;
+import javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AllFieldsTypeTest;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBState extends AbstractTestCase {
+
+    private static final int INSERT_COUNT = 20;
+
+    public TestEJBState(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() {
+        deleteAll(AllFieldsTypeTest.class);
+    }
+
+    public void testBigDecimalsLoseTrailingZeros() {
+        EntityManager pm1 = currentEntityManager();
+        startTx(pm1);
+        AllFieldsTypeTest aftt = new AllFieldsTypeTest();
+        aftt.setId(1);
+        aftt.setTestBigDecimal(new BigDecimal("5.760000"));
+        pm1.persist(aftt);
+
+        endTx(pm1);
+
+        EntityManager pm2 = currentEntityManager();
+        startTx(pm2);
+
+        Object retrieved = pm2.find(AllFieldsTypeTest.class, 1);
+        assertEquals(aftt, retrieved);
+        endTx(pm2);
+        endEm(pm2);
+        endEm(pm1);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactionalClass.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactionalClass.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactionalClass.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactionalClass.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,52 @@
+/*
+ * 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 javax.persistence.EntityManager;
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.TransactionalClassPC;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBTransactionalClass extends AbstractTestCase {
+
+    public TestEJBTransactionalClass(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void testTransactional() {
+        TransactionalClassPC pc = new TransactionalClassPC();
+        pc.setIntField(1);
+
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+        //pm.makeTransactional (pc);
+        pc.setIntField(2);
+        endTx(pm);
+
+        assertEquals(2, pc.getIntField());
+
+        startTx(pm);
+        pc.setIntField(3);
+        pm.getTransaction().rollback();
+
+        assertEquals(3, pc.getIntField());
+        endEm(pm);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactions.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactions.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactions.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestEJBTransactions.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,119 @@
+/*
+ * 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.ArrayList;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+public class TestEJBTransactions extends AbstractTestCase {
+
+    public TestEJBTransactions(String name) {
+        super(name, "kernelcactusapp");
+    }
+
+    public void setUp() {
+    }
+
+    public void testTxCannotBeCommittedTwiceInDiffThreads() throws Throwable {
+        final ArrayList list = new ArrayList();
+
+        final EntityManager em = currentEntityManager();
+        final EntityTransaction tx;
+
+        tx = em.getTransaction();
+        if (tx.isActive())
+            tx.rollback();
+        tx.begin();
+        endTx(em);
+
+        Thread thread = new Thread() {
+            @SuppressWarnings("unchecked")
+            public void run() {
+                try {
+                    endTx(em);
+                    list.add(new Integer(0));
+                }
+                catch (Exception e) {
+                    list.add(e);
+                }
+                catch (Throwable t) {
+                    list.add(t);
+                }
+            }
+        };
+
+        thread.start();
+
+        while (list.size() == 0) ;
+
+        Object result = list.get(0);
+
+        if (!(result instanceof Exception)) {
+            if (result instanceof Throwable)
+                throw (Throwable) result;
+        }
+        thread.join();
+    }
+
+    public void testTransactionsCannotBeCommittedTwice() {
+        EntityManager pm = currentEntityManager();
+        rollbackTx(pm);
+
+        startTx(pm);
+        endTx(pm);
+
+        try {
+            // second commit
+            endTx(pm);
+        }
+        catch (Exception e) {
+            // good: we should be throwing an exception here
+            System.out.println("Exception should be thrown here..." +
+                "Transactions cannot be committed twice...");
+        }
+    }
+
+    public void testTransactionsCannotBeRolledBackTwice() {
+        EntityManager pm = currentEntityManager();
+        startTx(pm);
+
+        EntityTransaction t;
+        t = pm.getTransaction();
+
+        if (t.isActive()) {
+            t.rollback();
+        } else {
+            t.begin();
+            t.rollback();
+        }
+
+        try {
+            // second rollback
+            t.rollback();
+        }
+        catch (Exception e) {
+            // good: we should be throwing an exception here
+            System.out.println("Exception should be thrown here..." +
+                "Transactions cannot be rolled back twice...");
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,125 @@
+/*
+ * TestExtents.java
+ *
+ * Created on October 10, 2006, 4:34 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.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2;
+
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestExtents extends BaseKernelTest {
+
+    /**
+     * Creates a new instance of TestExtents
+     */
+    public TestExtents() {
+    }
+
+    public TestExtents(String name) {
+        super(name);
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+
+        RuntimeTest1 b = new RuntimeTest1("STRING", 10);
+        RuntimeTest2 c = new RuntimeTest2("STRING2", 11);
+        pm.persist(b);
+        pm.persist(c);
+
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testExtent1() {
+
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest1.class, false);
+
+        assertEquals(pm, ext.getEntityManager());
+
+        assertEquals(RuntimeTest1.class, ext.getElementClass());
+        assertTrue(!ext.hasSubclasses());
+    }
+
+    public void testExtent2() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest1.class, false);
+
+        boolean found = false;
+        for (Iterator i = ext.iterator(); i.hasNext(); found = true)
+            assertEquals(RuntimeTest1.class, i.next().getClass());
+        assertTrue(found);
+    }
+
+    public void testExtent3() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest1.class, true);
+
+        boolean foundB = false;
+        for (Iterator i = ext.iterator(); i.hasNext();)
+            if (i.next().getClass().equals(RuntimeTest2.class))
+                foundB = true;
+        assertTrue(foundB);
+    }
+
+    public void testExtent4() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = (Extent) pm.createExtent(RuntimeTest1.class, true);
+
+        List all = new LinkedList();
+        for (Iterator i = ext.iterator(); i.hasNext();)
+            all.add(i.next());
+
+        List aList = ext.list();
+        assertEquals(all.size(), aList.size());
+        assertContainsSame(all, aList);
+    }
+
+    private void assertContainsSame(List l, Collection c) {
+        int size = 0;
+        for (Iterator iter = c.iterator(); iter.hasNext(); iter.next())
+            size++;
+
+        assertEquals(l.size(), size);
+
+        for (Iterator iter = l.iterator(); iter.hasNext();)
+            assertTrue(c.contains(iter.next()));
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestExtents2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,199 @@
+/*
+ * TestExtents2.java
+ *
+ * Created on October 10, 2006, 5:30 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.Iterator;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2;
+import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3;
+
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestExtents2 extends BaseKernelTest {
+
+    private Object _oid1 = null;
+    private Object _oid2 = null;
+    private Object _oid3 = null;
+
+    public TestExtents2(String name) {
+        super(name);
+    }
+
+    /**
+     * Creates a new instance of TestExtents2
+     */
+    public TestExtents2() {
+    }
+
+    public void setUp() {
+        deleteAll(RuntimeTest1.class);
+
+        RuntimeTest1 test1 = new RuntimeTest1();
+        test1.setIntField(1);
+        RuntimeTest2 test2 = new RuntimeTest2();
+        test2.setIntField(2);
+        test2.setIntField2(2);
+        RuntimeTest3 test3 = new RuntimeTest3();
+        test3.setIntField(3);
+        test3.setIntField3(3);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+        pm.persist(test1);
+        pm.persist(test2);
+        pm.persist(test3);
+        _oid1 = pm.getObjectId(test1);
+        _oid2 = pm.getObjectId(test2);
+        _oid3 = pm.getObjectId(test3);
+        endTx(pm);
+        endEm(pm);
+    }
+
+    public void testProperties() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest2.class, false);
+        assertEquals(pm, ext.getEntityManager());
+        assertEquals(RuntimeTest2.class, ext.getElementClass());
+        assertTrue(!ext.hasSubclasses());
+
+        ext = pm.createExtent(RuntimeTest1.class, true);
+        assertEquals(pm, ext.getEntityManager());
+        assertEquals(RuntimeTest1.class, ext.getElementClass());
+        assertTrue(ext.hasSubclasses());
+    }
+
+    public void testNoSubclasses() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest1.class, false);
+        Iterator itr = ext.iterator();
+        assertTrue(itr.hasNext());
+        assertEquals(_oid1, pm.getObjectId(itr.next()));
+        assertTrue(!itr.hasNext());
+        ext.closeAll();
+    }
+
+    public void testSubclasses() {
+        OpenJPAEntityManager pm = getPM();
+        Extent ext = pm.createExtent(RuntimeTest1.class, true);
+
+        int test1Count = 0;
+        int test2Count = 0;
+        int test3Count = 0;
+        Object next;
+        for (Iterator itr = ext.iterator(); itr.hasNext();) {
+            next = pm.getObjectId(itr.next());
+            if (_oid1.equals(next))
+                test1Count++;
+            else if (_oid2.equals(next))
+                test2Count++;
+            else if (_oid3.equals(next))
+                test3Count++;
+        }
+        ext.closeAll();
+        assertEquals(1, test1Count);
+        assertEquals(1, test2Count);
+        assertEquals(1, test3Count);
+    }
+
+    public void testContainsNewlyPersisted() {
+        RuntimeTest1 test1 = new RuntimeTest1();
+        RuntimeTest1 test2 = new RuntimeTest2();
+
+        OpenJPAEntityManager pm = getPM();
+
+        // pcl: 14 Oct 2003: default in 3.0 is now true, but this test
+        // assumes false somewhere.
+
+        pm.setIgnoreChanges(false);
+        startTx(pm);
+        try {
+            pm.persist(test1);
+            pm.persist(test2);
+            Object newOid = pm.getObjectId(test1);
+
+            Extent ext = pm.createExtent(RuntimeTest1.class, false);
+            boolean foundOid1 = false;
+            boolean foundNew = false;
+            Object next;
+            for (Iterator itr = ext.iterator(); itr.hasNext();) {
+                next = pm.getObjectId(itr.next());
+                if (_oid1.equals(next))
+                    foundOid1 = true;
+                else if (newOid.equals(next))
+                    foundNew = true;
+                else
+                    fail("Bad object in extent.");
+            }
+            ext.closeAll();
+            assertTrue(foundOid1);
+            assertTrue(foundNew);
+        } finally {
+            rollbackTx(pm);
+        }
+    }
+
+    public void testNotContainsNewlyDeleted() {
+        OpenJPAEntityManager pm = getPM();
+
+        // pcl: 14 Oct 2003: default in 3.0 is now true, but this test
+        // assumes false somewhere.
+        pm.setIgnoreChanges(false);
+        startTx(pm);
+        try {
+            RuntimeTest2 test2 =
+                (RuntimeTest2) pm.find(RuntimeTest2.class, _oid2);
+            pm.remove(test2);
+            RuntimeTest1 test1 = new RuntimeTest1();
+            pm.persist(test1);
+            pm.remove(test1);
+
+            Extent ext = pm.createExtent(RuntimeTest1.class, true);
+            boolean foundOid1 = false;
+            boolean foundOid3 = false;
+            Object next;
+            for (Iterator itr = ext.iterator(); itr.hasNext();) {
+                next = pm.getObjectId(itr.next());
+                if (_oid1.equals(next))
+                    foundOid1 = true;
+                else if (_oid3.equals(next))
+                    foundOid3 = true;
+                else
+                    fail("Bad object in extent.");
+            }
+            ext.closeAll();
+            assertTrue(foundOid1);
+            assertTrue(foundOid3);
+        } finally {
+            rollbackTx(pm);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroups.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroups.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroups.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroups.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,403 @@
+/*
+ * TestFetchGroups.java
+ *
+ * Created on October 10, 2006, 5:46 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.Arrays;
+import java.util.BitSet;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.AttachA;
+import org.apache.openjpa.persistence.kernel.common.apps.AttachB;
+import org.apache.openjpa.persistence.kernel.common.apps.AttachC;
+import org.apache.openjpa.persistence.kernel.common.apps.AttachD;
+import org.apache.openjpa.persistence.kernel.common.apps.AttachE;
+import org.apache.openjpa.persistence.kernel.common.apps.AttachF;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchGroupTestObject;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchGroupTestObjectChild;
+
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+
+public class TestFetchGroups extends BaseKernelTest {
+
+    private int oid1;
+    private int oid2;
+    private int oidc1;
+
+    public TestFetchGroups(String s) {
+        super(s);
+    }
+
+    /**
+     * Creates a new instance of TestFetchGroups
+     */
+    public TestFetchGroups() {
+    }
+
+    public void setUp() {
+        deleteAll(FetchGroupTestObject.class);
+
+        FetchGroupTestObject o1 = new FetchGroupTestObject();
+        // the value that 'a' is set to is important -- TestFetchGroupsExtent
+        // and TestFetchGroupsQuery rely on this
+        o1.setA(5);
+        o1.setB("foo");
+        //o1.setC (new BigInteger (89));
+        o1.setD(new Date());
+        o1.setE("e-foo");
+        o1.setF("f-foo");
+
+        FetchGroupTestObject o2 = new FetchGroupTestObject();
+        // the value that 'a' is set to is important -- TestFetchGroupsExtent
+        // and TestFetchGroupsQuery rely on this
+        o2.setA(3);
+        o2.setB("bar");
+        //o2.setC (new BigInteger (13));
+        o2.setD(new Date());
+        o2.setE("e-bar");
+        o2.setF("f-bar");
+        o2.setG(o1);
+        o2.setH(o1);
+
+        FetchGroupTestObjectChild c1 = new FetchGroupTestObjectChild();
+        // the value that 'a' is set to is important -- TestFetchGroupsExtent
+        // and TestFetchGroupsQuery rely on this
+        c1.setA(4);
+        c1.setB("child");
+        c1.setD(new Date());
+        c1.setE("e-baz");
+        c1.setF("f-baz");
+        c1.setG(o1);
+        c1.setH(o1);
+        c1.setChildA(1);
+        c1.setChildB(2);
+        c1.setChildC(3);
+        c1.setChildD(4);
+
+        OpenJPAEntityManager pm = getPM();
+        startTx(pm);
+
+        pm.persist(o1);
+        pm.persist(o2);
+        pm.persist(c1);
+        endTx(pm);
+
+        oid1 = o1.getId();
+        oid2 = o2.getId();
+        oidc1 = c1.getId();
+
+        endEm(pm);
+    }
+
+    public void testFetchGroupsFromConfiguration() {
+        Map props = new HashMap();
+        props.put("openjpa.FetchGroups", "default,fg1,fg2");
+        OpenJPAEntityManagerFactory factory = getEmf(props);
+
+        OpenJPAEntityManager pm =
+            (OpenJPAEntityManager) factory.createEntityManager();
+        checkGroups(pm, new String[]{ "fg1", "fg2" });
+        factory.close();
+    }
+
+    public void testFetchGroupsNoConfiguration() {
+        OpenJPAEntityManager pm = getPM();
+
+        FetchGroupTestObject o1 = getO1(pm);
+        FetchGroupTestObject o2 = getO2(pm);
+
+        // only field a should be loaded.
+        checkObject(pm, o1, true, false, false, false, false, false);
+
+        // upon loading field b, fields c and d should also be loaded,
+        // but e and f should not.
+        o1.getB();
+        checkObject(pm, o1, true, true, true, true, false, false);
+
+        // loading field h should not cause any of the others to be loaded.
+        assertEquals(o1, o2.getH());
+        checkObject(pm, o2, true, false, false, false, false, false);
+
+        // loading field g should cause e and f to be loaded.
+        assertEquals(o1, o2.getG());
+        checkObject(pm, o2, true, false, false, false, true, true);
+    }
+
+    public void testRetrieveAll() {
+        OpenJPAEntityManager pm = getPM();
+
+        FetchGroupTestObject o1 = getO1(pm);
+        FetchGroupTestObject o2 = getO2(pm);
+
+        // only field a should be loaded.
+        checkObject(pm, o1, true, false, false, false, false, false);
+        checkObject(pm, o2, true, false, false, false, false, false);
+
+        // only field a should be loaded.
+        pm.retrieve(o1);
+        checkObject(pm, o1, true, false, false, false, false, false);
+
+        // Add groups 1 and 3 to the default fetch configuration.
+        pm.getFetchPlan().addFetchGroup("g1");
+        pm.getFetchPlan().addFetchGroup("g3");
+
+        // Retrieve o1's "DFG" which will actually do all configured
+        // fetch groups.
+        // DFG fields and fields in groups 1 and 3 should be loaded
+        pm.retrieve(o1);
+        checkObject(pm, o1, true, true, true, true, false, false);
+    }
+
+    public void testFetchGroupConfiguration() {
+        OpenJPAEntityManager pm = getPM();
+        FetchPlan fetch = pm.getFetchPlan();
+
+        checkGroups(pm, new String[0]);
+
+        fetch.addFetchGroup("foo");
+        checkGroups(pm, new String[]{ "foo" });
+
+        fetch.addFetchGroup("bar");
+        fetch.addFetchGroup("baz");
+        checkGroups(pm, new String[]{ "foo", "bar", "baz" });
+
+        fetch.addFetchGroup("a");
+        fetch.addFetchGroup("b");
+        fetch.addFetchGroup("c");
+        fetch.addFetchGroup("d");
+        checkGroups(pm, new String[]
+            { "foo", "bar", "baz", "a", "b", "c", "d" });
+
+        fetch.removeFetchGroup("bar");
+        checkGroups(pm, new String[]{ "foo", "baz", "a", "b", "c", "d" });
+
+        fetch.removeFetchGroup("baz");
+        fetch.removeFetchGroup("c");
+        checkGroups(pm, new String[]{ "foo", "a", "b", "d" });
+
+        fetch.clearFetchGroups().addFetchGroup(FetchPlan.GROUP_DEFAULT);
+        checkGroups(pm, new String[0]);
+    }
+
+    private void checkGroups(OpenJPAEntityManager pm, String[] groups) {
+        HashSet groupSet = new HashSet(Arrays.asList(groups));
+        groupSet.add(FetchPlan.GROUP_DEFAULT);
+        assertEquals("groupSet dont match", groupSet,
+            new HashSet(pm.getFetchPlan().getFetchGroups()));
+    }
+
+    public void testFetchGroupsChildWithConfiguration() {
+        OpenJPAEntityManager pm = getPM();
+        pm.getFetchPlan().addFetchGroup("g1");
+        pm.getFetchPlan().addFetchGroup("g3");
+
+        // get this so that h's value is loaded into cache.
+        FetchGroupTestObject o1 = getO1(pm);
+
+        FetchGroupTestObjectChild c1 = getC1(pm);
+
+        // DFG fields and fields in groups 1 and 3 should be loaded
+        checkChildObject(pm, c1, true, true, true, true, false, false,
+            true, true, false, true);
+
+        // upon accessing field b, nothing should change.
+        c1.getB();
+        checkChildObject(pm, c1, true, true, true, true, false, false,
+            true, true, false, true);
+
+        c1.getH();
+    }
+
+    public void testFetchGroupsWithConfiguration() {
+        OpenJPAEntityManager pm = getPM();
+
+        pm.getFetchPlan().addFetchGroup("g1");
+        pm.getFetchPlan().addFetchGroup("g3");
+
+        FetchGroupTestObject o1 = getO1(pm);
+        FetchGroupTestObject o2 = getO2(pm);
+
+        // DFG fields and fields in groups 1 and 3 should be loaded
+        checkObject(pm, o1, true, true, true, true, false, false);
+
+        // upon accessing field b, nothing should change.
+        o1.getB();
+        checkObject(pm, o1, true, true, true, true, false, false);
+
+        // loading field h should not cause any of the others to be loaded.
+        assertEquals(o1, o2.getH());
+        checkObject(pm, o2, true, true, true, true, false, false);
+
+        // loading field g should cause e and f to be loaded.
+        assertEquals(o1, o2.getG());
+        checkObject(pm, o2, true, true, true, true, true, true);
+    }
+
+    /**
+     * Tests that relation fields are loaded immediately when
+     * they are in one of the PM's configured fetch groups.
+     */
+    public void testRelationsLoaded() {
+        OpenJPAEntityManager pm = getPM();
+        pm.getFetchPlan().addFetchGroup("g2");
+
+        // note: important the o1 is *not* in pm's cache at this point, so that
+        // we know it takes another datastore trip to get o1
+
+        // load o2 and retrieve its state manager
+        OpenJPAStateManager sm = getStateManager(getO2(pm), pm);
+        assertNotNull("SM is NULL", sm);
+
+        // 'g' is the name of a 1-1 relation field to o1 in configured
+        // fetch group 'g2'; make sure it is loaded
+        int field = sm.getMetaData().getField("g").getIndex();
+        try {
+            assertTrue(sm.getLoaded().get(field));
+            assertEquals(oid1,
+                ((FetchGroupTestObject) sm.fetchObjectField(field)).getId());
+        } catch (junit.framework.AssertionFailedError afe) {
+            bug(623, afe, "One to one mappings do not work with custom "
+                + "fetch groups");
+        }
+    }
+
+    protected void checkObject(OpenJPAEntityManager pm,
+        FetchGroupTestObject o, boolean a, boolean b,
+        boolean c, boolean d, boolean e, boolean f) {
+        OpenJPAStateManager sm = getStateManager(o, pm);
+        BitSet loaded = sm.getLoaded();
+
+        FieldMetaData[] fmds = sm.getMetaData().getFields();
+        int i = 0;
+        for (; i < fmds.length; i++) {
+            if (fmds[i].getName().equals("a"))
+                assertEquals(a, loaded.get(i));
+            else if (fmds[i].getName().equals("b"))
+                assertEquals(b, loaded.get(i));
+            else if (fmds[i].getName().equals("c"))
+                assertEquals(c, loaded.get(i));
+            else if (fmds[i].getName().equals("d"))
+                assertEquals(d, loaded.get(i));
+            else if (fmds[i].getName().equals("e"))
+                assertEquals(e, loaded.get(i));
+            else if (fmds[i].getName().equals("f"))
+                assertEquals(f, loaded.get(i));
+        }
+    }
+
+    protected void checkChildObject(OpenJPAEntityManager pm,
+        FetchGroupTestObjectChild o, boolean a, boolean b,
+        boolean c, boolean d, boolean e, boolean f, boolean childA,
+        boolean childB, boolean childC, boolean childD) {
+        checkObject(pm, o, a, b, c, d, e, f);
+
+        OpenJPAStateManager sm = getStateManager(o, pm);
+        BitSet loaded = sm.getLoaded();
+
+        FieldMetaData[] fmds = sm.getMetaData().getFields();
+        int i = 0;
+        for (; i < fmds.length; i++) {
+            if (fmds[i].getName().equals("childA"))
+                assertEquals(childA, loaded.get(i));
+            else if (fmds[i].getName().equals("childB"))
+                assertEquals(childB, loaded.get(i));
+            else if (fmds[i].getName().equals("childC"))
+                assertEquals(childC, loaded.get(i));
+            else if (fmds[i].getName().equals("childD"))
+                assertEquals(childD, loaded.get(i));
+        }
+    }
+
+    protected FetchGroupTestObject getO1(OpenJPAEntityManager pm) {
+        return pm.find(FetchGroupTestObject.class, oid1);
+    }
+
+    protected FetchGroupTestObject getO2(OpenJPAEntityManager pm) {
+        return pm.find(FetchGroupTestObject.class, oid2);
+    }
+
+    protected FetchGroupTestObjectChild getC1(OpenJPAEntityManager pm) {
+        return pm.find(FetchGroupTestObjectChild.class, oidc1);
+    }
+
+    /**
+     * Tests that named fetch groups actually bring in the
+     * managed object.
+     */
+    public void testFetchGroupInstantiated() {
+        deleteAll(AttachA.class);
+        deleteAll(AttachB.class);
+        deleteAll(AttachC.class);
+        deleteAll(AttachD.class);
+        deleteAll(AttachE.class);
+        deleteAll(AttachF.class);
+
+        OpenJPAEntityManager pm;
+
+        pm = getPM();
+        startTx(pm);
+        AttachE e = new AttachE();
+        AttachB b = new AttachB();
+        e.setB(b);
+        pm.persist(e);
+
+        endTx(pm);
+        endEm(pm);
+
+        Object ob;
+
+        pm = getPM();
+        startTx(pm);
+        assertSize(0, pm.getManagedObjects());
+        ob = pm.createExtent(AttachE.class, true).iterator().next();
+        // make sure relation is not loaded
+        assertSize(1, pm.getManagedObjects());
+        rollbackTx(pm);
+        endEm(pm);
+
+        pm = getPM();
+        startTx(pm);
+        // now make sure we load relations
+        pm.getFetchPlan().addFetchGroup("all");
+        assertSize(0, pm.getManagedObjects());
+        ob = pm.createExtent(AttachE.class, true).iterator().next();
+        // make sure relation is loaded
+        assertSize(2, pm.getManagedObjects());
+        rollbackTx(pm);
+        endEm(pm);
+    }
+}
+ 
\ No newline at end of file

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsExtent.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsExtent.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsExtent.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsExtent.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,91 @@
+/*
+ * TestFetchGroupsExtent.java
+ *
+ * Created on October 12, 2006, 9:54 AM
+ *
+ * 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.Collection;
+import java.util.List;
+
+
+
+import org.apache.openjpa.persistence.kernel.common.apps.FetchGroupTestObject;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchGroupTestObjectChild;
+
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestFetchGroupsExtent extends TestFetchGroups {
+
+    /**
+     * Creates a new instance of TestFetchGroupsExtent
+     */
+    public TestFetchGroupsExtent() {
+    }
+
+    public TestFetchGroupsExtent(String s) {
+        super(s);
+    }
+
+    protected FetchGroupTestObject getO1(OpenJPAEntityManager pm) {
+        Extent e = (Extent) pm.createExtent(FetchGroupTestObject.class,
+            true);
+        List l = e.list();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObject o WHERE o.a = 5");
+        q.setCandidateCollection(l);
+
+        return (FetchGroupTestObject)
+            ((Collection) q.getResultList()).iterator().next();
+    }
+
+    protected FetchGroupTestObject getO2(OpenJPAEntityManager pm) {
+        Extent e = (Extent) pm.createExtent(FetchGroupTestObject.class,
+            true);
+        List l = e.list();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObject o WHERE o.a = 3");
+        q.setCandidateCollection(l);
+
+        return (FetchGroupTestObject)
+            ((Collection) q.getResultList()).iterator().next();
+    }
+
+    protected FetchGroupTestObjectChild getC1(OpenJPAEntityManager pm) {
+        Extent e = (Extent) pm.createExtent(FetchGroupTestObject.class,
+            true);
+        List l = e.list();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObjectChild o WHERE o.a = 4");
+        q.setCandidateCollection(l);
+
+        return (FetchGroupTestObjectChild)
+            ((Collection) q.getResultList()).iterator().next();
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsQuery.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsQuery.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsQuery.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestFetchGroupsQuery.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,87 @@
+/*
+ * TestFetchGroupsQuery.java
+ *
+ * Created on October 12, 2006, 10:09 AM
+ *
+ * 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.FetchGroupTestObject;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchGroupTestObjectChild;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+public class TestFetchGroupsQuery extends TestFetchGroups {
+
+    /**
+     * Creates a new instance of TestFetchGroupsQuery
+     */
+    public TestFetchGroupsQuery() {
+    }
+
+    public TestFetchGroupsQuery(String s) {
+        super(s);
+    }
+
+    protected FetchGroupTestObject getO1(OpenJPAEntityManager pm) {
+//        OpenJPAQuery q = pm.createNativeQuery("a == 5",FetchGroupTestObject.class);
+//        return (FetchGroupTestObject)
+//        ((Collection) q.getResultList()).iterator().next();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObject o WHERE o.a = 5");
+        List l = q.getResultList();
+
+        return (FetchGroupTestObject) (l.iterator().next());
+    }
+
+    protected FetchGroupTestObject getO2(OpenJPAEntityManager pm) {
+//        OpenJPAQuery q = pm.createNativeQuery("a == 3",FetchGroupTestObject.class);
+//        return (FetchGroupTestObject)
+//        ((Collection) q.getResultList()).iterator().next();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObject o WHERE o.a = 3");
+        List l = q.getResultList();
+
+        return (FetchGroupTestObject) (l.iterator().next());
+    }
+
+    protected FetchGroupTestObjectChild getC1(OpenJPAEntityManager pm) {
+//        OpenJPAQuery q = pm.createNativeQuery("a == 4",FetchGroupTestObjectChild.class);
+//        return (FetchGroupTestObjectChild)
+//        ((Collection) q.getResultList()).iterator().next();
+
+        OpenJPAQuery q = pm.createQuery(
+            "SELECT o FROM FetchGroupTestObjectChild o WHERE o.a = 4");
+        List l = q.getResultList();
+
+        return (FetchGroupTestObjectChild) (l.iterator().next());
+    }
+}



Mime
View raw message