Author: mikedd
Date: Fri Nov 12 22:10:12 2010
New Revision: 1034584
URL: http://svn.apache.org/viewvc?rev=1034584&view=rev
Log:
OPENJPA-1790: Added Proxy for concurrent maps.
Submitted By: Heath Thomann, ported from Jody's patch for trunk
Added:
openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java
(with props)
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java
(with props)
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java
(with props)
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java
(with props)
Added:
openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java?rev=1034584&view=auto
==============================================================================
---
openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java
(added)
+++
openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java
Fri Nov 12 22:10:12 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.util;
+
+import java.util.Map;
+
+/**
+ * Utility methods used by concurrent map proxies.
+ *
+ */
+public class ProxyConcurrentMaps extends ProxyMaps {
+
+ /**
+ * Call before invoking {...@link Map#remove} on super.
+ */
+ public static boolean beforeRemove(ProxyMap map, Object key, Object value)
{
+ dirty(map, false);
+ return map.containsKey(key);
+ }
+
+ /**
+ * Call after invoking {...@link Map#remove} on super.
+ *
+ * @param ret the return value from the super's method
+ * @param before the return value from {...@link #beforeRemove}
+ * @return the value to return from {...@link Map#remove}
+ */
+ public static boolean afterRemove(ProxyMap map, Object key, Object value,
boolean ret,
+ boolean before) {
+ if (before) {
+ if (map.getChangeTracker() != null) {
+ ((MapChangeTracker) map.getChangeTracker()).removed(key, ret);
+ }
+ removed(map, key, true);
+ removed(map, ret, false);
+ }
+ return ret;
+ }
+}
Propchange:
openjpa/branches/2.0.x/openjpa-kernel/src/main/java/org/apache/openjpa/util/ProxyConcurrentMaps.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java?rev=1034584&view=auto
==============================================================================
---
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java
(added)
+++
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java
Fri Nov 12 22:10:12 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+...@entity
+public class ConcurrentEntityLeft {
+ @Id
+ private int id;
+
+ private String strData;
+
+ @ManyToOne
+ @JoinColumn(name="right_id", referencedColumnName="id")
+ private ConcurrentEntityRight rightEntity;
+
+ public ConcurrentEntityLeft() {
+
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ public ConcurrentEntityRight getRightEntity() {
+ return rightEntity;
+ }
+
+ public void setRightEntity(ConcurrentEntityRight rightEntity) {
+ this.rightEntity = rightEntity;
+ }
+}
Propchange:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityLeft.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java?rev=1034584&view=auto
==============================================================================
---
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java
(added)
+++
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java
Fri Nov 12 22:10:12 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.relations;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.MapKey;
+import javax.persistence.OneToMany;
+
+...@entity
+public class ConcurrentEntityRight {
+ @Id
+ private int id;
+
+ private String strData;
+
+ @OneToMany(mappedBy="rightEntity",
targetEntity=ConcurrentEntityLeft.class,
+ cascade={javax.persistence.CascadeType.ALL})
+ @MapKey(name="strData")
+ private Map<String, ConcurrentEntityLeft> leftEntityMap;
+
+ public ConcurrentEntityRight() {
+ leftEntityMap = new ConcurrentHashMap<String,
ConcurrentEntityLeft>();
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStrData() {
+ return strData;
+ }
+
+ public void setStrData(String strData) {
+ this.strData = strData;
+ }
+
+ public Map<String, ConcurrentEntityLeft> getLeftEntityMap() {
+ return leftEntityMap;
+ }
+}
Propchange:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/ConcurrentEntityRight.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java
URL:
http://svn.apache.org/viewvc/openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java?rev=1034584&view=auto
==============================================================================
---
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java
(added)
+++
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java
Fri Nov 12 22:10:12 2010
@@ -0,0 +1,48 @@
+/*
+ * 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.relations;
+
+import org.apache.openjpa.persistence.test.SingleEMTestCase;
+
+public class TestConcurrentMap extends SingleEMTestCase {
+ public void setUp() {
+ setUp(ConcurrentEntityLeft.class, ConcurrentEntityRight.class,
+ CLEAR_TABLES);
+ }
+
+ public void testConcurrentMap001() {
+ em.getTransaction().begin();
+
+ ConcurrentEntityLeft left = new ConcurrentEntityLeft();
+ left.setId(1);
+ left.setStrData("Lefty");
+
+ ConcurrentEntityRight right = new ConcurrentEntityRight();
+ right.setId(1);
+ right.setStrData("Poncho");
+
+ em.persist(left);
+ em.persist(right);
+
+ left.setRightEntity(right);
+ right.getLeftEntityMap().put(left.getStrData(), left);
+
+ em.getTransaction().commit();
+ }
+}
Propchange:
openjpa/branches/2.0.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestConcurrentMap.java
------------------------------------------------------------------------------
svn:eol-style = native