openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r683902 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persis...
Date Fri, 08 Aug 2008 08:06:19 GMT
Author: ppoddar
Date: Fri Aug  8 01:06:18 2008
New Revision: 683902

URL: http://svn.apache.org/viewvc?rev=683902&view=rev
Log:
OPENJPA-677: While loading intermediate data be more strict about when superclass oid  can
be allowed

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestIdentityWithSingleTableStrategy.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/Admin.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/ComputerUser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/RegularUser.java
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java?rev=683902&r1=683901&r2=683902&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationFieldStrategy.java
Fri Aug  8 01:06:18 2008
@@ -556,8 +556,10 @@
         ClassMapping relMapping = field.getTypeMapping();
         Object oid = null;
         if (relMapping.isMapped()) {
+        	boolean subs = field.getPolymorphic() != ValueMapping.POLY_FALSE 
+        		&& relMapping.getPCSubclasses().length > 0;
             oid = relMapping.getObjectId(store, res, field.getForeignKey(),
-                field.getPolymorphic() != ValueMapping.POLY_FALSE, null);
+                subs, null);
         } else {
             Column[] cols = field.getColumns();
             if (relMapping.getIdentityType() == ClassMapping.ID_DATASTORE) {

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestIdentityWithSingleTableStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestIdentityWithSingleTableStrategy.java?rev=683902&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestIdentityWithSingleTableStrategy.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/TestIdentityWithSingleTableStrategy.java
Fri Aug  8 01:06:18 2008
@@ -0,0 +1,86 @@
+/*
+ * 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.inheritance;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.inheritance.entity.Admin;
+import org.apache.openjpa.persistence.inheritance.entity.ComputerUser;
+import org.apache.openjpa.persistence.inheritance.entity.RegularUser;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Tests entities obtained via find(), getReference() or navigated to via
+ * relation traversal refers to the same instances.
+ * 
+ * Original reported in the context of entities of a inheritance hierarchy with
+ * SINGLE_TABLE strategy.
+ * 
+ * <A HREF="http://issues.apache.org/jira/browse/OPENJPA-677">OPENJPA-677</A>
+ * 
+ * @author Przemek Koprowski
+ * @author Pinaki Poddar
+ * 
+ */
+public class TestIdentityWithSingleTableStrategy extends SingleEMFTestCase {
+	private Admin admin;
+	private RegularUser user;
+
+	public void setUp() {
+		super.setUp(CLEAR_TABLES, Admin.class, RegularUser.class,
+				ComputerUser.class);
+
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		admin = new Admin();
+		user = new RegularUser();
+		user.setAdmin(admin);
+		admin.addRegularUser(user);
+		em.persist(admin);
+		em.persist(user);
+		em.getTransaction().commit();
+		em.close();
+	}
+
+	@Override
+	public void tearDown() {
+		// problem deleting table in MySQL
+	}
+
+	public void testFindAndNaviagtedEntityIdential() {
+		EntityManager em1 = emf.createEntityManager();
+		RegularUser regularUserFromFind = (RegularUser) em1.find(
+				RegularUser.class, user.getOid());
+		Admin adminFromFind = em1.find(Admin.class, admin.getOid());
+		Admin adminFromMethodBean = regularUserFromFind.getAdmin();
+		assertTrue(adminFromFind == adminFromMethodBean);
+		em1.close();
+	}
+
+	public void testReferenceAndNaviagtedEntityIdential() {
+		EntityManager em1 = emf.createEntityManager();
+		RegularUser regularUserFromFind = (RegularUser) em1.find(
+				RegularUser.class, user.getOid());
+		Admin adminFromGetReference = em1.getReference(Admin.class, admin
+				.getOid());
+		Admin adminFromMethodBean = regularUserFromFind.getAdmin();
+		assertTrue(adminFromGetReference == adminFromMethodBean);
+		em1.close();
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/Admin.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/Admin.java?rev=683902&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/Admin.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/Admin.java
Fri Aug  8 01:06:18 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.inheritance.entity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+
+@Entity
+@DiscriminatorValue("admin")
+public class Admin extends ComputerUser {
+	@OneToMany(mappedBy = "admin")
+	protected Set<RegularUser> regularUsers = new HashSet<RegularUser>();
+
+	public boolean addRegularUser(RegularUser version) {
+		return regularUsers.add(version);
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/ComputerUser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/ComputerUser.java?rev=683902&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/ComputerUser.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/ComputerUser.java
Fri Aug  8 01:06:18 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.inheritance.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
+@Entity
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+public abstract class ComputerUser {
+
+	@GeneratedValue(strategy = GenerationType.AUTO)
+	@Id
+	private Integer oid;
+
+	public Integer getOid() {
+		return oid;
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/RegularUser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/RegularUser.java?rev=683902&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/RegularUser.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/inheritance/entity/RegularUser.java
Fri Aug  8 01:06:18 2008
@@ -0,0 +1,43 @@
+/*
+ * 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.inheritance.entity;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
+
+import org.apache.openjpa.persistence.jdbc.Nonpolymorphic;
+
+@Entity
+@DiscriminatorValue("user")
+public class RegularUser extends ComputerUser {
+
+	@ManyToOne(fetch = FetchType.LAZY)
+	private Admin admin;
+
+	public Admin getAdmin() {
+		return admin;
+	}
+
+	public void setAdmin(Admin admin) {
+		this.admin = admin;
+	}
+
+}



Mime
View raw message