openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [21/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/jdbc/meta/TestLocators.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLocators.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLocators.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestLocators.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,229 @@
+/*
+ * TestLocators.java
+ *
+ * Created on October 3, 2006, 4:37 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.OracleDictionary;
+import org.apache.openjpa.persistence.Extent;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+
+public class TestLocators extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+    private OpenJPAEntityManagerFactory pmf;
+
+    public TestLocators(String name) {
+        super(name);
+    }    
+    
+    /** Creates a new instance of TestLocators */
+    public TestLocators() {
+    }
+    public void setUp() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        
+        Extent e = pm.createExtent(LocatorTestObject.class, true);
+        for (Iterator i = e.iterator(); i.hasNext();) {
+            pm.remove(i.next());
+            
+        }
+        endTx(pm);
+        pm.close();
+    }
+
+    public void tearDown()
+        throws Exception {
+        super.tearDown();
+
+       deleteAll(LocatorTestObject.class);
+    }
+
+    public void testBLOBs() {
+        doBlobTest(50000);
+    }
+
+    public void testSmallBLOBs() {
+        doBlobTest(50);
+
+        if (getCurrentPlatform() == AbstractTestCase.Platform.ORACLE) {
+            OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+            JDBCConfiguration conf = (JDBCConfiguration)
+                ((OpenJPAEntityManagerSPI) pm).getConfiguration();
+            OracleDictionary dict = (OracleDictionary)
+                conf.getDBDictionaryInstance();
+
+            int t = dict.maxEmbeddedBlobSize;
+            doBlobTest(t - 1);
+            doBlobTest(t);
+            doBlobTest(t + 1);
+        }
+    }
+
+    public void doBlobTest(int size) {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        LocatorTestObject o = new LocatorTestObject();
+        byte[] bytes = new byte[size];
+        Arrays.fill(bytes, (byte) 'b');
+        o.setBytes(bytes);
+        pm.persist(o);
+        Object oid = pm.getObjectId(o);
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+        byte[] newbytes = o.getBytes();
+        assertNotNull(newbytes);
+        assertEquals(bytes.length, newbytes.length);
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals(bytes[i], newbytes[i]);
+        }
+    }
+
+    public void testShrinkBLOB() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        LocatorTestObject o = new LocatorTestObject();
+        byte[] bytes = new byte[50000];
+        Arrays.fill(bytes, (byte) 'b');
+        o.setBytes(bytes);
+        pm.persist(o);
+        Object oid = pm.getObjectId(o);
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+
+        startTx(pm);
+        bytes = new byte[40000];
+        Arrays.fill(bytes, (byte) 'c');
+        o.setBytes(bytes);
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+        byte[] newbytes = o.getBytes();
+        assertEquals(bytes.length, newbytes.length);
+        for (int i = 0; i < bytes.length; i++) {
+            assertEquals(bytes[i], newbytes[i]);
+        }
+    }
+
+    public void testCLOBs() {
+        doClobTest(50000);
+    }
+
+    public void testSmallCLOBs() {
+        doClobTest(50);
+
+        if (getCurrentPlatform() == AbstractTestCase.Platform.ORACLE) {
+            OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+            JDBCConfiguration conf = (JDBCConfiguration)
+                ((OpenJPAEntityManagerSPI) pm).getConfiguration();
+            OracleDictionary dict = (OracleDictionary)
+                conf.getDBDictionaryInstance();
+
+            int t = dict.maxEmbeddedClobSize;
+            doClobTest(t - 1);
+            doClobTest(t);
+            doClobTest(t + 1);
+        }
+    }
+
+    public void doClobTest(int size) {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        LocatorTestObject o = new LocatorTestObject();
+        char[] chars = new char[size];
+        Arrays.fill(chars, (char) 'c');
+        o.setClobString(new String(chars));
+        pm.persist(o);
+        Object oid = pm.getObjectId(o);
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+        char[] newchars = o.getClobString().toCharArray();
+
+        assertNotNull(newchars);
+        assertEquals(chars.length, newchars.length);
+        for (int i = 0; i < chars.length; i++) {
+            assertEquals(chars[i], newchars[i]);
+        }
+    }
+
+    public void testShrinkCLOB() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);
+        LocatorTestObject o = new LocatorTestObject();
+        char[] chars = new char[50000];
+        Arrays.fill(chars, (char) 'c');
+        o.setClobString(new String(chars));
+        pm.persist(o);
+        Object oid = pm.getObjectId(o);
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+
+        startTx(pm);
+        chars = new char[40000];
+        Arrays.fill(chars, (char) 'd');
+        o.setClobString(new String(chars));
+        endTx(pm);
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        o = (LocatorTestObject) pm.getObjectId(oid);
+        char[] newchars = o.getClobString().toCharArray();
+        assertEquals(chars.length, newchars.length);
+        for (int i = 0; i < chars.length; i++) {
+            assertEquals(chars[i], newchars[i]);
+        }
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMappedByKeyMaps.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMappedByKeyMaps.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMappedByKeyMaps.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMappedByKeyMaps.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,268 @@
+/*
+ * TestMappedByKeyMaps.java
+ *
+ * Created on October 4, 2006, 9:26 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.strats.RelationMapInverseKeyFieldStrategy;
+import org.apache.openjpa.jdbc.meta.strats.RelationMapTableFieldStrategy;
+import org.apache.openjpa.util.AbstractLRSProxyMap;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+
+public class TestMappedByKeyMaps extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{
+    
+    /** Creates a new instance of TestMappedByKeyMaps */
+    public TestMappedByKeyMaps(String name) 
+    {
+    	super(name);
+    }
+    
+    public void testInverseKeyMapMapping() {
+        JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
+        ClassMapping pc = conf.getMappingRepositoryInstance().getMapping
+                (InverseKeyMapPC.class, null, true);
+        FieldMapping map = pc.getFieldMapping("helpers");
+        
+        ClassMapping helper = conf.getMappingRepositoryInstance().getMapping
+                (HelperPC.class, null, true);
+        FieldMapping str = helper.getFieldMapping("stringField");
+        
+        assertEquals("stringField", map.getKey().getValueMappedBy());
+        assertEquals(str, map.getKey().getValueMappedByMetaData());
+        assertTrue(map.getStrategy() instanceof
+                RelationMapInverseKeyFieldStrategy);
+        assertEquals(1, map.getKeyMapping().getColumns().length);
+        assertEquals(map.getKeyMapping().getColumns()[0],
+                str.getColumns()[0]);
+    }
+    
+    public void testJoinTableMapMapping() {
+        JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
+        ClassMapping pc = conf.getMappingRepositoryInstance().getMapping
+                (JoinTableMapPC.class, null, true);
+        FieldMapping map = pc.getFieldMapping("helpers");
+        
+        ClassMapping helper = conf.getMappingRepositoryInstance().getMapping
+                (HelperPC.class, null, true);
+        FieldMapping str = helper.getFieldMapping("stringField");
+        
+        assertEquals("stringField", map.getKey().getValueMappedBy());
+        assertEquals(str, map.getKey().getValueMappedByMetaData());
+        assertTrue(map.getStrategy() instanceof RelationMapTableFieldStrategy);
+        assertEquals(1, map.getKeyMapping().getColumns().length);
+        assertEquals(map.getKeyMapping().getColumns()[0],
+                str.getColumns()[0]);
+    }
+    
+    public void testInverseKeyMap() {
+        mappedByMap(new InverseKeyMapPC(), false);
+        queryMap(new InverseKeyMapPC());
+    }
+    
+    public void testInverseKeyLRSMap() {
+        mappedByMap(new InverseKeyMapPC(), true);
+    }
+    
+    public void testJoinTableMap() {
+        mappedByMap(new JoinTableMapPC(), false);
+        queryMap(new JoinTableMapPC());
+    }
+    
+    public void testJoinTableLRSMap() {
+        mappedByMap(new JoinTableMapPC(), true);
+    }
+    
+    private void mappedByMap(MappedByMapPC pc, boolean lrs) {
+       deleteAll(HelperPC.class);
+       deleteAll(pc.getClass());
+        
+        HelperPC h1 = new HelperPC();
+        h1.setStringField("h1");
+        pc.getHelpers().put(h1.getStringField(), h1);
+        HelperPC h2 = new HelperPC();
+        h2.setStringField("h2");
+        pc.getHelpers().put(h2.getStringField(), h2);
+        HelperPC h3 = new HelperPC();
+        h3.setStringField("h3");
+        pc.getHelpers().put(h3.getStringField(), h3);
+        
+        setLRS(pc.getClass(), lrs);
+        try {
+            OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+            startTx(pm);;
+            pm.persist(pc);
+            endTx(pm);;
+            Object oid = pm.getObjectId(pc);
+            
+            assertFalse(pc.getHelpers().containsKey("foo"));
+            assertNull(pc.getHelpers().get("foo"));
+            assertEquals(3, pc.getHelpers().size());
+            assertEquals(h1, pc.getHelpers().get("h1"));
+            assertEquals(h2, pc.getHelpers().get("h2"));
+            pm.close();
+            
+            pm = (OpenJPAEntityManager)currentEntityManager();;
+            pc = (MappedByMapPC) pm.getObjectId(oid);
+            if (lrs)
+                assertTrue(pc.getHelpers() instanceof AbstractLRSProxyMap);
+            assertEquals(3, pc.getHelpers().size());
+            assertFalse(pc.getHelpers().containsKey("foo"));
+            assertNull(pc.getHelpers().get("foo"));
+            assertEquals("h1", ((HelperPC) pc.getHelpers().get("h1")).
+                    getStringField());
+            assertEquals("h2", ((HelperPC) pc.getHelpers().get("h2")).
+                    getStringField());
+            
+            pm.begin();
+            pc.getHelpers().remove("h1");
+            assertEquals(2, pc.getHelpers().size());
+            assertFalse(pc.getHelpers().containsKey("h1"));
+            assertNull(pc.getHelpers().get("h1"));
+            HelperPC h4 = new HelperPC();
+            h4.setStringField("h4");
+            pc.getHelpers().put("h4", h4);
+            assertTrue(pc.getHelpers().containsKey("h4"));
+            assertEquals(h4, pc.getHelpers().get("h4"));
+            assertEquals(3, pc.getHelpers().size());
+            pm.commit();
+            assertEquals(3, pc.getHelpers().size());
+            assertFalse(pc.getHelpers().containsKey("h1"));
+            assertNull(pc.getHelpers().get("h1"));
+            assertEquals("h2", ((HelperPC) pc.getHelpers().get("h2")).
+                    getStringField());
+            assertEquals("h4", ((HelperPC) pc.getHelpers().get("h4")).
+                    getStringField());
+            pm.close();
+            
+            pm = (OpenJPAEntityManager)currentEntityManager();;
+            pc = (MappedByMapPC) pm.getObjectId(oid);
+            assertEquals(3, pc.getHelpers().size());
+            assertFalse(pc.getHelpers().containsKey("h1"));
+            assertNull(pc.getHelpers().get("h1"));
+            assertEquals("h2", ((HelperPC) pc.getHelpers().get("h2")).
+                    getStringField());
+            assertEquals("h4", ((HelperPC) pc.getHelpers().get("h4")).
+                    getStringField());
+            
+            // to test lrs functions
+            assertTrue(pc.getHelpers().containsValue
+                    (pc.getHelpers().get("h2")));
+            
+            Set keySet = pc.getHelpers().keySet();
+            Set ordered = new TreeSet();
+            assertEquals(3, keySet.size());
+            Iterator itr = keySet.iterator();
+            while (itr.hasNext())
+                ordered.add(itr.next());
+            //FIXME jthomas
+            //KodoJDOHelper.close(itr);
+            assertEquals(3, ordered.size());
+            assertTrue(ordered.contains("h2"));
+            assertTrue(ordered.contains("h3"));
+            assertTrue(ordered.contains("h4"));
+            ordered.clear();
+            
+            Collection values = pc.getHelpers().values();
+            assertEquals(3, values.size());
+            itr = values.iterator();
+            while (itr.hasNext()) {
+                Object next = itr.next();
+                assertTrue(next instanceof HelperPC);
+                ordered.add(((HelperPC) next).getStringField());
+            }
+            //FIXME jthomas
+            //KodoJDOHelper.close(itr);
+            assertEquals(3, ordered.size());
+            assertTrue(ordered.contains("h2"));
+            assertTrue(ordered.contains("h3"));
+            assertTrue(ordered.contains("h4"));
+            pm.close();
+        } finally {
+            unsetLRS(pc.getClass());
+        }
+    }
+    
+    private void queryMap(MappedByMapPC pc) {
+        HelperPC h5 = new HelperPC();
+        h5.setStringField("h5");
+        pc.getHelpers().put("h5", h5);
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.begin();
+        pm.persist(pc);
+        pm.commit();
+        pm.close();
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();;
+        OpenJPAQuery q = pm.createNativeQuery("stringField == 'h2'",HelperPC.class);
+        //FIXME jthomas
+        //q.setUnique(true);
+        HelperPC h2 = (HelperPC) q.getSingleResult();
+        
+        q = pm.createNativeQuery("helpers.containsKey ('h2')",pc.getClass());
+        //FIXME jthomas
+        //q.setUnique(true);
+        pc = (MappedByMapPC) q.getSingleResult();
+        assertEquals(3, pc.getHelpers().size());
+        assertEquals(h2, pc.getHelpers().get("h2"));
+        
+        q = pm.createNativeQuery("helpers.containsValue (:h2)",pc.getClass());
+        //FIXME  jthomas
+        //q.setUnique(true);
+        pc = (MappedByMapPC) q.getSingleResult();
+        assertEquals(3, pc.getHelpers().size());
+        assertEquals(h2, pc.getHelpers().get("h2"));
+        pm.close();
+    }
+    
+    private void setLRS(Class cls, boolean lrs) {
+        ClassMapping cm = ((JDBCConfiguration) getConfiguration()).
+                getMappingRepositoryInstance().getMapping(cls, null, true);
+        cm.getFieldMapping("helpers").setLRS(lrs);
+    }
+    
+    private void unsetLRS(Class cls) {
+        ClassMapping cm = ((JDBCConfiguration) getConfiguration()).
+                getMappingRepositoryInstance().getMapping(cls, null, true);
+        cm.getFieldMapping("helpers").setLRS(false);
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMetaDataValueIndicator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMetaDataValueIndicator.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMetaDataValueIndicator.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMetaDataValueIndicator.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,141 @@
+/*
+ * TestMetaDataValueIndicator.java
+ *
+ * Created on October 4, 2006, 1:35 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.strats.SuperclassDiscriminatorStrategy;
+import org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy;
+import org.apache.openjpa.persistence.Extent;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.*;
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+
+public class TestMetaDataValueIndicator extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{    
+    private OpenJPAEntityManager pm;
+    
+    private ClassMapping eMapping;
+    private ClassMapping fMapping;
+    
+    public TestMetaDataValueIndicator(String str) {
+        super(str);
+    }
+    
+    /** Creates a new instance of TestMetaDataValueIndicator */
+    public TestMetaDataValueIndicator() {
+    }
+    
+    public void setUp() {
+        // ### I hate that we have to do this
+        Class c = MultiE.class;
+        c = MultiF.class;
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        
+        eMapping = (ClassMapping) ((OpenJPAEntityManagerSPI) pm).getConfiguration().
+                getMetaDataRepositoryInstance().getMetaData(MultiE.class,
+                pm.getClassLoader(), true);
+        fMapping = (ClassMapping) ((OpenJPAEntityManagerSPI) pm).getConfiguration().
+                getMetaDataRepositoryInstance().getMetaData(MultiF.class,
+                pm.getClassLoader(), true);
+    }
+    
+    public void tearDown()
+    throws Exception {
+        if (pm.getTransaction().isActive())
+            pm.getTransaction().rollback();
+        pm.close();
+        super.tearDown();
+    }
+    
+    public void testMetaData() {
+        assertEquals(ValueMapDiscriminatorStrategy.class,
+                eMapping.getDiscriminator().getStrategy().getClass());
+        assertEquals(SuperclassDiscriminatorStrategy.class,
+                fMapping.getDiscriminator().getStrategy().getClass());
+    }
+    
+    public void testOperations() {
+       deleteAll(MultiE.class);
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        
+        MultiE e = new MultiE();
+        e.setString0("foo");
+        pm.persist(e);
+        
+        MultiF f = new MultiF();
+        f.setString0("bar");
+        pm.persist(f);
+        
+        pm.getTransaction().commit();
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        //FIXME jthomas
+        /* Cant find equivalent of getExtent()
+        assertEquals(2, countExtent(pm.getExtent(MultiE.class, true)));
+        assertEquals(1, countExtent(pm.getExtent(MultiE.class, false)));
+        assertEquals(1, countExtent(pm.getExtent(MultiF.class, true)));
+        assertEquals(1, countExtent(pm.getExtent(MultiF.class, false)));
+         
+        Object oid = pm.getObjectId
+            (pm.getExtent(MultiE.class, true).iterator().next());
+         */
+        //FIXME remove the next line once the above block is fixed
+        Object oid =null;
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        assertNotNull(pm.getObjectId(oid));
+        pm.close();
+        
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        assertNotNull(pm.getObjectId(oid));
+    }
+    
+    private int countExtent(Extent e) {
+        int count = 0;
+        for (Iterator iter = e.iterator(); iter.hasNext();) {
+            iter.next();
+            count++;
+        }
+        return count;
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiDFG.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiDFG.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiDFG.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiDFG.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,99 @@
+/*
+ * TestMultiDFG.java
+ *
+ * Created on October 4, 2006, 1: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.jdbc.meta;
+
+import java.util.*;
+import javax.persistence.EntityTransaction;
+import javax.transaction.Transaction;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+import org.apache.openjpa.meta.FieldMetaData;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestMultiDFG extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{    
+    private Object boid;
+    
+    public TestMultiDFG(String name) {
+        super(name);
+    }
+    
+    
+    /** Creates a new instance of TestMultiDFG */
+    public TestMultiDFG() {
+    }
+    
+    public void setUp() {
+        
+       deleteAll(MultiB.class);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        EntityTransaction t = pm.getTransaction();
+        t.begin();
+        MultiB b = new MultiB();
+        pm.persist(b);
+        t.commit();
+        boid = pm.getObjectId(b);
+        pm.close();
+    }
+    
+    public void testDFG() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        MultiB b = (MultiB) pm.getObjectId(boid);
+        
+        // check the non-dfg fields
+        OpenJPAStateManager sm = getStateManager(b, pm);
+        FieldMetaData fmd = sm.getMetaData().getField("bString");
+        assertTrue("bString should not be loaded",
+                !sm.getLoaded().get(fmd.getIndex()));
+        
+        fmd = sm.getMetaData().getField("bInt");
+        assertTrue("bInt should not be loaded",
+                !sm.getLoaded().get(fmd.getIndex()));
+        
+        System.out.println("### getting values");
+        b.getBString();
+        
+        System.out.println("### getting values again");
+        b.getString0();
+        b.getBString();
+        
+        pm.close();
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableMappings.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableMappings.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableMappings.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableMappings.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,237 @@
+/*
+ * TestMultiTableMappings.java
+ *
+ * Created on October 4, 2006, 4:09 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.jdbc.meta;
+
+import java.util.*;
+import javax.persistence.EntityTransaction;
+import javax.transaction.Transaction;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.jdbc.JDBCFetchPlan;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestMultiTableMappings extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase {
+    
+
+    private Object aoid;
+    private Object boid;
+    private Object coid;
+    private Object doid;
+    
+    public TestMultiTableMappings(String name) {
+        super(name);
+    }
+    
+    /** Creates a new instance of TestMultiTableMappings */
+    public TestMultiTableMappings() {
+    }
+    
+    public void setUpTestCase() {
+       deleteAll(MultiA.class);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Collection os = new ArrayList();
+        MultiA a = new MultiA();
+        MultiB b = new MultiB();
+        MultiC c = new MultiC();
+        MultiD d = new MultiD();
+        os.add(a);
+        os.add(b);
+        os.add(c);
+        os.add(d);
+        d.setA(new MultiA());
+        os.add(new MultiD());
+        d.setDString1("d string 1");
+        
+        EntityTransaction t = pm.getTransaction();
+        t.begin();
+        pm.persistAll(os);
+        t.commit();
+        aoid = pm.getObjectId(a);
+        boid = pm.getObjectId(b);
+        coid = pm.getObjectId(c);
+        doid = pm.getObjectId(d);
+        pm.close();
+    }
+    
+    public void XXXtestUpdates() {
+        //TEST DISABLED ... not converted
+        /*
+        PersistenceManager pm = getPM();
+        Transaction t = pm.currentTransaction();
+        try {
+            for (int i = 0; i < 2; i++) {
+                t.begin();
+                changeA((MultiA) pm.getObjectById(aoid, i == 0));
+                changeB((MultiB) pm.getObjectById(boid, i == 0));
+                changeC((MultiC) pm.getObjectById(coid, i == 0));
+                changeD((MultiD) pm.getObjectById(doid, i == 0));
+                t.commit();
+            }
+        } finally {
+            if (t.isActive()) {
+                t.rollback();
+            }
+            pm.close();
+        }
+         */
+    }
+    
+    public void XXXtestInserts() {
+        //TEST DISABLED ... not converted
+        /*
+        PersistenceManager pm = getPM();
+        assertEquals(2,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiA.class, false)).execute()).size());
+         
+        assertEquals(4,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiB.class, true)).execute()).size());
+         
+        assertEquals(1,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiB.class, false)).execute()).size());
+         
+        assertEquals(1,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiC.class, false)).execute()).size());
+         
+        assertEquals(2,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiD.class, false)).execute()).size());
+         
+        assertEquals(6,
+                ((Collection) pm.newQuery
+                (pm.getExtent(MultiA.class, true)).execute()).size());
+         
+        pm.close();
+         */
+    }
+    
+    public void XXXtestOneToOne() {
+        //TEST DISABLED ... not converted
+        /*
+        PersistenceManager pm = getPM();
+        MultiD d = (MultiD) pm.getObjectById(doid, true);
+        assertNotNull(d.getA());
+        pm.close();
+         */
+    }
+    
+    public void XXXtestQueries() {
+        //TEST DISABLED ... not converted
+        /*
+        PersistenceManager pm = getPM();
+        Query q = pm.newQuery(pm.getExtent(MultiD.class, false),
+                "dString1 == \"d string 1\"");
+        //### this behaves like '""': "d string 1");
+        Collection c = (Collection) q.execute();
+        assertEquals(1, c.size());
+        pm.close();
+         */
+    }
+    
+    // ### more tests:
+    // ### - horizontal with extent with subclass=false
+    // ### - aggregates with horizontal, interface, this stuff,
+    // ### - base A, vertical B extends A, virtual C extends B,
+    // ###   vertical D extends C, vertical E extends C, flat F extends C
+    
+    public void testVerticalQueryModeQueries() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createNativeQuery("",MultiA.class);
+        ((JDBCFetchPlan) q.getFetchPlan()).
+                setSubclassFetchMode(JDBCFetchPlan.EAGER_PARALLEL);
+        // we need ordering; otherwise kodo is smart enough to only run first
+        // select until its results are exhausted
+        
+        //FIXME jthomas
+        //q.setOrdering("string0 ascending");
+        sql.clear();
+        assertEquals(sql.toString(), 0, sql.size());
+        
+        Collection c = (Collection) q.getCandidateCollection();
+        
+        // account for the select distinct
+        if (((String) sql.get(0)).startsWith("SELECT DISTINCT"))
+            assertEquals(sql.toString(), 5, sql.size());
+        else
+            assertEquals(sql.toString(), 4, sql.size());
+        sql.clear();
+        
+        assertEquals(6, c.size());
+        
+        // only check for counts sql if any was executed (some databases
+        // might eagerly instantiate all the rows, such as pointbase)
+        if (sql.size() != 0)
+            assertEquals(sql.toString(), 4, sql.size()); // select counts
+        sql.clear();
+        
+        // walk through the results. This will cause individual
+        // objects to be loaded, and therefore the dfgs to be loaded,
+        // and therefore any additional SQL to be executed.
+        for (Iterator iter = c.iterator(); iter.hasNext();)
+            iter.next();
+        
+        assertEquals(sql.toString(), 0, sql.size());
+        
+        pm.close();
+    }
+    
+    private void changeA(MultiA a) {
+        a.setString0(a.getString0() + " changed");
+        a.setInt0(a.getInt0() + 1);
+    }
+    
+    private void changeB(MultiB b) {
+        changeA(b);
+        b.setBString(b.getBString() + " changed");
+    }
+    
+    private void changeC(MultiC c) {
+        changeB(c);
+        c.setCString0(c.getCString0() + " changed");
+    }
+    
+    private void changeD(MultiD d) {
+        changeB(d);
+        d.setDString0(d.getDString0() + " changed");
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableSelfCollection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableSelfCollection.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableSelfCollection.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestMultiTableSelfCollection.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,209 @@
+/*
+ * TestMultiTableSelfCollection.java
+ *
+ * Created on October 4, 2006, 2:35 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.jdbc.meta;
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestMultiTableSelfCollection extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest
+{    
+    private Object a1oid;
+    private Object a2oid;
+    private Object a3oid;
+    private Object a4oid;
+    
+    private Object c1oid;
+    private Object c2oid;
+    private Object c3oid;
+    private Object c4oid;
+    
+    public TestMultiTableSelfCollection(String name) {
+        super(name);
+    }
+    
+    /** Creates a new instance of TestMultiTableSelfCollection */
+    public TestMultiTableSelfCollection() {
+    }
+    
+    public void setUp() {
+       deleteAll(MultiA.class);
+        
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        
+        Collection os = new ArrayList();
+        MultiA a1 = new MultiA();
+        MultiA a2 = new MultiA();
+        MultiA a3 = new MultiA();
+        MultiA a4 = new MultiA();
+        MultiC c1 = new MultiC();
+        MultiC c2 = new MultiC();
+        MultiC c3 = new MultiC();
+        MultiC c4 = new MultiC();
+        os.add(a1);
+        os.add(a2);
+        os.add(a3);
+        os.add(a4);
+        os.add(c1);
+        os.add(c2);
+        os.add(c3);
+        os.add(c4);
+        
+        c1.getMultiAs().add(a1);
+        c1.getMultiAs().add(a2);
+        a1.getMultiCs().add(c1);
+        a2.getMultiCs().add(c1);
+        
+        c2.getMultiAs().add(a1);
+        c2.getMultiAs().add(a2);
+        a1.getMultiCs().add(c2);
+        a2.getMultiCs().add(c2);
+        
+        c3.getMultiAs().add(a3);
+        c3.getMultiAs().add(a4);
+        a3.getMultiCs().add(c3);
+        a4.getMultiCs().add(c3);
+        
+        c4.getMultiAs().add(a3);
+        c4.getMultiAs().add(a4);
+        a3.getMultiCs().add(c4);
+        a4.getMultiCs().add(c4);
+        
+        pm.persistAll(os);
+        pm.getTransaction().commit();
+        
+        a1oid = pm.getObjectId(a1);
+        a2oid = pm.getObjectId(a2);
+        a3oid = pm.getObjectId(a3);
+        a4oid = pm.getObjectId(a4);
+        
+        c1oid = pm.getObjectId(c1);
+        c2oid = pm.getObjectId(c2);
+        c3oid = pm.getObjectId(c3);
+        c4oid = pm.getObjectId(c4);
+        
+        pm.close();
+    }
+    
+    public void testSelfCollections() {
+        OpenJPAEntityManager pm = (OpenJPAEntityManager)currentEntityManager();
+        
+        // check that all the sets are the right size, and equal where
+        // they should be.
+        
+        MultiA a1 = (MultiA) pm.getObjectId(a1oid);
+        assertEquals(2, a1.getMultiCs().size());
+        
+        MultiA a2 = (MultiA) pm.getObjectId(a2oid);
+        assertEquals(2, a2.getMultiCs().size());
+        
+        assertEquals(a1.getMultiCs(), a2.getMultiCs());
+        
+        MultiA a3 = (MultiA) pm.getObjectId(a3oid);
+        assertEquals(2, a3.getMultiCs().size());
+        
+        MultiA a4 = (MultiA) pm.getObjectId(a4oid);
+        assertEquals(2, a4.getMultiCs().size());
+        
+        assertEquals(a3.getMultiCs(), a4.getMultiCs());
+        
+        MultiC c1 = (MultiC) pm.getObjectId(c1oid);
+        assertEquals(2, c1.getMultiAs().size());
+        
+        MultiC c2 = (MultiC) pm.getObjectId(c2oid);
+        assertEquals(2, c2.getMultiAs().size());
+        
+        assertEquals(c1.getMultiAs(), c2.getMultiAs());
+        
+        MultiC c3 = (MultiC) pm.getObjectId(c3oid);
+        assertEquals(2, c3.getMultiAs().size());
+        
+        MultiC c4 = (MultiC) pm.getObjectId(c4oid);
+        assertEquals(2, c4.getMultiAs().size());
+        
+        assertEquals(c3.getMultiAs(), c4.getMultiAs());
+        
+        // check that all the sets contain the correct values, and
+        // don't contain the wrong values. Probably don't need to do
+        // the above check as well.
+        
+        assertTrue(a1.getMultiCs().contains(c1));
+        assertTrue(a1.getMultiCs().contains(c2));
+        assertTrue(!a1.getMultiCs().contains(c3));
+        assertTrue(!a1.getMultiCs().contains(c4));
+        
+        assertTrue(a2.getMultiCs().contains(c1));
+        assertTrue(a2.getMultiCs().contains(c2));
+        assertTrue(!a2.getMultiCs().contains(c3));
+        assertTrue(!a2.getMultiCs().contains(c4));
+        
+        assertTrue(!a3.getMultiCs().contains(c1));
+        assertTrue(!a3.getMultiCs().contains(c2));
+        assertTrue(a3.getMultiCs().contains(c3));
+        assertTrue(a3.getMultiCs().contains(c4));
+        
+        assertTrue(!a4.getMultiCs().contains(c1));
+        assertTrue(!a4.getMultiCs().contains(c2));
+        assertTrue(a4.getMultiCs().contains(c3));
+        assertTrue(a4.getMultiCs().contains(c4));
+        
+        assertTrue(c1.getMultiAs().contains(a1));
+        assertTrue(c1.getMultiAs().contains(a2));
+        assertTrue(!c1.getMultiAs().contains(a3));
+        assertTrue(!c1.getMultiAs().contains(a4));
+        
+        assertTrue(c2.getMultiAs().contains(a1));
+        assertTrue(c2.getMultiAs().contains(a2));
+        assertTrue(!c2.getMultiAs().contains(a3));
+        assertTrue(!c2.getMultiAs().contains(a4));
+        
+        assertTrue(!c3.getMultiAs().contains(a1));
+        assertTrue(!c3.getMultiAs().contains(a2));
+        assertTrue(c3.getMultiAs().contains(a3));
+        assertTrue(c3.getMultiAs().contains(a4));
+        
+        assertTrue(!c4.getMultiAs().contains(a1));
+        assertTrue(!c4.getMultiAs().contains(a2));
+        assertTrue(c4.getMultiAs().contains(a3));
+        assertTrue(c4.getMultiAs().contains(a4));
+        
+        pm.close();
+    }
+    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestNoClassColumn.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestNoClassColumn.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestNoClassColumn.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestNoClassColumn.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,68 @@
+/*
+ * TestNoClassColumn.java
+ *
+ * Created on October 4, 2006, 2:44 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.kernel.Query;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestNoClassColumn extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+        
+    /** Creates a new instance of TestNoClassColumn */
+    public TestNoClassColumn() {
+    }
+
+    public TestNoClassColumn(String test) {
+        super(test);
+    }
+
+    public void testQuery() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        OpenJPAQuery q = pm.createNativeQuery("",NoClassColumn.class);
+        //FIXME jthomas
+        //q.declareParameters("java.lang.String input");
+        //q.setFilter("test==input");
+        Map params = new HashMap();
+        params.put("input", "blah");
+        //FIXME jthomas
+        //Collection c = (Collection) q.executeWithMap(params);
+        pm.close();
+    }    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestRawField.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,75 @@
+/*
+ * TestRawField.java
+ *
+ * Created on October 4, 2006, 2:57 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.jdbc.meta;
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestRawField extends org.apache.openjpa.persistence.jdbc.kernel.BaseJDBCTest{
+    
+    /** Creates a new instance of TestRawField */
+    public TestRawField(String name) 
+    {
+    	super(name);
+    }
+    
+    public void setUp() {
+       deleteAll(RawField.class);
+    }
+
+    public void testRaw() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        RawField pc = new RawField();
+        pc.setString("BAR");
+        pm.persist(pc);
+        Object oid = pm.getObjectId(pc);
+
+        // batching?
+        pc = new RawField();
+        pc.setString("GOO");
+        pm.persist(pc);
+        pm.getTransaction().commit();
+        pm.close();
+
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (RawField) pm.getObjectId(oid);
+        assertEquals(pc.getString(), "BARFOO", pc.getString());
+        pm.close();
+    }    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestStateImage.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestStateImage.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestStateImage.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/TestStateImage.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,241 @@
+/*
+ * TestStateImage.java
+ *
+ * Created on October 4, 2006, 3:09 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.jdbc.meta;
+
+import java.util.*;
+import org.apache.openjpa.kernel.Query;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestStateImage extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase {
+    private Object _oid = null;
+    
+    /** Creates a new instance of TestStateImage */
+    public TestStateImage() {
+    }
+    public TestStateImage(String test) {
+        super(test);
+    }
+    
+    
+    public void setUpTestCase() {
+       deleteAll(StateImagePC2.class);
+       deleteAll(StateImagePC3.class);
+        
+        StateImagePC2 pc = new StateImagePC2();
+        pc.setStringField("string1");
+        pc.setIntField(1);
+        StateImagePC2 pc2 = new StateImagePC2();
+        pc2.setStringField("string2");
+        pc2.setIntField(2);
+        pc.setStateImage(pc2);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+        pm.persist(pc);
+        _oid = pm.getObjectId(pc);
+        pm.getTransaction().commit();
+        pm.close();
+    }
+    
+    public void testOptLock() {
+        OpenJPAEntityManager pm1 = getEm(true, true);
+        OpenJPAEntityManager pm2 = getEm(true, true);
+        
+        pm1.getTransaction().begin();
+        pm2.getTransaction().begin();
+        StateImagePC2 pc1 = (StateImagePC2) pm1.getObjectId(_oid);
+        StateImagePC2 pc2 = (StateImagePC2) pm2.getObjectId(_oid);
+        
+        pc1.setIntField(3);
+        pc1.setStateImage(null);
+        
+        pc2.setIntField(4);
+        
+        pm1.getTransaction().commit();
+        try {
+            pm2.getTransaction().commit();
+            fail("Should have caused OL exception.");
+        } catch (Exception jfe) {
+            pm2.getTransaction().begin();
+            pm2.refresh(pc2);
+            pc2.setIntField(4);
+            pm2.getTransaction().commit();
+        }
+        
+        // make sure the next transaction works too
+        pm2.getTransaction().begin();
+        pc2.setIntField(5);
+        pm2.getTransaction().commit();
+        
+        pm1.getTransaction().begin();
+        pm1.refresh(pc1);
+        pc1.setIntField(6);
+        
+        pm2.getTransaction().begin();
+        pc2.setIntField(7);
+        
+        pm1.getTransaction().commit();
+        try {
+            pm2.getTransaction().commit();
+            fail("Should have caused OL exception.");
+        } catch (Exception jfe) {
+            pm2.getTransaction().begin();
+            pm2.refresh(pc2);
+            pc2.setIntField(7);
+            pm2.getTransaction().commit();
+        }
+        pm1.close();
+        pm2.close();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        StateImagePC2 pc = (StateImagePC2) pm.getObjectId(_oid);
+        assertNull(pc.getStateImage());
+        assertEquals(7, pc.getIntField());
+        pm.close();
+    }
+    
+    /**
+     * This currently isn't working: state-image locking will not
+     * detect when someone else updated the row before deleting.
+     */
+    public void NOTWORKINGtestOptLockWithDelete() {
+        OpenJPAEntityManager pm1 = getEm(true, true);
+        StateImagePC2 pc1 = (StateImagePC2) pm1.getObjectId(_oid);
+        
+        OpenJPAEntityManager pm2 = getEm(true, true);
+        StateImagePC2 pc2 = (StateImagePC2) pm2.getObjectId(_oid);
+        
+        pm1.getTransaction().begin();
+        pc1.setIntField(3);
+        
+        pm2.getTransaction().begin();
+        pm2.remove(pc2);
+        
+        pm1.getTransaction().commit();
+        try {
+            pm2.getTransaction().commit();
+            fail("Should have caused OL exception.");
+        } catch (Exception jfe) {
+            pm2.getTransaction().begin();
+            pm2.refresh(pc2);
+            pm2.remove(pc2);
+            pm2.getTransaction().commit();
+        }
+    }
+    
+    public void testOptLockOnVerticalClass() {
+        OpenJPAEntityManager pm1 = getEm(true, true);
+        OpenJPAEntityManager pm2 = getEm(true, true);
+        
+        // have to load via query or extent where we're selecting the vertical
+        // field in the initial SELECT
+        OpenJPAQuery q1 = pm1.createNativeQuery("",StateImagePC2.class);
+        //FIXME  jthomas
+        //q1.setOrdering("intField ascending");
+        StateImagePC2 pc1 = (StateImagePC2) ((Collection) q1.getCandidateCollection()).
+                iterator().next();
+        q1.closeAll();
+        
+        OpenJPAQuery q2 = pm2.createNativeQuery("",StateImagePC2.class);
+        //FIXME jthomas
+        //q2.setOrdering("intField ascending");
+        StateImagePC2 pc2 = (StateImagePC2) ((Collection) q2.getCandidateCollection()).
+                iterator().next();
+        q2.closeAll();
+        
+        pm1.getTransaction().begin();
+        pc1.setStringField("changed1");
+        pc1.setStateImage(null);
+        
+        pm2.getTransaction().begin();
+        pc2.setStringField("changed2");
+        
+        pm1.getTransaction().commit();
+        
+        try {
+            pm2.getTransaction().commit();
+            fail("Should have caused OL exception.");
+        } catch (Exception jfe) {
+            pm2.getTransaction().begin();
+            pm2.refresh(pc2);
+            pc2.setStringField("changed2");
+            pm2.getTransaction().commit();
+        }
+        pm1.close();
+        pm2.close();
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        StateImagePC2 pc = (StateImagePC2) pm.getObjectId(_oid);
+        assertNull(pc.getStateImage());
+        assertEquals("changed2", pc.getStringField());
+        pm.close();
+    }
+    
+    public void testLockGroup()
+    throws Exception {
+        OpenJPAEntityManager pm = getEm(true, true);
+        pm.getTransaction().begin();
+        StateImagePC3 pc = new StateImagePC3();
+        pc.setLockField(4);
+        pc.setNoLockField(6);
+        pm.persist(pc);
+        pm.getTransaction().commit();
+        
+        pm.getTransaction().begin();
+        pc.setLockField(6);
+        sql.clear();
+        pm.getTransaction().commit();
+        assertNotSQL("* WHERE * NOLOCK*");
+        
+        pm.close();
+    }
+    
+    public static void main(String[] args) {
+        
+        //FIXME
+        //main(TestStateImage.class);
+    }
+    private OpenJPAEntityManager getEm(boolean optimistic,boolean retainValues){
+        OpenJPAEntityManager em = currentEntityManager();
+        em.setNontransactionalRead(true);
+        em.setRetainState(retainValues);
+        em.setOptimistic(optimistic);
+        return em;
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestLockGroupsWithHorizontalBaseType.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestLockGroupsWithHorizontalBaseType.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestLockGroupsWithHorizontalBaseType.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestLockGroupsWithHorizontalBaseType.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,85 @@
+/*
+ * TestLockGroupsWithHorizontalBaseType.java
+ *
+ * Created on October 4, 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.jdbc.meta.horizontal;
+
+
+import java.util.*;
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+import org.apache.openjpa.persistence.common.utils.*;
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestLockGroupsWithHorizontalBaseType extends AbstractTestCase
+{   
+    /** Creates a new instance of TestLockGroupsWithHorizontalBaseType */
+    public TestLockGroupsWithHorizontalBaseType(String name) 
+    {
+    	super(name, "jdbccactusapp");
+    }
+
+
+    public void setUp() {
+       deleteAll(LockGroupSubclass.class);
+    }
+
+    public void testHorizontalLockGroup() {
+        LockGroupSubclass pc = new LockGroupSubclass();
+        pc.setDefaultLockGroupField("foo");
+        pc.setNonDefaultLockGroupField("bar");
+        OpenJPAEntityManager pm = getEm(true, true);
+        pm.getTransaction().begin();
+        pm.persist(pc);
+        pm.getTransaction().commit();
+        pm.getTransaction().begin();
+
+        Object oid = pm.getObjectId(pc);
+
+        OpenJPAEntityManager  pm2 = getEm(true, true);
+        LockGroupSubclass pc2 = (LockGroupSubclass) pm2.getObjectId(oid);
+        pm2.getTransaction().begin();
+        pc2.setNonDefaultLockGroupField("baz");
+        pm2.getTransaction().commit();
+
+        pc.setDefaultLockGroupField("wookie");
+        pm.getTransaction().commit();
+    }    
+    
+   private OpenJPAEntityManager getEm(boolean optimistic,boolean retainValues) {
+        OpenJPAEntityManager em = (OpenJPAEntityManager)currentEntityManager();
+        em.setNontransactionalRead(true);
+        em.setRetainState(retainValues);
+        em.setOptimistic(optimistic);
+        return em;
+    }    
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestQueryAgainstEntireMappedHierarchy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestQueryAgainstEntireMappedHierarchy.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestQueryAgainstEntireMappedHierarchy.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/horizontal/TestQueryAgainstEntireMappedHierarchy.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,91 @@
+/*
+ * TestQueryAgainstEntireMappedHierarchy.java
+ *
+ * Created on October 5, 2006, 10:46 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.jdbc.meta.horizontal;
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestQueryAgainstEntireMappedHierarchy extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase
+{
+	
+    /** Creates a new instance of TestQueryAgainstEntireMappedHierarchy */
+    public TestQueryAgainstEntireMappedHierarchy(String name) 
+    {
+    	super(name);
+    }
+    
+    public void setUpTestCase() 
+    {        
+        // this test depends on this fact
+        assertTrue(HorizJ.class.getSuperclass() == HorizD.class);
+        assertTrue(HorizK.class.getSuperclass() == HorizJ.class);
+
+       deleteAll(HorizD.class);
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        pm.getTransaction().begin();
+
+        HorizD d = new HorizD();
+        d.setStringA("stringa-d");
+        d.setStringC("stringc-d");
+        pm.persist(d);
+
+        HorizJ j = new HorizJ();
+        j.setStringA("stringa-j");
+        j.setStringC("stringc-j");
+        pm.persist(j);
+
+        HorizK k = new HorizK();
+        k.setStringA("stringa-k");
+        k.setStringC("stringc-k");
+        pm.persist(k);
+
+        pm.getTransaction().commit();
+        pm.close();
+    }
+
+    public void testQueryAgainstEntireMappedHierarchy() {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        sql.clear();
+        //FIXME jthomas
+        //pm.newQuery(HorizD.class).execute();
+        String lastStatement = (String) sql.get(sql.size() - 1);
+        assertTrue(lastStatement.toLowerCase().indexOf("in (") == -1);
+        pm.close();
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/tableperclass/TestUnionPlaceholderTypes.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/tableperclass/TestUnionPlaceholderTypes.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/tableperclass/TestUnionPlaceholderTypes.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/tableperclass/TestUnionPlaceholderTypes.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,123 @@
+/*
+ * TestUnionPlaceholderTypes.java
+ *
+ * Created on October 5, 2006, 2:04 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.jdbc.meta.tableperclass;
+
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.SQLFactory;
+import org.apache.openjpa.kernel.Broker;
+import org.apache.openjpa.util.Id;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestUnionPlaceholderTypes extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase {
+    
+    
+    /** Creates a new instance of TestUnionPlaceholderTypes */
+    public TestUnionPlaceholderTypes(String name) 
+    {
+    	super(name);
+    }
+
+    private boolean _union = false;
+
+    public void setUpTestCase() {
+        JDBCConfiguration conf = (JDBCConfiguration) getConfiguration();
+        //FIXME jthomas
+        //_union = ((SQLFactory) conf.getSQLFactoryInstance()).getAdvancedSQL().getSupportsUnion();
+    }
+
+    public void testUnion()
+        throws Exception {
+       deleteAll(PlaceholderTypesA.class);
+
+        PlaceholderTypesA pta = new PlaceholderTypesA();
+        pta.setIntA(1);
+        PlaceholderTypesB ptb = new PlaceholderTypesB();
+        ptb.setIntA(2);
+        ptb.setIntB(3);
+        ptb.setBooleanB(true);
+        ptb.setByteB((byte) 64);
+        ptb.setCharB('a');
+        ptb.setFloatB(99.9F);
+        ptb.setStringB("stringB");
+        ptb.setClobB("clobB");
+        ptb.setBlobB("blobB");
+
+        Broker broker = getBrokerFactory().newBroker();
+        broker.begin();
+        broker.persist(pta, null);
+        broker.persist(ptb, null);
+        broker.commit();
+        Object oida = broker.getObjectId(pta);
+        long idb = ((Id) broker.getObjectId(ptb)).getId();
+        broker.close();
+
+        broker = getBrokerFactory().newBroker();
+        broker.begin();
+        sql.clear();
+        pta = (PlaceholderTypesA) broker.find(oida, true, null);
+        assertEquals(1, pta.getIntA());
+        if (_union)
+            assertEquals(1, sql.size());
+        else
+            assertNotSQL("UNION");
+        broker.close();
+
+        broker = getBrokerFactory().newBroker();
+        broker.begin();
+        sql.clear();
+        ptb = (PlaceholderTypesB) broker.find(broker.newObjectId
+            (PlaceholderTypesB.class, new Long(idb)), true, null);
+        assertEquals(2, ptb.getIntA());
+        assertEquals(3, ptb.getIntB());
+        assertTrue(ptb.getBooleanB());
+        assertEquals(64, ptb.getByteB());
+        assertEquals('a', ptb.getCharB());
+        assertEquals(99.9F, ptb.getFloatB(), .001);
+        assertEquals("stringB", ptb.getStringB());
+        assertEquals("clobB", ptb.getClobB());
+        assertEquals("blobB", ptb.getBlobB());
+        if (_union)
+            assertEquals(1, sql.size());
+        else
+            assertNotSQL("UNION");
+        broker.close();
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestJoinSubclasses.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestJoinSubclasses.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestJoinSubclasses.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/meta/vertical/TestJoinSubclasses.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,221 @@
+/*
+ * TestJoinSubclasses.java
+ *
+ * Created on October 5, 2006, 2:17 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.jdbc.meta.vertical;
+
+
+import java.util.*;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.Join;
+import org.apache.openjpa.persistence.Extent;
+import org.apache.openjpa.util.Id;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.*;
+
+
+import java.lang.annotation.Annotation;
+import junit.framework.*;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+public class TestJoinSubclasses
+        extends org.apache.openjpa.persistence.jdbc.kernel.TestSQLListenerTestCase{
+     
+    /** Creates a new instance of TestJoinSubclasses */
+    public TestJoinSubclasses(String name) 
+    {
+    	super(name);
+    }
+    
+    
+    private String _outer = "OUTER";
+    private Object _base = null;
+    private Object _baseSubFlat = null;
+    
+    public boolean skipTest() {
+        //FIXME
+        /*
+        return super.skipTest()
+            || ((JDBCConfiguration) getConfiguration()).
+            getDBDictionaryInstance().joinSyntax == Join.SYNTAX_TRADITIONAL;
+         */
+        return false;
+    }
+    
+    public void setUpTestCase() {
+        if (((JDBCConfiguration) getConfiguration()).getDBDictionaryInstance().
+                joinSyntax == Join.SYNTAX_DATABASE)
+            _outer = "(+)";
+        
+       deleteAll(JoinSubclassBase.class);
+        
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        startTx(pm);;
+        JoinSubclassBase base = new JoinSubclassBase();
+        base.setBaseField(1);
+        pm.persist(base);
+        
+        JoinSubclassBaseSubVert sub1 = new JoinSubclassBaseSubVert();
+        sub1.setBaseField(2);
+        sub1.setBaseSubVertField(3);
+        pm.persist(sub1);
+        
+        JoinSubclassBaseSubFlat sub2 = new JoinSubclassBaseSubFlat();
+        sub2.setBaseField(3);
+        sub2.setBaseSubVertField(4);
+        sub2.setBaseSubFlatField(5);
+        pm.persist(sub2);
+        
+        endTx(pm);;
+        _base = pm.getObjectId(base);
+        _baseSubFlat = pm.getObjectId(sub2);
+        pm.close();
+    }
+    
+    public void testBaseExtentNoSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(JoinSubclassBase.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        JoinSubclassBase pc = (JoinSubclassBase) itr.next();
+        assertEquals(1, pc.getBaseField());
+        assertEquals(JoinSubclassBase.class, pc.getClass());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testBaseExtentWithSubs()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(JoinSubclassBase.class, true);
+        Collection pcs = new TreeSet(((Extent) extent).list());
+        assertEquals(3, pcs.size());
+        Iterator itr = pcs.iterator();
+        for (int i = 0; i < 2; i++) {
+            JoinSubclassBase pc = (JoinSubclassBase) itr.next();
+            assertEquals(i + 1, pc.getBaseField());
+            switch (i) {
+                case 0:
+                    assertEquals(JoinSubclassBase.class, pc.getClass());
+                    break;
+                case 1:
+                    assertEquals(JoinSubclassBaseSubVert.class, pc.getClass());
+                    assertEquals(i + 2, ((JoinSubclassBaseSubVert) pc).
+                            getBaseSubVertField());
+                    break;
+                case 2:
+                    assertEquals(JoinSubclassBaseSubFlat.class, pc.getClass());
+                    assertEquals(i + 2, ((JoinSubclassBaseSubFlat) pc).
+                            getBaseSubVertField());
+                    assertEquals(i + 3, ((JoinSubclassBaseSubFlat) pc).
+                            getBaseSubFlatField());
+                    break;
+            }
+        }
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testLeafExtent()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        Extent extent = pm.createExtent(JoinSubclassBaseSubFlat.class, false);
+        Iterator itr = extent.iterator();
+        assertTrue(itr.hasNext());
+        JoinSubclassBaseSubFlat pc = (JoinSubclassBaseSubFlat) itr.next();
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSubVertField());
+        assertEquals(5, pc.getBaseSubFlatField());
+        assertTrue(!itr.hasNext());
+        extent.closeAll();
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertNotSQL(_outer);
+    }
+    
+    public void testBaseGetById()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        JoinSubclassBase pc = (JoinSubclassBase) pm.getObjectId(_base);
+        assertEquals(1, pc.getBaseField());
+        assertEquals(JoinSubclassBase.class, pc.getClass());
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with non-exact id
+        Id oid = new Id(JoinSubclassBase.class, ((Id) _base).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (JoinSubclassBase) pm.getObjectId(oid);
+        assertEquals(1, pc.getBaseField());
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertSQL(_outer);
+    }
+    
+    public void testLeafGetById()
+    throws Exception {
+        OpenJPAEntityManager pm =(OpenJPAEntityManager)currentEntityManager();
+        JoinSubclassBaseSubFlat pc = (JoinSubclassBaseSubFlat)
+        pm.getObjectId(_baseSubFlat);
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSubVertField());
+        assertEquals(5, pc.getBaseSubFlatField());
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertNotSQL(_outer);
+        sql.clear();
+        
+        // should outer join with non-exact id
+        Id oid = new Id(JoinSubclassBase.class, ((Id) _baseSubFlat).getId());
+        pm = (OpenJPAEntityManager)currentEntityManager();
+        pc = (JoinSubclassBaseSubFlat) pm.getObjectId(oid);
+        assertEquals(3, pc.getBaseField());
+        assertEquals(4, pc.getBaseSubVertField());
+        assertEquals(5, pc.getBaseSubFlatField());
+        pm.close();
+        
+        assertEquals(sql.toString(), 1, sql.size());
+        assertSQL(_outer);
+    }
+    
+}



Mime
View raw message