openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1447955 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/
Date Tue, 19 Feb 2013 22:54:36 GMT
Author: curtisr7
Date: Tue Feb 19 22:54:35 2013
New Revision: 1447955

URL: http://svn.apache.org/r1447955
Log:
OPENJPA-2328: Fix NoSuchElementException when using HandlerRelationMapTableFieldStrategy.
Patch contributed by Guillaume Chauvet.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java?rev=1447955&r1=1447954&r2=1447955&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/HandlerRelationMapTableFieldStrategy.java
Tue Feb 19 22:54:35 2013
@@ -317,7 +317,7 @@ public class HandlerRelationMapTableFiel
                     if (field.isUni1ToMFK()){
                         updateSetNull(sm, mkey, store, rm);
                     } else { 
-                        HandlerStrategies.where(key, itr.next(), store, delRow,  _kcols);
+                        HandlerStrategies.where(key, mkey, store, delRow,  _kcols);
                         rm.flushSecondaryRow(delRow);
                     }
                 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java?rev=1447955&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java
Tue Feb 19 22:54:35 2013
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2013 Apache Software Foundation.
+ *
+ * Licensed 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.strategy;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * Defines the aggregated side of the entity relation
+ */
+@Entity
+public class MappedEntity {
+
+    public enum Key {
+        A, B, C
+    };
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private int id;
+
+    private long value = System.nanoTime();
+
+    public int getId() {
+        return id;
+    }
+
+    public long getValue() {
+        return value;
+    }
+
+    public void setValue(long value) {
+        this.value = value;
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MappedEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java?rev=1447955&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java
Tue Feb 19 22:54:35 2013
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2013 Apache Software Foundation.
+ *
+ * Licensed 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.strategy;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.FetchType;
+import javax.persistence.MapKeyColumn;
+import javax.persistence.MapKeyEnumerated;
+import javax.persistence.OneToMany;
+
+import org.apache.openjpa.persistence.jdbc.strategy.MappedEntity.Key;
+
+/**
+ * Defines the aggregator side of the entity relation
+ */
+@Entity
+public class MapperEntity {
+
+    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
+    @MapKeyColumn(name = "CODE")
+    @MapKeyEnumerated(EnumType.STRING)
+    private Map<Key, MappedEntity> values = new HashMap<Key, MappedEntity>();
+
+    public MappedEntity get(Key key) {
+        if (!values.containsKey(key)) {
+            values.put(key, new MappedEntity());
+        }
+        return values.get(key);
+    }
+
+    public void remove(Key key) {
+        values.remove(key);
+    }
+
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/MapperEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java?rev=1447955&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java
Tue Feb 19 22:54:35 2013
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2013 Apache Software Foundation.
+ *
+ * Licensed 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.strategy;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.jdbc.strategy.MappedEntity.Key;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ */
+public class TestHandlerStrategy extends SingleEMFTestCase {
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(MappedEntity.class, MapperEntity.class, "openjpa.jdbc.MappingDefaults",
+            "ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict", CLEAR_TABLES);
+    }
+
+    /**
+     * @see JIRA ticket OPENJPA-2328 for more explanation
+     */
+    public void testIssue_OPENJPA2328() {
+        EntityManager em = emf.createEntityManager();
+        MapperEntity ae = new MapperEntity();
+        for (Key key : Key.values()) {
+            ae.get(key).setValue(System.nanoTime());
+        }
+
+        // First step : persist some data into database
+        em.getTransaction().begin();
+        em.persist(ae);
+        em.getTransaction().commit();
+
+        // Second step : update & remove some data from collection
+        em.getTransaction().begin();
+        ae.get(Key.A).setValue(10L); // Required
+        ae.remove(Key.B); // Required*
+        em.getTransaction().commit();
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/strategy/TestHandlerStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message