openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1822909 - in /openjpa/branches/2.2.x: openjpa-kernel/src/main/java/org/apache/openjpa/datacache/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/per...
Date Thu, 01 Feb 2018 21:57:06 GMT
Author: jgrassel
Date: Thu Feb  1 21:57:06 2018
New Revision: 1822909

URL: http://svn.apache.org/viewvc?rev=1822909&view=rev
Log:
OPENJPA-2726: Under certain conditions an Embeddable can be directly admitted into the Datacache
map

Added:
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java
  (with props)
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java
  (with props)
Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java?rev=1822909&r1=1822908&r2=1822909&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheStoreManager.java
Thu Feb  1 21:57:06 2018
@@ -423,6 +423,14 @@ public class DataCacheStoreManager
                 data = newPCData(sm, cache);
             }
             data.store(sm);
+            
+            // Check if data has no id, if it does not, do not enter it into the cache, as
we do
+            // not want to introduce any null-key entries into the cache map (some cache
+            // implementations cannot handle that)
+            if (data.getId() == null) {
+                return;
+            }
+            
             if (isNew) { 
                 cache.put(data);
             } else {
@@ -487,6 +495,9 @@ public class DataCacheStoreManager
 
         DataCachePCData data = cache.get(sm.getObjectId());
         boolean alreadyCached = data != null;
+        if (alreadyCached == false && sm.isEmbedded()) {
+            return;
+        }
 
         if ((fetch.getCacheStoreMode() == DataCacheStoreMode.USE && !alreadyCached)
||
              fetch.getCacheStoreMode() == DataCacheStoreMode.REFRESH) {

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java?rev=1822909&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java
Thu Feb  1 21:57:06 2018
@@ -0,0 +1,129 @@
+/*
+ * 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.cache.jpa;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.openjpa.datacache.ConcurrentDataCache;
+import org.apache.openjpa.datacache.DataCache;
+import org.apache.openjpa.datacache.DataCachePCDataImpl;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
+import org.apache.openjpa.persistence.StoreCache;
+import org.apache.openjpa.persistence.StoreCacheImpl;
+import org.apache.openjpa.persistence.cache.jpa.model.EmbeddableData;
+import org.apache.openjpa.persistence.cache.jpa.model.LeftHand;
+import org.apache.openjpa.persistence.cache.jpa.model.RightHand;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.apache.openjpa.util.CacheMap;
+
+public class TestDataCache extends SingleEMFTestCase {
+    public void setUp() {
+        super.setUp(CLEAR_TABLES,
+                "openjpa.DataCache","true",
+                LeftHand.class,
+                RightHand.class,
+                EmbeddableData.class);
+        emf.createEntityManager();
+    }
+    
+    public void testNoRawEmbeddableStoreInDatacache() {
+        final EntityManager em = emf.createEntityManager();
+        final OpenJPAEntityManager oem = em.unwrap(OpenJPAEntityManager.class);
+        final OpenJPAEntityManagerFactory oemf = oem.getEntityManagerFactory();
+        final StoreCacheImpl sc = (StoreCacheImpl) oemf.getStoreCache();
+        final DataCache dc = sc.getDelegate();
+        final ConcurrentDataCache cdc = (ConcurrentDataCache) dc;
+        
+        
+        final LeftHand lh = new LeftHand();
+        lh.setId(System.currentTimeMillis());
+        lh.setStrData("left hand");
+        
+        final RightHand rh = new RightHand();
+        rh.setId(System.currentTimeMillis());
+        rh.setStrData("right hand");
+        
+        final EmbeddableData ed = new EmbeddableData();
+        ed.setEmbeddedString("Embedded String");
+        ed.setLazyEmbeddedString("Lazy String");
+        rh.setEmb(ed);
+        
+        final ArrayList<RightHand> rhList = new ArrayList<RightHand>();
+        rhList.add(rh);
+        lh.setRhList(rhList);
+        
+        em.getTransaction().begin();
+        em.persist(lh);
+        em.persist(rh);
+        em.getTransaction().commit();
+        
+        CacheMap cm = cdc.getCacheMap();
+        validateCache(cm);
+        
+        em.clear();
+        oemf.getCache().evictAll();
+        assertEquals(0, cm.size());
+        
+        Query q = em.createQuery("SELECT lh FROM LeftHand lh");
+        List resultList = q.getResultList();
+        for (Object o : resultList) {
+            System.out.println(o);
+        }
+        
+        validateCache(cm);
+    }
+    
+    private void validateCache(CacheMap cm) {
+        assertNotNull(cm);
+        
+        final Collection afterCommitCacheEntries = cm.values();
+        assertNotNull(afterCommitCacheEntries);       
+        
+        // Expecting 1 entry for LeftHand, and 1 entry for righthand
+        boolean foundLeft = false;
+        boolean foundRight = false;
+        Iterator<?> i1 = afterCommitCacheEntries.iterator();
+        while (i1.hasNext()) {
+            DataCachePCDataImpl o = (DataCachePCDataImpl) i1.next();
+            assertNotNull(o);
+            Class<?> type = o.getType();
+            if (LeftHand.class.equals(type)) {
+                foundLeft = true;
+            } else if (RightHand.class.equals(type)) {
+                foundRight = true;
+            } else if (EmbeddableData.class.equals(type)) {
+                // Found raw Embeddable in the datacache
+                fail();
+            }  
+        }
+        
+        assertTrue(foundLeft);
+        assertTrue(foundRight);
+        
+        assertEquals(2, cm.size());
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/TestDataCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java?rev=1822909&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java
Thu Feb  1 21:57:06 2018
@@ -0,0 +1,58 @@
+/*
+ * 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.cache.jpa.model;
+
+import javax.persistence.Basic;
+import javax.persistence.Embeddable;
+import javax.persistence.FetchType;
+
+@Embeddable
+public class EmbeddableData {
+    @Basic
+    private String embeddedString;
+    
+    @Basic(fetch=FetchType.LAZY)
+    private String lazyEmbeddedString;
+    
+    public EmbeddableData() {
+        
+    }
+
+    public String getEmbeddedString() {
+        return embeddedString;
+    }
+
+    public void setEmbeddedString(String embeddedString) {
+        this.embeddedString = embeddedString;
+    }
+
+    public String getLazyEmbeddedString() {
+        return lazyEmbeddedString;
+    }
+
+    public void setLazyEmbeddedString(String lazyEmbeddedString) {
+        this.lazyEmbeddedString = lazyEmbeddedString;
+    }
+
+    @Override
+    public String toString() {
+        return "EmbeddableData [embeddedString=" + embeddedString + "]";
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/EmbeddableData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java?rev=1822909&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java
Thu Feb  1 21:57:06 2018
@@ -0,0 +1,82 @@
+/*
+ * 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.cache.jpa.model;
+
+import java.util.Collection;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Version;
+
+@Entity
+public class LeftHand {
+    @Id
+    private long id;
+    
+    private String strData;
+    
+    @OneToMany
+    private Collection<RightHand> rhList;
+    
+    @Version
+    private long version;
+    
+    public LeftHand() {
+        
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getStrData() {
+        return strData;
+    }
+
+    public void setStrData(String strData) {
+        this.strData = strData;
+    }
+
+    public Collection<RightHand> getRhList() {
+        return rhList;
+    }
+
+    public void setRhList(Collection<RightHand> rhList) {
+        this.rhList = rhList;
+    }
+
+    public long getVersion() {
+        return version;
+    }
+
+    public void setVersion(long version) {
+        this.version = version;
+    }
+
+    @Override
+    public String toString() {
+        return "LeftHand [id=" + id + ", strData=" + strData + ", rhList=" + rhList + ",
version=" + version + "]";
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/LeftHand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java?rev=1822909&view=auto
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java
(added)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java
Thu Feb  1 21:57:06 2018
@@ -0,0 +1,70 @@
+/*
+ * 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.cache.jpa.model;
+
+import javax.persistence.Basic;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class RightHand {
+    @Id
+    private long id;
+    
+    @Basic
+    private String strData;
+    
+    @Embedded
+    private EmbeddableData emb;
+    
+    public RightHand() {
+        
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getStrData() {
+        return strData;
+    }
+
+    public void setStrData(String strData) {
+        this.strData = strData;
+    }
+
+    public EmbeddableData getEmb() {
+        return emb;
+    }
+
+    public void setEmb(EmbeddableData emb) {
+        this.emb = emb;
+    }
+
+    @Override
+    public String toString() {
+        return "RightHand [id=" + id + ", strData=" + strData + ", emb=" + emb + "]";
+    }
+}

Propchange: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/cache/jpa/model/RightHand.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message