openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r688809 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel: TestDynamicFetchPlan.java common/apps/FetchA.java common/apps/FetchB.java common/apps/FetchBase.java
Date Mon, 25 Aug 2008 18:11:00 GMT
Author: ppoddar
Date: Mon Aug 25 11:10:59 2008
New Revision: 688809

URL: http://svn.apache.org/viewvc?rev=688809&view=rev
Log:
OPENJPA-704:Adding test case

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchA.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchB.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchBase.java

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java?rev=688809&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestDynamicFetchPlan.java
Mon Aug 25 11:10:59 2008
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel;
+
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchA;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchB;
+import org.apache.openjpa.persistence.kernel.common.apps.FetchBase;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Tests behavior of FetchPlan constructed dynamically by adding fields.
+ * 
+ * Originally reported by Michael Vorburger in 
+ * <A HREF="http://n2.nabble.com/Fetch-Group-questions-tc534861.html">OpenJPA 
+ * user group</A>
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class TestDynamicFetchPlan extends SingleEMFTestCase {
+	private static final String JPQL = "select a from FetchA a";
+	
+	public void setUp() {
+		super.setUp(CLEAR_TABLES, FetchBase.class, FetchA.class, FetchB.class);
+		createData();
+	}
+
+	public void createData() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		FetchA a1 = new FetchA();
+		a1.setText("a1");
+		FetchB b1 = new FetchB();
+		b1.setText("b1");
+		a1.setB(b1);
+		em.persist(a1);
+		em.persist(b1);
+		em.getTransaction().commit();
+	}
+
+	public void testFetchBySubClassFieldB() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class, "b");
+		fp.addField(FetchB.class, "text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertNull(a.getText());
+		assertEquals("b1", b.getText());
+	}
+
+	public void testFetchBySubClassFieldA() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class, "b");
+		fp.addField(FetchA.class, "text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertEquals("a1", a.getText());
+		assertNull(b.getText());
+	}
+	
+	public void testFetchBySuperClassField() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class, "b");
+		fp.addField(FetchBase.class, "text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertEquals("a1", a.getText());
+		assertEquals("b1", b.getText());
+	}
+	
+	public void testFetchBySubClassFieldNameB() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class.getName() + ".b");
+		fp.addField(FetchB.class.getName() + ".text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertNull(a.getText());
+		assertEquals("b1", b.getText());
+	}
+
+	public void testFetchBySubClassFieldNameA() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class.getName() + ".b");
+		fp.addField(FetchA.class.getName() + ".text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertEquals("a1", a.getText());
+		assertNull(b.getText());
+	}
+	
+	public void testFetchBySuperClassFieldName() {
+		OpenJPAEntityManager em = emf.createEntityManager();
+		FetchPlan fp = em.getFetchPlan();
+		fp.clearFetchGroups();
+		fp.clearFields();
+		fp.addField(FetchA.class.getName() + ".b");
+		fp.addField(FetchBase.class.getName() + ".text");
+
+		FetchA a = (FetchA) em.createQuery(JPQL).getSingleResult();
+		em.close();
+
+		FetchB  b = a.getB();
+		assertNotNull(b);
+		assertEquals("a1", a.getText());
+		assertEquals("b1", b.getText());
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchA.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchA.java?rev=688809&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchA.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchA.java
Mon Aug 25 11:10:59 2008
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel.common.apps;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+
+/**
+ * A persistent entity to verify behavior of dynamically constructed FetchPlan 
+ * by adding fields.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
+public class FetchA extends FetchBase {
+	@OneToOne
+	private FetchB b;
+
+	public FetchB getB() {
+		return b;
+	}
+
+	public void setB(FetchB b) {
+		this.b = b;
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchB.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchB.java?rev=688809&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchB.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchB.java
Mon Aug 25 11:10:59 2008
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel.common.apps;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+/**
+ * A persistent entity to verify behavior of dynamically constructed FetchPlan 
+ * by adding fields.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
+public class FetchB extends FetchBase {
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchBase.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchBase.java?rev=688809&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchBase.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/common/apps/FetchBase.java
Mon Aug 25 11:10:59 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.kernel.common.apps;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * A base entity to verify behavior of dynamically constructed FetchPlan by
+ * adding fields.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+
+@MappedSuperclass
+public class FetchBase {
+	@Id
+	@GeneratedValue
+	private long id;
+	
+	private String text;
+
+	public String getText() {
+		return text;
+	}
+
+	public void setText(String text) {
+		this.text = text;
+	}
+
+	public long getId() {
+		return id;
+	}
+}



Mime
View raw message