openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mik...@apache.org
Subject svn commit: r802211 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/
Date Fri, 07 Aug 2009 21:31:46 GMT
Author: mikedd
Date: Fri Aug  7 21:31:45 2009
New Revision: 802211

URL: http://svn.apache.org/viewvc?rev=802211&view=rev
Log:
OPENJPA-1232: 
Call toNestedFields for Map Keys as well as Map values.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapEmbeddable.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapHolder.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEntitiesAsKeys.java
  (with props)
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=802211&r1=802210&r2=802211&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
Fri Aug  7 21:31:45 2009
@@ -95,8 +95,8 @@
                     keys.add(e.getKey());
                     values.add(e.getValue());
                 }
-
-                Object[] keyArray = keys.toArray();
+                Object[] keyArray = toNestedFields(sm, fmd.getKey(),
+                    keys, fetch, context).toArray();
                 Object[] valueArray = toNestedFields(sm, fmd.getElement(),
                     values, fetch, context).toArray();
                 for (int idx = 0; idx < keyArray.length; idx++)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapEmbeddable.java?rev=802211&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapEmbeddable.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapEmbeddable.java
Fri Aug  7 21:31:45 2009
@@ -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.datacache;
+
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class MapEmbeddable {
+    private int value;
+
+    MapEmbeddable(int value) {
+        this.value = value;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return "MapEmbeddable [_value=" + value + "]";
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapHolder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapHolder.java?rev=802211&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapHolder.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/MapHolder.java
Fri Aug  7 21:31:45 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.Map;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Version;
+
+@Entity(name = "MapHolder")
+public class MapHolder {
+    @Id
+    private int id;
+
+    @Version
+    private int version;
+
+    @ElementCollection
+    private Map<MapEmbeddable, MapEmbeddable> embeddableMap;
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+
+    public Map<MapEmbeddable, MapEmbeddable> getEmbeddableMap() {
+        return embeddableMap;
+    }
+
+    public void setEmbeddableMap(Map<MapEmbeddable, MapEmbeddable> embeddableMap) {
+        this.embeddableMap = embeddableMap;
+    }
+
+    @Override
+    public String toString() {
+        return "MapHolder [embeddableMap=" + embeddableMap + ", id=" + id + ", version="
+ version + "]";
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEntitiesAsKeys.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEntitiesAsKeys.java?rev=802211&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEntitiesAsKeys.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/datacache/TestEntitiesAsKeys.java
Fri Aug  7 21:31:45 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.test.PersistenceTestCase;
+
+public class TestEntitiesAsKeys extends PersistenceTestCase {
+
+    OpenJPAEntityManagerFactorySPI emf =
+        createEMF(MapHolder.class, MapEmbeddable.class, "openjpa.DataCache", "true", "openjpa.RemoteCommitProvider",
+            "sjvm", "openjpa.RuntimeUnenhancedClasses", "unsupported");
+
+    public void setUp() {
+        populate();
+    }
+
+    public void populate() {
+        EntityManager em = emf.createEntityManager();
+        // clean up before execution
+        em.getTransaction().begin();
+        em.createQuery("Delete from MapHolder").executeUpdate();
+        em.getTransaction().commit();
+
+        em.getTransaction().begin();
+        MapHolder mh = new MapHolder();
+        mh.setId(10);
+        mh.setEmbeddableMap(getEmbeddableMap(1, 2, 3, 4, 5, 6, 7, 8));
+        em.persist(mh);
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void testMapContents() {
+        EntityManager em = emf.createEntityManager();
+
+        MapHolder mh = em.find(MapHolder.class, 10);
+        mh.getEmbeddableMap();
+        assertNotNull(mh);
+
+        for (Object o : mh.getEmbeddableMap().keySet()) {
+            assertTrue("Expected key to be instanceof MapEmbeddable but was " + o.getClass().getCanonicalName(),
+                o instanceof MapEmbeddable);
+        }
+
+        for (Object o : mh.getEmbeddableMap().values()) {
+            assertTrue("Expected value to be instanceof MapEmbeddable but was " + o.getClass().getCanonicalName(),
+                o instanceof MapEmbeddable);
+        }
+        em.close();
+    }
+
+    private Map<MapEmbeddable, MapEmbeddable> getEmbeddableMap(Integer... integers)
{
+        Map<MapEmbeddable, MapEmbeddable> rval = new HashMap<MapEmbeddable, MapEmbeddable>();
+        assertEquals(0, integers.length % 2);
+
+        for (int i = 0; i < integers.length; i += 2) {
+            rval.put(new MapEmbeddable(integers[i]), new MapEmbeddable(integers[i + 1]));
+        }
+
+        return rval;
+    }
+}

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



Mime
View raw message