openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpala...@apache.org
Subject svn commit: r1171939 - in /openjpa/branches/1.1.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps...
Date Sat, 17 Sep 2011 10:20:06 GMT
Author: rpalache
Date: Sat Sep 17 10:20:06 2011
New Revision: 1171939

URL: http://svn.apache.org/viewvc?rev=1171939&view=rev
Log:
OPENJPA-209 Detect identical instances being added to L1 cache multiple times during a load
session. Applying Pinaki poddar's patch to 1.1.x branch.

Added:
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwned.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwner.java
    openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestProjectionQueryWithIdenticalResult.java
Modified:
    openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java
    openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java

Modified: openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java?rev=1171939&r1=1171938&r2=1171939&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java
(original)
+++ openjpa/branches/1.1.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ProjectionResultObjectProvider.java
Sat Sep 17 10:20:06 2011
@@ -70,6 +70,8 @@ class ProjectionResultObjectProvider
     public Object getResultObject()
         throws Exception {
         Result res = getResult();
+        // for a projection, Result has no base mapping
+        res.setBaseMapping(null);
         int idx = res.indexOf();
         Object[] arr = new Object[_exps[idx].projections.length];
         for (int i = 0; i < _exps[idx].projections.length; i++)

Modified: openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=1171939&r1=1171938&r2=1171939&view=diff
==============================================================================
--- openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/branches/1.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Sat Sep 17 10:20:06 2011
@@ -311,7 +311,9 @@ public class StateManagerImpl
 
         // initialize our state and add ourselves to the broker's cache
         setPCState(state);
-        _broker.setStateManager(_id, this, BrokerImpl.STATUS_INIT);
+        if (_broker.getStateManagerImplById(getObjectId(), false) == null) {
+            _broker.setStateManager(_id, this, BrokerImpl.STATUS_INIT);
+        }
         if (state == PCState.PNEW)
             fireLifecycleEvent(LifecycleEvent.AFTER_PERSIST);
 

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwned.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwned.java?rev=1171939&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwned.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwned.java
Sat Sep 17 10:20:06 2011
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jdbc.common.apps;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+/**
+ * Entity which is traget of a unidirectional one-to-one relation.
+ * 
+ * Used in
+ * @see org.apache.openjpa.persistence.query.TestProjectionQueryWithIdenticalResult
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+public class UnidirectionalOneToOneOwned {
+	@Id
+	@GeneratedValue
+	private long id;
+	
+	private String marker;
+	
+	@Version
+	private int version;
+	
+	public String getMarker() {
+		return marker;
+	}
+
+	public void setMarker(String marker) {
+		this.marker = marker;
+	}
+
+	public long getId() {
+		return id;
+	}
+
+	public int getVersion() {
+		return version;
+	}
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwner.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwner.java?rev=1171939&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwner.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/UnidirectionalOneToOneOwner.java
Sat Sep 17 10:20:06 2011
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package org.apache.openjpa.persistence.jdbc.common.apps;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.Version;
+
+/**
+ * Persistent entity with unidirectional one-to-one relation.
+ * 
+ * Used in
+ * @see org.apache.openjpa.persistence.query.TestProjectionQueryWithIdenticalResult
+ *  
+ * @author Pinaki Poddar
+ *
+ */
+@Entity
+public class UnidirectionalOneToOneOwner {
+	@Id
+	@GeneratedValue
+	private long id;
+	
+	private String marker;
+	
+	@Version
+	private int version;
+	
+	@OneToOne(cascade=CascadeType.ALL)
+	private UnidirectionalOneToOneOwned owned;
+
+	public String getMarker() {
+		return marker;
+	}
+
+	public void setMarker(String marker) {
+		this.marker = marker;
+	}
+
+	public UnidirectionalOneToOneOwned getOwned() {
+		return owned;
+	}
+
+	public void setOwned(UnidirectionalOneToOneOwned owned) {
+		this.owned = owned;
+	}
+
+	public long getId() {
+		return id;
+	}
+
+	public int getVersion() {
+		return version;
+	}
+}

Added: openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestProjectionQueryWithIdenticalResult.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestProjectionQueryWithIdenticalResult.java?rev=1171939&view=auto
==============================================================================
--- openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestProjectionQueryWithIdenticalResult.java
(added)
+++ openjpa/branches/1.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestProjectionQueryWithIdenticalResult.java
Sat Sep 17 10:20:06 2011
@@ -0,0 +1,109 @@
+/*
+ * 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.query;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.jdbc.common.apps.UnidirectionalOneToOneOwned;
+import org.apache.openjpa.persistence.jdbc.common.apps.UnidirectionalOneToOneOwner;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+
+/**
+ * The query uses projection and result contains the same instance once as
+ * a direct projection and again as a fetch group of the other projection.
+ * Does the query return two separate instances or one identical instance?
+ * 
+ * Originally reported as two different failures:
+ * <A HREF="https://issues.apache.org/jira/browse/OPENJPA-209">OPENJPA-209</A>
+ * <A HREF="https://issues.apache.org/jira/browse/OPENJPA-210">OPENJPA-210</A>

+ * 
+ * @author Pinaki Poddar
+ */
+public class TestProjectionQueryWithIdenticalResult extends SingleEMFTestCase {
+	private static boolean USE_TXN = true; 
+    public void setUp() {
+        setUp(CLEAR_TABLES,
+        	  UnidirectionalOneToOneOwned.class, 
+        	  UnidirectionalOneToOneOwner.class);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        UnidirectionalOneToOneOwner owner = new UnidirectionalOneToOneOwner();
+        owner.setMarker("Owner");
+        UnidirectionalOneToOneOwned owned = new UnidirectionalOneToOneOwned();
+        owned.setMarker("Owned");
+        owner.setOwned(owned);
+        em.persist(owner);
+        em.getTransaction().commit();
+        em.close();
+    }
+    
+	public void testDuplicateResultInProjection1() {
+		String jpql = "SELECT p.owned, p FROM UnidirectionalOneToOneOwner p";
+		List<Object[]> result = executeQuery(jpql, USE_TXN);
+		for (Object[] row : result) {
+			assertTrue(row[0] instanceof UnidirectionalOneToOneOwned);
+			assertTrue(row[1] instanceof UnidirectionalOneToOneOwner);
+			assertTrue(((UnidirectionalOneToOneOwner)row[1]).getOwned() == row[0]);
+		}
+	}
+	
+	public void testDuplicateResultInProjection2() {
+		String jpql = "SELECT p, p.owned FROM UnidirectionalOneToOneOwner p";
+		List<Object[]> result = executeQuery(jpql, USE_TXN);
+		for (Object[] row : result) {
+			assertTrue(row[1] instanceof UnidirectionalOneToOneOwned);
+			assertTrue(row[0] instanceof UnidirectionalOneToOneOwner);
+			assertTrue(((UnidirectionalOneToOneOwner)row[0]).getOwned() == row[1]);
+		}
+	}
+	
+	public void testDuplicateResultInProjection3() {
+		String jpql = "SELECT p, q FROM UnidirectionalOneToOneOwner p, " +
+						"UnidirectionalOneToOneOwned q WHERE p.owned = q";
+		List<Object[]> result = executeQuery(jpql, USE_TXN);
+		for (Object[] row : result) {
+			assertTrue(row[0] instanceof UnidirectionalOneToOneOwner);
+			assertTrue(row[1] instanceof UnidirectionalOneToOneOwned);
+			assertTrue(((UnidirectionalOneToOneOwner)row[0]).getOwned() == row[1]);
+		}
+	}
+	
+	public void testDuplicateResultInProjection4() {
+		String jpql = "SELECT q, p FROM UnidirectionalOneToOneOwner p, " +
+					    "UnidirectionalOneToOneOwned q WHERE p.owned = q";
+		List<Object[]> result = executeQuery(jpql, USE_TXN);
+		for (Object[] row : result) {
+			assertTrue(row[0] instanceof UnidirectionalOneToOneOwned);
+			assertTrue(row[1] instanceof UnidirectionalOneToOneOwner);
+			assertTrue(((UnidirectionalOneToOneOwner)row[1]).getOwned() == row[0]);
+		}
+	}
+	
+	private List executeQuery(String jpql, boolean useTxn) {
+		EntityManager em = emf.createEntityManager();
+		em.getTransaction().begin();
+		List result = em.createQuery(jpql).getResultList();
+		em.getTransaction().rollback();
+		return result;
+	}
+}



Mime
View raw message