openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r668268 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/data...
Date Mon, 16 Jun 2008 19:29:24 GMT
Author: ppoddar
Date: Mon Jun 16 12:29:24 2008
New Revision: 668268

URL: http://svn.apache.org/viewvc?rev=668268&view=rev
Log:
OPENJPA-625: remove Embedded collection members throws exception in PCData

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEmbeddedCollection.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddedEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddingOwnerEntity.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java?rev=668268&r1=668267&r2=668268&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractPCData.java
Mon Jun 16 12:29:24 2008
@@ -176,10 +176,13 @@
                     ret.add((Locale) itr.next());
                 return ret;
             case JavaTypes.PC:
-                if (vmd.isEmbedded())
-                    for (Iterator itr=data.iterator(); itr.hasNext();)
+                if (vmd.isEmbedded()) {
+                    for (Iterator itr=data.iterator(); itr.hasNext();) {
                         ret.add(toEmbeddedField(sm, vmd, itr.next(), fetch
                             , context));
+                    }
+                    return ret;
+                }
                 // no break
             case JavaTypes.PC_UNTYPED:
                 Object[] r = toRelationFields(sm, data, fetch);

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEmbeddedCollection.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEmbeddedCollection.java?rev=668268&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEmbeddedCollection.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEmbeddedCollection.java
Mon Jun 16 12:29:24 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.datacache;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.StoreCacheImpl;
+import org.apache.openjpa.persistence.datacache.common.apps.EmbeddedEntity;
+import org.apache.openjpa.persistence.datacache.common.apps.EmbeddingOwnerEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * Test removing members of embedded collection with active DataCache.
+ * 
+ * Originally reported in 
+ * <HREF="http://issues.apache.org/jira/browse/OPENJPA-625">OPENJPA-625</A>
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class TestEmbeddedCollection extends SingleEMFTestCase {
+
+	private static final int SIZE = 4;
+	private static OpenJPAEntityManagerFactorySPI emf = null;
+	/**
+	 * Sets up EntityManagerFactory: with DataCache.
+	 */
+	public void setUp() throws Exception {
+		if (emf == null) {
+			super.setUp("openjpa.jdbc.SynchronizeMappings", "buildSchema",
+					"openjpa.RuntimeUnenhancedClasses", "unsupported",
+					"openjpa.DataCache", "true", "openjpa.RemoteCommitProvider",
+					"sjvm", "openjpa.jdbc.UpdateManager", "constraint",
+					EmbeddingOwnerEntity.class, 
+					EmbeddedEntity.class,
+					CLEAR_TABLES);
+			emf = super.emf;
+			
+			createData();
+		}
+		assertNotNull(emf);
+		assertNotNull(emf.getStoreCache());
+		assertTrue(isDataCacheActive(emf));
+	}
+
+	boolean isDataCacheActive(OpenJPAEntityManagerFactorySPI emf) {
+		return ((StoreCacheImpl) emf.getStoreCache()).getDelegate() != null
+				&& emf.getConfiguration().getDataCacheManagerInstance()
+						.getSystemDataCache() != null;
+	}
+	
+	@Override
+	public void tearDown() throws Exception {
+		
+	}
+	
+	public void createData() {
+		EmbeddingOwnerEntity owner = new EmbeddingOwnerEntity();
+		for (int i = 0; i < SIZE; i++) {
+			EmbeddedEntity member = new EmbeddedEntity();
+			member.setMarker("Member-" + i);
+			owner.addMember(member);
+		}
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		em.persist(owner);
+		em.getTransaction().commit();
+		Object id = OpenJPAPersistence.cast(em).getObjectId(owner);
+		em.clear();
+
+		EmbeddingOwnerEntity test = em.find(EmbeddingOwnerEntity.class, id);
+		assertNotNull(test);
+		List<EmbeddedEntity> members = test.getMembers();
+		assertNotNull(members);
+		assertEquals(SIZE, members.size());
+		for (int i = 0; i < SIZE; i++)
+			members.get(i).getMarker().equals("Member-" + i);
+	}
+
+	public void testRemoveMemberFromEmbeddedCollection() {
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		List<EmbeddingOwnerEntity> result = em.createQuery(
+				"SELECT p FROM EmbeddingOwnerEntity p").getResultList();
+
+		assertNotNull(result);
+		assertFalse(result.isEmpty());
+
+		EmbeddingOwnerEntity owner = result.get(0);
+		Object id = owner.getId();
+		
+		assertTrue(emf.getStoreCache().contains(EmbeddingOwnerEntity.class, id));
+		
+		List<EmbeddedEntity> members = owner.getMembers();
+		members.remove(0);
+		owner.removeMember(0);
+		owner.removeMember(members.get(0));
+		em.getTransaction().commit();
+		
+		assertEquals(owner.getMembers().size(), SIZE-3); 
+	}
+
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddedEntity.java?rev=668268&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddedEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddedEntity.java
Mon Jun 16 12:29:24 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.datacache.common.apps;
+
+import javax.persistence.Embeddable;
+import javax.persistence.Entity;
+
+import org.apache.openjpa.persistence.datacache.TestEmbeddedCollection;
+
+/**
+ * Embeddable persistent entity.
+ * 
+ * Used in {@link TestEmbeddedCollection}.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+@Embeddable
+public class EmbeddedEntity {
+	private String marker;
+
+	public String getMarker() {
+		return marker;
+	}
+
+	public void setMarker(String marker) {
+		this.marker = marker;
+	}
+}

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddingOwnerEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddingOwnerEntity.java?rev=668268&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddingOwnerEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/common/apps/EmbeddingOwnerEntity.java
Mon Jun 16 12:29:24 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.datacache.common.apps;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+import org.apache.openjpa.persistence.datacache.TestEmbeddedCollection;
+
+/**
+ * Persistent entity that embeds a persistent collection of embeddable.
+ *  
+ * Used in {@link TestEmbeddedCollection}. 
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+public class EmbeddingOwnerEntity {
+	@Id
+	@GeneratedValue
+	private long id;
+	
+	@PersistentCollection(elementEmbedded = true, 
+			elementType = EmbeddedEntity.class, 
+			fetch = FetchType.LAZY)
+	private List<EmbeddedEntity> members;
+
+	public List<EmbeddedEntity> getMembers() {
+		return members;
+	}
+
+	public void addMember(EmbeddedEntity member) {
+		if (members == null)
+			members = new ArrayList<EmbeddedEntity>();
+		this.members.add(member);
+	}
+	
+	public void removeMember(EmbeddedEntity member) {
+		if (members != null)
+			members.remove(member);
+	}
+	
+	public EmbeddedEntity removeMember(int member) {
+		return (members != null) ? members.remove(member) : null;
+	}
+
+	public long getId() {
+		return id;
+	} 
+}



Mime
View raw message