openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r627979 [3/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-pers...
Date Fri, 15 Feb 2008 09:20:40 GMT
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityListenerAnnot.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityListenerAnnot.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityListenerAnnot.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityListenerAnnot.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,265 @@
+/*
+ * 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.annotations;
+
+import java.util.List;
+
+import javax.persistence.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+public class TestEntityListenerAnnot extends AbstractTestCase
+{
+
+	public TestEntityListenerAnnot(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+	public void setUp()
+	{
+		deleteAll(Employee.class);
+		deleteAll(ContractEmployee.class);
+		CallbackStorage.clearStore();
+	}
+
+	public void testPrePersist()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+
+		ContractEmployee cemp = new ContractEmployee(21, "afam", 25, 5);
+
+		em.persist(cemp);
+		CallbackStorage store = CallbackStorage.getInstance();
+
+		assertNotNull(store.getClist());
+		assertEquals("@pre/post persist callback is over/under-firing", 2, store.getClist().size());
+		assertEquals("longnamevalidatorprr", store.getClist().get(0));
+		assertEquals("contractemployee", store.getClist().get(1));
+
+		endEm(em);
+	}
+
+	public void testPostPersist()
+	{
+		OpenJPAEntityManager em = null;	
+	  try{	
+		em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		Employee emp = new Employee(1, "john");
+
+		em.persist(emp);
+		CallbackStorage store = CallbackStorage.getInstance();
+
+		assertNotNull(store.getClist());
+		assertEquals("@pre/post persist callback is over/under-firing", 4, store.getClist().size());
+		assertEquals("namevalidator", store.getClist().get(0));
+		assertEquals("longnamevalidatorprr", store.getClist().get(1));
+		assertEquals("employeepop", store.getClist().get(2));
+		assertEquals("We expected 'gen#" +  emp.getCheck() + " : " + emp.getCheck() + "'. However, we got '" + store.getClist().get(3) + "'", "gen#"+emp.getCheck(), store.getClist().get(3));
+	  }
+      finally {
+		endTx(em);
+		endEm(em);
+      }
+	}
+
+	public void testPre_PostRemove()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		Employee emp = new Employee(8, "Jonathan");
+		em.persist(emp);
+
+		endTx(em);
+		endEm(em);
+		//--------------------------------------------------------------
+		em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		emp = em.find(Employee.class, 8);
+
+		CallbackStorage.clearStore(); //clear the store
+		assertTrue(CallbackStorage.isEmpty());
+
+		em.remove(emp);
+
+		assertTrue(!CallbackStorage.isEmpty());
+		assertEquals("callback is under/over-firing...", 2, CallbackStorage.size());
+		assertEquals("namevalidatorprr", CallbackStorage.getInstance().getClist().get(0));
+		assertEquals("namevalidatorpor", CallbackStorage.getInstance().getClist().get(1));
+
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testPreUpdate()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		Employee emp = new Employee(5, "Abraham");
+		em.persist(emp);
+
+		CallbackStorage.clearStore();
+
+		String query = "Update Employee e SET e.name = 'Joseph' WHERE e.id = :id";
+
+		int result = em.createQuery(query)
+		               .setParameter("id", 5)
+		               .executeUpdate();
+
+		List store = CallbackStorage.getInstance().getClist();
+
+		assertNotNull(result);
+		assertEquals(1, result);
+		assertNotNull(store);
+		assertEquals(3, store.size());
+		assertEquals("namevalidatorpou", store.get(0));
+		assertEquals("longnamevalidatorpou", store.get(1));
+		assertEquals("employeepou", store.get(2));
+
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testPreUpdate2()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		Employee emp = new Employee(5, "Abraham");
+		em.persist(emp);
+
+		CallbackStorage.clearStore();
+		endTx(em);
+
+		startTx(em);
+		emp = em.find(Employee.class, 5);
+
+		CallbackStorage.clearStore();
+		assertEquals("Abraham", emp.getName());
+
+		emp.setName("Abrahamovich");
+		em.flush();
+
+		List store = CallbackStorage.getInstance().getClist();
+
+		assertNotNull(store);
+		assertEquals("update callback is either underfiring or overfiring...", 3, store.size());
+		assertEquals("namevalidatorpou", store.get(0));
+		assertEquals("longnamevalidatorpou", store.get(1));
+		assertEquals("employeepou", store.get(2));
+
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testPostLoad()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		Employee emp = new Employee(6, "Jefferson");
+
+		em.persist(emp);
+		CallbackStorage.clearStore();
+
+		endTx(em);
+
+		startTx(em);
+		CallbackStorage.clearStore();
+
+		assertTrue(CallbackStorage.getInstance().getClist().isEmpty());
+
+		emp = em.find(Employee.class, 6);
+		em.refresh(emp);
+
+		assertNotNull(emp);
+		assertNotNull(CallbackStorage.getInstance().getClist());
+		assertEquals("PostLoad is overfiring...not accurate", 2, CallbackStorage.getInstance().getClist().size());
+		assertEquals("employeepol", CallbackStorage.getInstance().getClist().get(0));
+		assertEquals("employeepol", CallbackStorage.getInstance().getClist().get(1));
+
+		endTx(em);
+		endEm(em);
+	}
+
+	public void testGenPriKeyAvailInPostPersist()
+	{
+		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+		startTx(em);
+
+		assertNotNull(em);
+
+		Employee emp = new Employee(7, "Maxwell");
+
+		assertEquals(0, emp.getCheck());
+
+		em.persist(emp);
+		int check = emp.getCheck();
+
+		assertNotNull(check);
+		assertTrue(CallbackStorage.getInstance().getClist().contains("gen#"+check));
+
+		endTx(em);
+		endEm(em);
+	}
+	/*Fix Me: aokeke - should fail when persisting with invalid id*/
+//	public void testExceptionCauseTxRollback2()
+//	{
+//		OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+//		startTx(em);
+//		
+//		Employee emp = new Employee(-1, "failure");
+//		
+//		try
+//		{
+//			//persisting an entity with an invalid id throws an exception
+//			em.persist(emp);
+//			endTx(em);
+//			fail("Should have failed..persisting an entity with invalid id");
+//		}
+//		catch(RuntimeException e)
+//		{			
+//			assertFalse(em.isPersistent(emp));
+//			assertTrue("transaction was not marked for rollback", em.getRollbackOnly());
+//			e.printStackTrace();
+//			if(em.getRollbackOnly() == true)
+//				endEm(em);
+//		}
+//		catch(Exception e)
+//		{
+//			assertFalse(em.isPersistent(emp));
+//			assertTrue("transaction was not marked for rollback", em.getRollbackOnly());
+//			e.printStackTrace();
+//			if(em.getRollbackOnly() == true)
+//				endEm(em);
+//		}
+//		
+//		if(em.isActive())
+//			endEm(em);
+//	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityOrderBy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityOrderBy.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityOrderBy.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEntityOrderBy.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,116 @@
+/*
+ * 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.annotations;
+
+import java.util.*;
+
+import org.apache.openjpa.conf.*;
+import org.apache.openjpa.meta.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import org.apache.openjpa.persistence.common.utils.*;
+
+import junit.framework.*;
+
+/**
+ * <p>Test @OrderBy annotation support.</p>
+ *
+ * @author Abe White
+ */
+public class TestEntityOrderBy extends AbstractTestCase
+{
+
+	public TestEntityOrderBy(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+//    private ClassMetaData _meta;
+
+    public void setUp()
+    {
+//        _meta = ((OpenJPAConfiguration) getConfiguration()).
+//            getMetaDataRepositoryInstance().getMetaData(OrderByEntity.class,
+//            null, true);
+    }
+
+ /*   public void testEmptyOrderBy() {
+        String dec = Order.ELEMENT + " asc";
+        assertEquals(dec, _meta.getField("strings").getOrderDeclaration());
+        assertEquals(dec, _meta.getField("pkRels").getOrderDeclaration());
+    }
+
+    public void testSpecifiedOrderBy() {
+        assertEquals("string desc", _meta.getField("stringRels").
+            getOrderDeclaration());
+    }
+*/
+    public void testUse() {
+        // note: functionality thoroughly tested in kodo.meta.TestOrderBy;
+        // this is just a sanity check on JPA use
+        deleteAll(OrderByEntity.class);
+
+        OrderByEntity pc = new OrderByEntity();
+        pc.setId(1L);
+        pc.getStrings().add("2");
+        pc.getStrings().add("1");
+        pc.getStrings().add("3");
+
+        OrderByEntity rel1 = new OrderByEntity();
+        rel1.setId(102L);
+        rel1.setString("2");
+        OrderByEntity rel2 = new OrderByEntity();
+        rel2.setId(101L);
+        rel2.setString("1");
+        OrderByEntity rel3 = new OrderByEntity();
+        rel3.setId(103L);
+        rel3.setString("3");
+        pc.getPKRels().add(rel1);
+        pc.getPKRels().add(rel2);
+        pc.getPKRels().add(rel3);
+        pc.getStringRels().add(rel1);
+        pc.getStringRels().add(rel2);
+        pc.getStringRels().add(rel3);
+
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        em.persistAll(pc, rel1, rel2, rel3);
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(OrderByEntity.class, 1L);
+        List<String> strings = pc.getStrings();
+        assertEquals("1", strings.get(0));
+        assertEquals("2", strings.get(1));
+        assertEquals("3", strings.get(2));
+
+        List<OrderByEntity> pkRels = pc.getPKRels();
+        assertEquals(101L, pkRels.get(0).getId());
+        assertEquals(102L, pkRels.get(1).getId());
+        assertEquals(103L, pkRels.get(2).getId());
+
+        List<OrderByEntity> stringRels = pc.getStringRels();
+        assertEquals("3", stringRels.get(0).getString());
+        assertEquals("2", stringRels.get(1).getString());
+        assertEquals("1", stringRels.get(2).getString());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEnumerated.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEnumerated.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEnumerated.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestEnumerated.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.annotations;
+
+import org.apache.openjpa.persistence.*;
+import java.util.List;
+import javax.persistence.*;
+import junit.framework.*;
+import org.apache.openjpa.persistence.common.utils.*;
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+
+
+
+
+
+/**
+ * Test enums and the @Enumerated annotation.
+ *
+ * @author Abe White
+ */
+public class TestEnumerated extends AbstractTestCase
+{
+
+	public TestEnumerated(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp() {
+        deleteAll(AnnoTest1.class);
+    }
+
+   /** public void testMapping() {
+        ClassMapping cls = (ClassMapping) getConfiguration().
+            getMetaDataRepositoryInstance().getMetaData(AnnoTest1.class,
+            null, true);
+        FieldMapping fm = cls.getDeclaredFieldMapping("enumeration");
+        assertNotNull(fm);
+        assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
+        assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
+        assertEquals(JavaTypes.SHORT, fm.getColumns()[0].getJavaType());
+
+        fm = cls.getDeclaredFieldMapping("ordinalEnumeration");
+        assertNotNull(fm);
+        assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
+        assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
+        assertEquals(JavaTypes.SHORT, fm.getColumns()[0].getJavaType());
+
+        fm = cls.getDeclaredFieldMapping("stringEnumeration");
+        assertNotNull(fm);
+        assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
+        assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
+        assertEquals(JavaTypes.STRING, fm.getColumns()[0].getJavaType());
+    }*/
+
+    public void testBehavior() 
+    {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();        
+        startTx(em);
+        
+        AnnoTest1 pc = new AnnoTest1(1);
+        assertNotNull("pc is null", pc);
+        assertNotNull("InheritanceType.TABLE_PER_CLASS is null", InheritanceType.TABLE_PER_CLASS);
+        assertNotNull("InheritanceType.JOINED is null", InheritanceType.JOINED);
+        pc.setEnumeration(InheritanceType.TABLE_PER_CLASS);
+        pc.setOrdinalEnumeration(InheritanceType.TABLE_PER_CLASS);
+        pc.setStringEnumeration(InheritanceType.JOINED);
+        em.persist(pc);
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        OpenJPAQuery q = em.createQuery("SELECT o FROM AnnoTest1 o"); 
+        assertEquals(1, q.getResultList().size());
+        
+//        AnnoTest1 pc2 = em.find(AnnoTest1.class, new Long(1));
+        AnnoTest1 pc2 = (AnnoTest1) q.getSingleResult();
+        assertNotNull("pc2 is null", pc2);
+        assertEquals(InheritanceType.TABLE_PER_CLASS, pc2.getEnumeration());
+        assertEquals(InheritanceType.TABLE_PER_CLASS, pc2.getOrdinalEnumeration());
+        assertEquals(InheritanceType.JOINED,  pc2.getStringEnumeration());
+        startTx(em);
+        pc2.setEnumeration(InheritanceType.JOINED);
+        pc2.setOrdinalEnumeration(InheritanceType.JOINED);
+        pc2.setStringEnumeration(InheritanceType.TABLE_PER_CLASS);
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+//        pc2 = em.find(AnnoTest1.class, new Long(1));
+        q = em.createQuery("SELECT o FROM AnnoTest1 o"); 
+        pc2 = (AnnoTest1) q.getSingleResult();
+        assertEquals(InheritanceType.JOINED, pc2.getEnumeration());
+        assertEquals(InheritanceType.JOINED, pc2.getOrdinalEnumeration());
+        assertEquals(InheritanceType.TABLE_PER_CLASS, pc2.getStringEnumeration());
+        endEm(em);
+    }
+    
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestFlatInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestFlatInheritance.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestFlatInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestFlatInheritance.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+/**
+ * Test for InheritanceType.SINGLE_TABLE
+ *
+ * @author Steve Kim
+ */
+public class TestFlatInheritance extends AbstractTestCase
+{
+
+	public TestFlatInheritance(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp()
+    {
+        deleteAll(Flat1.class);
+    }
+
+    public void testInheritance() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        Flat1 pc = new Flat1(1);
+        Flat2 pc2 = new Flat2(2);
+        pc.setBasic(10);
+        pc2.setBasic(20);
+        pc2.setBasic2("DOG");
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(Flat1.class, 1);
+        assertEquals(10, pc.getBasic());
+        pc = em.find(Flat1.class, 2);
+        assertEquals(Flat2.class, pc.getClass());
+        assertEquals(20, pc.getBasic());
+        assertEquals("DOG", ((Flat2) pc).getBasic2());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestGenerators.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestGenerators.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestGenerators.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestGenerators.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,103 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import org.apache.openjpa.persistence.common.utils.*;
+
+import junit.framework.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Test for generators
+ *
+ * @author Steve Kim
+ */
+public class TestGenerators extends AbstractTestCase
+{
+
+	public TestGenerators(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp()
+        throws Exception {
+        deleteAll(Generator.class);
+    }
+
+    public void testGet() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        Generator g = new Generator();
+        g.setPk(5);
+        em.persist(g);
+        assertPks(g);
+        endTx(em);
+        endEm(em);
+        assertNew();
+    }
+
+    public void testFlush() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        Generator g = new Generator();
+        g.setPk(5);
+        em.persist(g);
+        em.flush();
+        assertPks(g);
+        endTx(em);
+        endEm(em);
+        assertNew();
+    }
+
+    public void testCommit() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        Generator g = new Generator();
+        g.setPk(5);
+        em.persist(g);
+        endTx(em);
+        endEm(em);
+        assertNew();
+    }
+
+    private void assertNew() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        Query q = em.createQuery("select g from Generator g where "
+            + "g.stringField = 'foo'");
+        for (Object o : q.getResultList())
+            assertPks((Generator) o);
+        endEm(em);
+    }
+
+    private void assertPks(Generator g) {
+        assertNotEquals(0, g.getPk());
+        assertNotNull(g.getPk2());
+       // assertNotEquals(new Integer(0), g);
+        assertNotEquals(0, g.getPk3());
+    }
+
+    private boolean assertNotEquals(long n, long num)
+    {
+    	return(n != num);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestJoinedInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestJoinedInheritance.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestJoinedInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestJoinedInheritance.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,81 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import org.apache.openjpa.persistence.common.utils.*;
+
+import junit.framework.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+
+/**
+ * Test for InheritanceType.JOINED
+ *
+ * @author Steve Kim
+ */
+public class TestJoinedInheritance extends AbstractTestCase
+{
+
+	public TestJoinedInheritance(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp()
+    {
+        new AnnoTest1();
+        new AnnoTest2();
+        new AnnoTest3();
+
+        deleteAll(AnnoTest1.class);
+        deleteAll(AnnoTest2.class);
+    }
+
+    public void testInheritance() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest3 pc = new AnnoTest3();
+        pc.setPk(new Long(1));
+        pc.setBasic(10);
+        pc.setBasic2(20);
+        em.persist(pc);
+
+        AnnoTest2 pc2 = new AnnoTest2();
+        pc2.setPk1(2);
+        pc2.setPk2("bar");
+        pc2.setInverseOneOne(pc);
+        pc.setSubOneOne(pc2);
+        em.persist(pc2);
+
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc2 = em.find(AnnoTest2.class, new AnnoTest2.Oid(2, "bar"));
+        pc = (AnnoTest3) pc2.getInverseOneOne();
+        assertEquals(pc.getInverseOwnerOneOne(), pc2);
+        assertEquals(10, pc.getBasic());
+        assertEquals(20, pc.getBasic2());
+        assertEquals(pc2, pc.getSubOneOne());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestManyToMany.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestManyToMany.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestManyToMany.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestManyToMany.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,123 @@
+/*
+ * 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.annotations;
+
+import java.util.*;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Test for m-m
+ *
+ * @author Steve Kim
+ */
+public class TestManyToMany extends AbstractTestCase
+{
+	public TestManyToMany(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp() {
+        deleteAll(AnnoTest1.class);
+        deleteAll(AnnoTest2.class);
+    }
+
+    public void testManyToMany() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        long lid = 4;
+        AnnoTest1 pc = new AnnoTest1(lid);
+        em.persist(pc);
+        AnnoTest2 pc2;
+        for (int i = 0; i < 3; i++) {
+            pc2 = new AnnoTest2(5 + i, "foo" + i);
+            pc.getManyMany().add(pc2);
+            em.persist(pc2);
+        }
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, new Long(lid));
+        Set<AnnoTest2> many = pc.getManyMany();
+        assertEquals(3, many.size());
+        for (AnnoTest2 manyPc2 : many) {
+            switch ((int) manyPc2.getPk1()) {
+                case 5:
+                    assertEquals("foo0", manyPc2.getPk2());
+                    break;
+                case 6:
+                    assertEquals("foo1", manyPc2.getPk2());
+                    break;
+                case 7:
+                    assertEquals("foo2", manyPc2.getPk2());
+                    break;
+                default:
+                    fail("bad pk:" + manyPc2.getPk1());
+            }
+        }
+        endEm(em);
+    }
+
+    public void testInverseOwnerManyToMany() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        long lid = 4;
+        AnnoTest1 pc = new AnnoTest1(lid);
+        em.persist(pc);
+        AnnoTest2 pc2;
+        for (int i = 0; i < 3; i++) {
+            pc2 = new AnnoTest2(5 + i, "foo" + i);
+            pc2.getManyMany().add(pc);
+            em.persist(pc2);
+        }
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, new Long(lid));
+        Set<AnnoTest2> many = pc.getInverseOwnerManyMany();
+        assertEquals(3, many.size());
+        for (AnnoTest2 manyPc2 : many) {
+            assertTrue(manyPc2.getManyMany().contains(pc));
+            switch ((int) manyPc2.getPk1()) {
+                case 5:
+                    assertEquals("foo0", manyPc2.getPk2());
+                    break;
+                case 6:
+                    assertEquals("foo1", manyPc2.getPk2());
+                    break;
+                case 7:
+                    assertEquals("foo2", manyPc2.getPk2());
+                    break;
+                default:
+                    fail("bad pk:" + manyPc2.getPk1());
+            }
+        }
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestMapKey.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestMapKey.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestMapKey.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestMapKey.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,131 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.jdbc.meta.*;
+import org.apache.openjpa.jdbc.meta.strats.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+
+
+/**
+ * <p>Test the use of the {@link MapKey} annotation.  Note that we have
+ * more thorough Kodo core tests for the mappings themselves.  See
+ * {@link kodo.jdbc.meta.TestMappedByKeyMaps}.
+ *
+ * @author Abe White
+ */
+public class TestMapKey extends AbstractTestCase
+{
+
+	public TestMapKey(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    //private ClassMapping _mapping;
+
+    public void setUp()
+    {
+        deleteAll(Flat1.class);
+        deleteAll(AnnoTest2.class);
+        deleteAll(AnnoTest1.class);
+//        _mapping = ((JDBCConfiguration) getConfiguration()).
+//            getMappingRepositoryInstance().getMapping(AnnoTest1.class,
+//            null, true);
+    }
+
+   /** public void testDefaultMapKeyMapping() {
+        FieldMapping fm = _mapping.getFieldMapping("defaultMapKey");
+        assertTrue(fm.getStrategy() instanceof RelationMapTableFieldStrategy);
+        assertEquals("pk", fm.getKey().getValueMappedBy());
+        assertEquals(_mapping.getRepository().getMetaData(Flat1.class, null,
+            true).getField("pk"), fm.getKey().getValueMappedByMetaData());
+    }
+
+    public void testNamedMapKeyMapping() {
+        FieldMapping fm = _mapping.getFieldMapping("namedMapKey");
+        assertTrue(fm.getStrategy() instanceof RelationMapTableFieldStrategy);
+        assertEquals("basic", fm.getKey().getValueMappedBy());
+        assertEquals(_mapping.getRepository().getMetaData(Flat1.class, null,
+            true).getField("basic"), fm.getKey().getValueMappedByMetaData());
+    }
+
+    public void testInverseOwnerMapKeyMapping() {
+        FieldMapping fm = _mapping.getFieldMapping("inverseOwnerMapKey");
+        assertTrue(fm.getStrategy() instanceof
+            RelationMapInverseKeyFieldStrategy);
+        assertEquals("basic", fm.getKey().getValueMappedBy());
+        assertEquals(_mapping.getRepository().getMetaData(AnnoTest2.class,
+            null, true).getField("basic"), fm.getKey().
+            getValueMappedByMetaData());
+    }**/
+
+    public void testInsertAndRetrieve()
+    {
+
+        Flat1 f1 = new Flat1(1);
+        f1.setBasic(100);
+        Flat1 f2 = new Flat1(2);
+        f2.setBasic(200);
+        AnnoTest2 a1 = new AnnoTest2(1L, "1");
+        a1.setBasic("100");
+        AnnoTest2 a2 = new AnnoTest2(2L, "2");
+        a2.setBasic("200");
+
+        AnnoTest1 pc = new AnnoTest1(1L);
+        pc.getDefaultMapKey().put(f1.getPk(), f1);
+        pc.getDefaultMapKey().put(f2.getPk(), f2);
+        pc.getNamedMapKey().put(f1.getBasic(), f1);
+        pc.getNamedMapKey().put(f2.getBasic(), f2);
+        pc.getInverseOwnerMapKey().put(a1.getBasic(), a1);
+        pc.getInverseOwnerMapKey().put(a2.getBasic(), a2);
+        a1.setOneManyOwner(pc);
+        a2.setOneManyOwner(pc);
+
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+       startTx(em);
+        em.persistAll(new Object[]{ pc, f1, f2, a1, a2 });
+       endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        assertEquals(2, pc.getDefaultMapKey().size());
+        assertEquals(1, pc.getDefaultMapKey().get(1).getPk());
+        assertEquals(2, pc.getDefaultMapKey().get(2).getPk());
+        assertEquals(2, pc.getNamedMapKey().size());
+        assertEquals(100, pc.getNamedMapKey().get(100).getBasic());
+        assertEquals(200, pc.getNamedMapKey().get(200).getBasic());
+        assertEquals(2, pc.getInverseOwnerMapKey().size());
+        assertEquals("100", pc.getInverseOwnerMapKey().get("100").
+            getBasic());
+        assertEquals("200", pc.getInverseOwnerMapKey().get("200").
+            getBasic());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToMany.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToMany.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToMany.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToMany.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,113 @@
+/*
+ * 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.annotations;
+
+import java.util.*;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+
+
+/**
+ * Test for 1-m
+ *
+ * @author Steve Kim
+ */
+public class TestOneToMany extends AbstractTestCase
+{
+	public TestOneToMany(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp() {
+        deleteAll(AnnoTest1.class);
+        deleteAll(AnnoTest2.class);
+    }
+
+    public void testOneToMany() {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        pc.getOneMany().add(new AnnoTest2(15, "foo"));
+        pc.getOneMany().add(new AnnoTest2(20, "foobar"));
+        em.persist(pc);
+        em.persistAll(pc.getOneMany());
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        Collection<AnnoTest2> many = pc.getOneMany();
+        assertEquals(2, many.size());
+        for (AnnoTest2 pc2 : many) {
+            switch ((int) pc2.getPk1()) {
+                case 15:
+                    assertEquals("foo", pc2.getPk2());
+                    break;
+                case 20:
+                    assertEquals("foobar", pc2.getPk2());
+                    break;
+                default:
+                    fail("unknown element:" + pc2.getPk1());
+            }
+        }
+        endEm(em);
+    }
+
+    public void testInverseOwnerOneToMany() {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest2 pc2 = new AnnoTest2(15, "foo");
+        pc.getInverseOwnerOneMany().add(pc2);
+        pc2.setOneManyOwner(pc);
+        pc2 = new AnnoTest2(20, "foobar");
+        pc.getInverseOwnerOneMany().add(pc2);
+        pc2.setOneManyOwner(pc);
+        em.persist(pc);
+        em.persistAll(pc.getInverseOwnerOneMany());
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager)currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        Collection<AnnoTest2> many = pc.getInverseOwnerOneMany();
+        assertEquals(2, many.size());
+        for (AnnoTest2 pc3 : many) {
+            assertEquals(pc, pc3.getOneManyOwner());
+            switch ((int) pc3.getPk1()) {
+                case 15:
+                    assertEquals("foo", pc3.getPk2());
+                    break;
+                case 20:
+                    assertEquals("foobar", pc3.getPk2());
+                    break;
+                default:
+                    fail("unknown element:" + pc3.getPk1());
+            }
+        }
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToOne.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToOne.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToOne.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestOneToOne.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,146 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Test for 1-1
+ *
+ * @author Steve Kim
+ */
+public class TestOneToOne extends AbstractTestCase
+{
+
+	public TestOneToOne(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp() {
+        deleteAll(AnnoTest1.class);
+        deleteAll(AnnoTest2.class);
+    }
+
+    public void testOneToOne() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest2 pc2 = new AnnoTest2(15, "foo");
+        pc.setOneOne(pc2);
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        pc2 = pc.getOneOne();
+        assertNotNull(pc2);
+        assertEquals(15, pc2.getPk1());
+        assertEquals("foo", pc2.getPk2());
+        endEm(em);
+    }
+
+    public void testSelfOneToOne() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest1 pc2 = new AnnoTest1(15);
+        pc.setSelfOneOne(pc2);
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        pc2 = pc.getSelfOneOne();
+        assertNotNull(pc2);
+        assertEquals(new Long(15), pc2.getPk());
+        endEm(em);
+    }
+
+    public void testPKJoinSelfOneToOne() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest1 pc2 = new AnnoTest1(15);
+        pc.setSelfOneOne(pc2);
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        pc2 = pc.getSelfOneOne();
+        assertNotNull(pc2);
+        assertEquals(new Long(15), pc2.getPk());
+        endEm(em);
+    }
+
+    public void testOtherTableOneToOne() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest2 pc2 = new AnnoTest2(15, "foo");
+        pc.setOtherTableOneOne(pc2);
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        pc2 = pc.getOtherTableOneOne();
+        assertNotNull(pc2);
+        assertEquals(15, pc2.getPk1());
+        assertEquals("foo", pc2.getPk2());
+        endEm(em);
+    }
+
+    public void testInverseOneToOne() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc = new AnnoTest1(5);
+        AnnoTest2 pc2 = new AnnoTest2(15, "foo");
+        pc2.setInverseOneOne(pc);
+        em.persist(pc);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        pc2 = pc.getInverseOwnerOneOne();
+        assertNotNull(pc2);
+        assertEquals(15, pc2.getPk1());
+        assertEquals("foo", pc2.getPk2());
+        assertEquals(pc, pc2.getInverseOneOne());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPropertyAccess.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPropertyAccess.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPropertyAccess.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestPropertyAccess.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.annotations;
+
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+
+
+public class TestPropertyAccess extends AbstractTestCase
+{
+	public TestPropertyAccess(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    public void setUp() {
+        deleteAll(PropertyAccess1.class);
+    }
+
+    public void testPropertyAccessBasicCreation() {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        PropertyAccess1 pa1_1 = new PropertyAccess1(10);
+        pa1_1.setName("foo");
+        em.persist(pa1_1);
+        endTx(em);
+
+        // getting a new EM should not be necessary once the extended PC stuff
+        // is complete.
+        em = (OpenJPAEntityManager) currentEntityManager();
+
+        PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
+        assertNotSame(pa1_1, pa1_2);
+        assertNotNull(pa1_2);
+        assertEquals(10, pa1_2.getId());
+        assertEquals("foo", pa1_2.getName());
+    }
+
+    public void testPropertyAccessBasicMutation() {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        PropertyAccess1 pa1_1 = new PropertyAccess1(10);
+        pa1_1.setName("foo");
+        em.persist(pa1_1);
+        endTx(em);
+
+        // getting a new EM should not be necessary once the extended PC stuff
+        // is complete.
+        em = (OpenJPAEntityManager) currentEntityManager();
+
+        startTx(em);
+        PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
+        pa1_2.setName(pa1_2.getName() + "bar");
+        endTx(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        PropertyAccess1 pa1_3 = em.find(PropertyAccess1.class, 10);
+        assertNotSame(pa1_2, pa1_3);
+        assertEquals("foobar", pa1_3.getName());
+    }
+
+    public void testJPQL() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        em.createQuery("select o from PropertyAccess1 o where " +
+            "o.name = 'foo'").getResultList();
+        em.createQuery("select o from PropertyAccess1 o order by " +
+            "o.name asc").getResultList();
+        endEm(em);
+    }
+
+    public void testJPQLWithFieldNameMismatch() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        em.createQuery("select o from PropertyAccess1 o where " +
+            "o.intValue = 0").getResultList();
+        em.createQuery("select o from PropertyAccess1 o order by " +
+            "o.intValue asc").getResultList();
+        endEm(em);
+    }
+
+    /*public void testJDOQL() {
+        PersistenceManager pm = getPM();
+        pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
+            + "where name == 'foo'").execute();
+        pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
+            + "order by name ascending").execute();
+        pm.close();
+    }
+
+    public void testJDOQLWithFieldNameMismatch() {
+        PersistenceManager pm = getPM();
+        pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
+            + "where intValue == 0").execute();
+        pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
+            + "order by intValue asc").execute();
+        pm.close();
+    }*/
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestSerializedLobs.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestSerializedLobs.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestSerializedLobs.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestSerializedLobs.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,146 @@
+/*
+ * 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.annotations;
+
+import java.sql.*;
+import java.util.Date;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.jdbc.sql.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+
+
+/**
+ * Test for serialized, clob, and lob types.
+ *
+ * @author Steve Kim
+ */
+public class TestSerializedLobs extends AbstractTestCase
+{
+
+	public TestSerializedLobs(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+    private static final Date DATE = new Date();
+
+    public void setUp() {
+        deleteAll(AnnoTest1.class);
+    }
+
+    // Serialized fields not being read properly
+    public void testSerialized() {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+        AnnoTest1 pc1 = new AnnoTest1(1);
+        AnnoTest1 pc2 = new AnnoTest1(2);
+        pc1.setSerialized("ASDASD");
+        pc2.setSerialized(DATE);
+        em.persist(pc1);
+        em.persist(pc2);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc1 = em.find(AnnoTest1.class, em.getObjectId(pc1));
+        pc2 = em.find(AnnoTest1.class, em.getObjectId(pc2));
+        assertEquals("ASDASD", pc1.getSerialized());
+        assertEquals(DATE, pc2.getSerialized());
+        endEm(em);
+    }
+
+    public void testBlob()
+        throws Exception {
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+
+        AnnoTest1 pc = new AnnoTest1(1);
+        pc.setBlob("Not Null".getBytes());
+        em.persist(pc);
+        endTx(em);
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class, em.getObjectId(pc));
+        assertEquals("Not Null", new String(pc.getBlob()));
+        Connection conn = (Connection) em.getConnection();
+        Statement stmnt = conn.createStatement();
+        ResultSet rs = stmnt.executeQuery("SELECT BLOBVAL FROM ANNOTEST1 "
+            + "WHERE PK = 1");
+        assertTrue(rs.next());
+
+       /** JDBCConfiguration conf = (JDBCConfiguration) em.getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        if (dict.useGetBytesForBlobs)
+            rs.getBytes(1);
+        else if (dict.useGetObjectForBlobs)
+            rs.getObject(1);
+        else {
+            Blob blob = rs.getBlob(1);
+            blob.getBytes(1L, (int) blob.length());
+        }
+        assertEquals("Not Null", new String(pc.getBlob()));
+
+        try {
+            rs.close();
+        } catch (SQLException e) {
+        }
+        try {
+            stmnt.close();
+        } catch (SQLException e) {
+        }
+        try {
+            conn.close();
+        } catch (SQLException e) {
+        }**/
+        endEm(em);
+    }
+
+    public void testClob()
+        throws Exception {
+        OpenJPAEntityManager em =(OpenJPAEntityManager) currentEntityManager();
+        startTx(em);
+
+        AnnoTest1 pc = new AnnoTest1(1);
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < 1000; i++)
+            buf.append((char) ('a' + (i % 24)));
+        pc.setClob(buf.toString());
+        em.persist(pc);
+        endTx(em);
+        endEm(em);
+
+        em =(OpenJPAEntityManager) currentEntityManager();
+        pc = em.find(AnnoTest1.class,em.getObjectId(pc));
+        String str = pc.getClob();
+        assertEquals(1000, str.length());
+        for (int i = 0; i < str.length(); i++)
+            assertEquals('a' + (i % 24), str.charAt(i));
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestTablePerClassInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestTablePerClassInheritance.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestTablePerClassInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestTablePerClassInheritance.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.annotations;
+
+import org.apache.openjpa.jdbc.conf.*;
+import org.apache.openjpa.jdbc.meta.*;
+import org.apache.openjpa.jdbc.meta.strats.*;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
+import junit.framework.*;
+
+import org.apache.openjpa.persistence.common.utils.*;
+
+
+
+/**
+ * <p>Test that InheritanceType.TABLE_PER_CLASS JPA mapping is translated
+ * correctly.  See the <code>kodo.jdbc.meta.tableperclass</code> test package
+ * for more detailed tests of functionality.</p>
+ *
+ * @author Abe White
+ */
+public class TestTablePerClassInheritance extends AbstractTestCase
+{
+
+	public TestTablePerClassInheritance(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+   /** public void testMapping() {
+        ClassMapping mapping = ((JDBCConfiguration) getConfiguration()).
+            getMappingRepositoryInstance().getMapping(TablePerClass2.class,
+            null, true);
+        assertTrue(mapping.getStrategy() instanceof FullClassStrategy);
+        assertTrue(mapping.getDiscriminator().getStrategy()
+            instanceof NoneDiscriminatorStrategy);
+        assertNull(mapping.getJoinForeignKey());
+        assertNull(mapping.getJoinablePCSuperclassMapping());
+        assertEquals("TPC_BASIC", mapping.getFieldMapping("basic").
+            getColumns()[0].getName());
+        ClassMapping embed = mapping.getFieldMapping("embed").
+            currentEntityManager()beddedMapping();
+        assertEquals("TPC_EMB_BASIC", embed.getFieldMapping("basic").
+            getColumns()[0].getName());
+
+        ClassMapping sup = mapping.getPCSuperclassMapping();
+        assertEquals(TablePerClass1.class, sup.getDescribedType());
+        assertTrue(sup.getStrategy() instanceof FullClassStrategy);
+        assertTrue(sup.getDiscriminator().getStrategy()
+            instanceof NoneDiscriminatorStrategy);
+        assertEquals("TPC_BASIC", sup.getFieldMapping("basic").
+            getColumns()[0].getName());
+        embed = sup.getFieldMapping("embed").currentEntityManager()beddedMapping();
+        assertEquals("TPC_EMB_BASIC", embed.getFieldMapping("basic").
+            getColumns()[0].getName());
+    }**/
+
+    public void testInsertAndRetrieve() {
+        deleteAll(TablePerClass1.class);
+
+        OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
+       startTx(em);
+        TablePerClass1 tpc1 = new TablePerClass1();
+        tpc1.setBasic(1);
+        EmbedValue ev = new EmbedValue();
+        ev.setBasic("11");
+        tpc1.setEmbed(ev);
+        TablePerClass2 tpc2 = new TablePerClass2();
+        tpc2.setBasic(2);
+        tpc2.setBasic2("2");
+        ev = new EmbedValue();
+        ev.setBasic("22");
+        tpc2.setEmbed(ev);
+        em.persistAll(tpc1, tpc2);
+       endTx(em);
+        int id1 = tpc1.getPk();
+        int id2 = tpc2.getPk();
+        endEm(em);
+
+        em = (OpenJPAEntityManager) currentEntityManager();
+        tpc1 = em.find(TablePerClass1.class, id1);
+        assertEquals(1, tpc1.getBasic());
+        assertEquals("11", tpc1.getEmbed().getBasic());
+        tpc2 = (TablePerClass2) em.find(TablePerClass1.class, id2);
+        assertEquals(2, tpc2.getBasic());
+        assertEquals("2", tpc2.getBasic2());
+        assertEquals("22", tpc2.getEmbed().getBasic());
+        endEm(em);
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestVersion.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestVersion.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestVersion.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/TestVersion.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,248 @@
+/*
+ * 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.annotations;
+
+import javax.persistence.* ;
+
+import org.apache.openjpa.jdbc.conf.* ;
+import org.apache.openjpa.jdbc.meta.* ;
+import org.apache.openjpa.jdbc.meta.strats.* ;
+
+import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.* ;
+import junit.framework.* ;
+
+import org.apache.openjpa.persistence.common.utils.* ;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+
+/*
+   Test for opt-lock
+
+   @author Steve Kim
+  */
+public class TestVersion extends AbstractTestCase
+{
+	private Object oid;
+
+	private Object oid1;
+
+	private Object oid2;
+
+	public TestVersion(String name)
+	{
+		super(name, "annotationcactusapp");
+	}
+
+
+
+	public void setUp()
+	{
+		new AnnoTest1();
+		new AnnoTest2();
+		new AnnoTest3();
+
+		deleteAll(AnnoTest1.class);
+		deleteAll(AnnoTest2.class);
+
+		OpenJPAEntityManager em = currentEntityManager();
+		startTx(em);
+		AnnoTest1 test1 = new AnnoTest1();
+		test1.setPk(new Long(5));
+		test1.setBasic(50);
+		test1.setTransient(500);
+		em.persist(test1);
+
+		AnnoTest2 test2 = new AnnoTest2();
+		test2.setPk1(5);
+		test2.setPk2("bar");
+		test2.setBasic("50");
+		em.persist(test2);
+
+		AnnoTest3 test3 = new AnnoTest3();
+		test3.setPk(new Long(3));
+		test3.setBasic2(50);
+		em.persist(test3);
+		oid = em.getObjectId(test1);
+		oid1 = em.getObjectId(test2);
+		oid2 = em.getObjectId(test3);
+
+		endTx(em);
+		endEm(em);
+	}
+
+/*
+ * Fix Me aokeke -- Testcases causes deadlock during runtime CR307216 is used to track this issue.
+ */
+ public void testVersionNumeric()
+	{
+		OpenJPAEntityManager em1 = currentEntityManager();
+		startTx(em1);
+		EntityManager em2 = currentEntityManager();
+
+
+		AnnoTest1 pc1 = em1.find(AnnoTest1.class, oid);
+		AnnoTest1 pc2 = em2.find(AnnoTest1.class, oid);
+		assertEquals(1, pc1.getVersion());
+		assertEquals(1, pc2.getVersion());
+		assertEquals(0, pc1.getTransient());
+		pc1.setBasic(75);
+
+		endTx(em1);
+		endEm(em1);
+
+		startTx(em2);
+		pc2.setBasic(75);
+		em1 = (OpenJPAEntityManager) currentEntityManager();
+		pc1 = em1.find(AnnoTest1.class, oid);
+		assertEquals(2, pc1.getVersion());
+		endEm(em1);
+		try
+		{
+			endTx(em2);
+			fail("Optimistic fail");
+		}
+		catch (RuntimeException re)
+		{}
+		catch (Exception e)
+		{}
+		finally
+		{
+			endEm(em2);
+		}
+	}
+
+	public void testVersionTimestamp()
+	{
+		OpenJPAEntityManager em1 = currentEntityManager();
+		startTx(em1);
+		OpenJPAEntityManager em2 = currentEntityManager();
+
+		AnnoTest2 pc1 = em1.find(AnnoTest2.class, oid1);
+		AnnoTest2 pc2 = em2.find(AnnoTest2.class, oid1);
+		assertNotNull(pc1.getVersion());
+		assertEquals(pc1.getVersion(), pc2.getVersion());
+		pc1.setBasic("75");
+
+		endTx(em1);
+		endEm(em1);
+
+
+		startTx(em2);
+		pc2.setBasic("75");
+
+		em1 = (OpenJPAEntityManager) currentEntityManager();
+		pc1 = em1.find(AnnoTest2.class, oid1);
+		assertTrue(pc1.getVersion().compareTo(pc2.getVersion()) > 0);
+		endEm(em1);
+		try
+		{
+			endTx(em2);
+			fail("Optimistic fail");
+		}
+		catch (RuntimeException re)
+		{}
+		catch (Exception e)
+		{}
+		finally
+		{
+			endEm(em2);
+		}
+	}
+
+	public void testVersionSubclass()
+	{
+		OpenJPAEntityManager em1 = currentEntityManager();
+		startTx(em1);
+		OpenJPAEntityManager em2 = currentEntityManager();
+
+		AnnoTest3 pc1 = em1.find(AnnoTest3.class, oid2);
+		AnnoTest3 pc2 = em2.find(AnnoTest3.class, oid2);
+		assertEquals(1, pc1.getVersion());
+		assertEquals(1, pc2.getVersion());
+		pc1.setBasic2(75);
+
+		endTx(em1);
+		endEm(em1);
+
+
+		startTx(em2);
+		pc2.setBasic2(75);
+
+
+		em1 = (OpenJPAEntityManager) currentEntityManager();
+		pc1 = em1.find(AnnoTest3.class, oid2);
+		assertEquals(2, pc1.getVersion());
+		endEm(em1);
+		try
+		{
+			endTx(em2);
+			fail("Optimistic fail");
+		}
+		catch (RuntimeException re)
+		{}
+		catch (Exception e)
+		{}
+		finally
+		{
+			endEm(em2);
+		}
+	}
+
+	public void testVersionNoChange()
+	{
+		OpenJPAEntityManager em = currentEntityManager();
+		startTx(em);
+
+		AnnoTest1 pc = em.find(AnnoTest1.class, oid);
+		assertEquals(1, pc.getVersion());
+		assertEquals(0, pc.getTransient());
+		pc.setTransient(750);
+		endTx(em);
+		endEm(em);
+
+		em = (OpenJPAEntityManager) currentEntityManager();
+		pc = em.find(AnnoTest1.class, oid);
+		assertEquals(1, pc.getVersion());
+		assertEquals(0, pc.getTransient());
+		endEm(em);
+	}
+
+
+	   public void testNoDefaultVersionWithoutFieldOrColumn()
+	   {
+			OpenJPAEntityManager pm = (OpenJPAEntityManager) currentEntityManager();
+		   ClassMapping cls =  ((JDBCConfigurationImpl)((OpenJPAEntityManagerSPI) OpenJPAPersistence.cast(pm)).getConfiguration()).getMappingRepositoryInstance().getMapping(EmbedOwner.class, null, true);
+		   assertEquals(NoneVersionStrategy.getInstance(),
+				   cls.getVersion().getStrategy()); assertEquals(0,
+						   cls.getVersion().getColumns().length);
+			endEm(pm);
+	   }
+
+	   public void testVersionWithField()
+	   {
+		   OpenJPAEntityManager pm = (OpenJPAEntityManager) currentEntityManager();
+		   ClassMapping cls = ((JDBCConfigurationImpl)((OpenJPAEntityManagerSPI) OpenJPAPersistence.cast(pm)).getConfiguration()).getMappingRepositoryInstance().getMapping(AnnoTest1.class, null, true);
+		   assertTrue(NoneVersionStrategy.getInstance() !=
+			   cls.getVersion().getStrategy()); assertEquals(1,
+					   cls.getVersion().getColumns().length);
+			endEm(pm);
+	   }
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest1.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest1.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest1.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,311 @@
+/*
+ * 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.annotations.common.apps.annotApp.annotype;
+
+import java.util.*;
+
+import javax.persistence.*;
+
+import org.apache.openjpa.persistence.jdbc.*;
+
+@Entity
+@Table(name = "ANNOTEST1")
+@Inheritance(strategy = InheritanceType.JOINED)
+@DiscriminatorColumn(name = "ANNOCLS")
+@DiscriminatorValue("ANNO1")
+@SecondaryTables({ @SecondaryTable(name = "OTHER_ANNOTEST1",
+    pkJoinColumns = @PrimaryKeyJoinColumn(name = "OTHER_PK",
+        referencedColumnName = "PK")) })
+public class AnnoTest1 {
+
+    @Id
+    @Column(name = "PK")
+    private Long pk;
+
+    @Version
+    @Column(name = "ANNOVER")
+    private int version;
+
+    @Basic
+    private int basic;
+
+    @Transient
+    private int trans;
+
+    @Basic
+    @Column(name = "OTHERVALUE", table = "OTHER_ANNOTEST1")
+    private int otherTableBasic;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "SELFONEONE_PK", referencedColumnName = "PK")
+    private AnnoTest1 selfOneOne;
+
+    @OneToOne
+    @PrimaryKeyJoinColumn
+    private AnnoTest1 pkJoinSelfOneOne;
+
+    @OneToOne
+    @JoinColumns({
+    @JoinColumn(name = "ONEONE_PK1", referencedColumnName = "PK1"),
+    @JoinColumn(name = "ONEONE_PK2", referencedColumnName = "PK2") })
+    private AnnoTest2 oneOne;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    @JoinColumns({
+    @JoinColumn(name = "OTHERONE_PK1", referencedColumnName = "PK1",
+        table = "OTHER_ANNOTEST1"),
+    @JoinColumn(name = "OTHERONE_PK2", referencedColumnName = "PK2",
+        table = "OTHER_ANNOTEST1") })
+    private AnnoTest2 otherTableOneOne;
+
+    @OneToOne(mappedBy = "inverseOneOne", fetch = FetchType.LAZY)
+    private AnnoTest2 inverseOwnerOneOne;
+
+    @Lob
+    @Column(name = "BLOBVAL")
+    private byte[] blob;
+
+    @Basic
+    @Lob
+    @Column(name = "SERVAL")
+    private Object serial;
+
+    @Column(name = "CLOBVAL")
+    @Lob
+    private String clob;
+
+    // un-annotated enum should be persisted by default
+    @Column(name = "ENUMVAL")
+    private InheritanceType enumeration;
+
+    @Enumerated
+    @Column(name = "ORD_ENUMVAL")
+    private InheritanceType ordinalEnumeration;
+
+    @Enumerated(EnumType.STRING)
+    @Column(name = "STR_ENUMVAL")
+    private InheritanceType stringEnumeration;
+
+    @OneToMany
+    @ElementJoinColumn(name = "ONEMANY_PK", referencedColumnName = "PK")
+    private Set<AnnoTest2> oneMany = new HashSet();
+
+    @OneToMany(mappedBy = "oneManyOwner")
+    private Set<AnnoTest2> inverseOwnerOneMany = new HashSet();
+
+    @ManyToMany
+    @JoinTable(name = "ANNOTEST1_MANYMANY",
+        joinColumns = @JoinColumn(name = "MANY_PK"),
+        inverseJoinColumns = {
+        @JoinColumn(name = "MANY_PK1", referencedColumnName = "PK1"),
+        @JoinColumn(name = "MANY_PK2", referencedColumnName = "PK2") })
+    private Set<AnnoTest2> manyMany = new HashSet();
+
+    @ManyToMany(mappedBy = "manyMany")
+    private Set<AnnoTest2> inverseOwnerManyMany = new HashSet();
+
+    @MapKey
+    @OneToMany
+    private Map<Integer, Flat1> defaultMapKey = new HashMap();
+
+    @MapKey(name = "basic")
+    @OneToMany
+    private Map<Integer, Flat1> namedMapKey = new HashMap();
+
+    @MapKey(name = "basic")
+    @OneToMany(mappedBy = "oneManyOwner")
+    private Map<String, AnnoTest2> inverseOwnerMapKey = new HashMap();
+
+    public AnnoTest1() {
+    }
+
+    public AnnoTest1(long pk) {
+        this.pk = new Long(pk);
+    }
+
+//    public AnnoTest1(Long pk) {
+//        this.pk = pk;
+//    }
+
+    public void setPk(Long val) {
+        pk = val;
+    }
+
+    public Long getPk() {
+        return pk;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setBasic(int i) {
+        basic = i;
+    }
+
+    public int getBasic() {
+        return basic;
+    }
+
+    public void setTransient(int i) {
+        trans = i;
+    }
+
+    public int getTransient() {
+        return trans;
+    }
+
+    public void setOtherTableBasic(int i) {
+        otherTableBasic = i;
+    }
+
+    public int getOtherTableBasic() {
+        return otherTableBasic;
+    }
+
+    public void setSelfOneOne(AnnoTest1 other) {
+        selfOneOne = other;
+    }
+
+    public AnnoTest1 getSelfOneOne() {
+        return selfOneOne;
+    }
+
+    public void setPKJoinSelfOneOne(AnnoTest1 other) {
+        pkJoinSelfOneOne = other;
+    }
+
+    public AnnoTest1 getPKJoinSelfOneOne() {
+        return pkJoinSelfOneOne;
+    }
+
+    public void setOneOne(AnnoTest2 other) {
+        oneOne = other;
+    }
+
+    public AnnoTest2 getOneOne() {
+        return oneOne;
+    }
+
+    public void setOtherTableOneOne(AnnoTest2 other) {
+        otherTableOneOne = other;
+    }
+
+    public AnnoTest2 getOtherTableOneOne() {
+        return otherTableOneOne;
+    }
+
+    public void setInverseOwnerOneOne(AnnoTest2 other) {
+        inverseOwnerOneOne = other;
+    }
+
+    public AnnoTest2 getInverseOwnerOneOne() {
+        return inverseOwnerOneOne;
+    }
+
+    public void setBlob(byte[] bytes) {
+        blob = bytes;
+    }
+
+    public byte[] getBlob() {
+        return blob;
+    }
+
+    public void setSerialized(Object o) {
+        serial = o;
+    }
+
+    public Object getSerialized() {
+        return serial;
+    }
+
+    public void setClob(String s) {
+        clob = s;
+    }
+
+    public String getClob() {
+        return clob;
+    }
+
+    public InheritanceType getEnumeration() {
+        return enumeration;
+    }
+
+    public void setEnumeration(InheritanceType val) {
+        enumeration = val;
+    }
+
+    public InheritanceType getOrdinalEnumeration() {
+        return ordinalEnumeration;
+    }
+
+    public void setOrdinalEnumeration(InheritanceType val) {
+        ordinalEnumeration = val;
+    }
+
+    public InheritanceType getStringEnumeration() {
+        return stringEnumeration;
+    }
+
+    public void setStringEnumeration(InheritanceType val) {
+        stringEnumeration = val;
+    }
+
+    public Set<AnnoTest2> getOneMany() {
+        return oneMany;
+    }
+
+    public Set<AnnoTest2> getInverseOwnerOneMany() {
+        return inverseOwnerOneMany;
+    }
+
+    public Set<AnnoTest2> getManyMany() {
+        return manyMany;
+    }
+
+    public Set<AnnoTest2> getInverseOwnerManyMany() {
+        return inverseOwnerManyMany;
+    }
+
+    public Map<Integer, Flat1> getDefaultMapKey() {
+        return this.defaultMapKey;
+    }
+
+    public void setDefaultMapKey(Map<Integer, Flat1> defaultMapKey) {
+        this.defaultMapKey = defaultMapKey;
+    }
+
+    public Map<Integer, Flat1> getNamedMapKey() {
+        return this.namedMapKey;
+    }
+
+    public void setNamedMapKey(Map<Integer, Flat1> namedMapKey) {
+        this.namedMapKey = namedMapKey;
+    }
+
+    public Map<String, AnnoTest2> getInverseOwnerMapKey() {
+        return this.inverseOwnerMapKey;
+    }
+
+    public void setInverseOwnerMapKey(
+        Map<String, AnnoTest2> inverseOwnerMapKey) {
+        this.inverseOwnerMapKey = inverseOwnerMapKey;
+    }
+}
+

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest2.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest2.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,165 @@
+/*
+ * 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.annotations.common.apps.annotApp.annotype;
+
+import java.util.*;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "ANNOTEST2")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "ANNOCLS")
+@DiscriminatorValue("ANNO2")
+@IdClass(AnnoTest2.Oid.class)
+public class AnnoTest2 {
+
+    @Id
+    @Column(name = "PK1")
+    protected long pk1;
+
+    @Id
+    @Column(name = "PK2")
+    protected String pk2;
+
+    @Version
+    @Column(name = "ANNOVER")
+    protected Date version;
+
+    @Basic
+    protected String basic;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "INVERSEONEONE_PK", referencedColumnName = "PK")
+    protected AnnoTest1 inverseOneOne;
+
+    @ManyToOne(fetch = FetchType.LAZY)
+    @JoinColumn(name = "MANYONEONE_PK", referencedColumnName = "PK")
+    protected AnnoTest1 oneManyOwner;
+
+    @ManyToMany
+    @JoinTable(name = "ANNOTEST2_MANYMANY",
+        joinColumns = {
+        @JoinColumn(name = "MANY_PK1", referencedColumnName = "PK1"),
+        @JoinColumn(name = "MANY_PK2", referencedColumnName = "PK2") },
+        inverseJoinColumns =
+        @JoinColumn(name = "MANYE_PK", referencedColumnName = "PK"))
+    protected Set<AnnoTest1> manyMany = new HashSet();
+
+    public AnnoTest2() {
+    }
+
+    public AnnoTest2(long pk1, String pk2) {
+        this.pk1 = pk1;
+        this.pk2 = pk2;
+    }
+
+    public void setPk1(long val) {
+        pk1 = val;
+    }
+
+    public long getPk1() {
+        return pk1;
+    }
+
+    public void setPk2(String str) {
+        pk2 = str;
+    }
+
+    public String getPk2() {
+        return pk2;
+    }
+
+    public Date getVersion() {
+        return version;
+    }
+
+    public void setBasic(String s) {
+        basic = s;
+    }
+
+    public String getBasic() {
+        return basic;
+    }
+
+    public void setInverseOneOne(AnnoTest1 other) {
+        inverseOneOne = other;
+    }
+
+    public AnnoTest1 getInverseOneOne() {
+        return inverseOneOne;
+    }
+
+    public void setOneManyOwner(AnnoTest1 other) {
+        oneManyOwner = other;
+    }
+
+    public AnnoTest1 getOneManyOwner() {
+        return oneManyOwner;
+    }
+
+    public Set getManyMany() {
+        return manyMany;
+    }
+
+    public static class Oid {
+
+        public long pk1;
+        public String pk2;
+
+        public Oid() {
+        }
+
+        public Oid(long pk1, String pk2) {
+            this.pk1 = pk1;
+            this.pk2 = pk2;
+        }
+
+        public Oid(String str) {
+            if (str != null) {
+                int index = str.indexOf(",");
+                pk1 = Long.parseLong(str.substring(0, index));
+                pk2 = str.substring(index + 1);
+                if ("null".equals(pk2))
+                    pk2 = null;
+            }
+        }
+
+        public boolean equals(Object o) {
+            if (o == this)
+                return true;
+            if (!(o instanceof Oid))
+                return false;
+            Oid other = (Oid) o;
+            if (pk1 != other.pk1)
+                return false;
+            if (pk2 == null)
+                return other.pk2 == null;
+            return pk2.equals(other.pk2);
+        }
+
+        public int hashCode() {
+            return ((int) pk1) + (pk2 == null ? 0 : pk2.hashCode());
+        }
+
+        public String toString() {
+            return pk1 + "," + (pk2 == null ? "null" : pk2);
+        }
+    }
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest3.java?rev=627979&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest3.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/annotations/common/apps/annotApp/annotype/AnnoTest3.java Fri Feb 15 01:19:55 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.annotations.common.apps.annotApp.annotype;
+
+import javax.persistence.*;
+
+@Entity
+@DiscriminatorValue("ANNO3")
+@Table(name = "ANNOTEST3")
+@PrimaryKeyJoinColumns(@PrimaryKeyJoinColumn(name = "SUB_PK",
+    referencedColumnName = "PK"))
+public class AnnoTest3 extends AnnoTest1 {
+
+    @Basic
+    @Column(name = "SUBBASIC")
+    protected int basic2;
+
+    @OneToOne(fetch = FetchType.LAZY)
+    protected AnnoTest2 subOneOne;
+
+    public AnnoTest3() {
+    }
+
+    public AnnoTest3(long pk) {
+        super(pk);
+    }
+
+    public AnnoTest3(Long pk) {
+        super(pk);
+    }
+
+    public void setBasic2(int i) {
+        basic2 = i;
+    }
+
+    public int getBasic2() {
+        return basic2;
+    }
+
+    public AnnoTest2 getSubOneOne() {
+        return subOneOne;
+    }
+
+    public void setSubOneOne(AnnoTest2 anno2) {
+        subOneOne = anno2;
+    }
+}



Mime
View raw message