You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2013/06/30 15:56:47 UTC

svn commit: r1498123 - /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java

Author: aadamchik
Date: Sun Jun 30 13:56:47 2013
New Revision: 1498123

URL: http://svn.apache.org/r1498123
Log:
a small performance optimization

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java?rev=1498123&r1=1498122&r2=1498123&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MappingCache.java Sun Jun 30 13:56:47 2013
@@ -19,6 +19,7 @@
 package org.apache.cayenne.map;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -195,7 +196,7 @@ class MappingCache implements MappingNam
 
         return entity;
     }
-    
+
     public ObjEntity getObjEntity(Persistent object) {
         ObjectId id = object.getObjectId();
         if (id != null) {
@@ -215,6 +216,15 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getDbEntities();
+        }
+
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getDbEntities());
@@ -229,6 +239,14 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getProcedures();
+        }
+        
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getProcedures());
@@ -243,6 +261,14 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getQueries();
+        }
+        
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getQueries());
@@ -257,6 +283,14 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getObjEntities();
+        }
+        
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getObjEntities());
@@ -271,6 +305,14 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getEmbeddables();
+        }
+        
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getEmbeddables());
@@ -285,6 +327,15 @@ class MappingCache implements MappingNam
         // always fresh list here, so instead of doing the right thing of
         // refreshing the cache and returning cache.entries(), we are scanning
         // the list of DataMaps.
+        
+        if (maps.size() == 0) {
+            return Collections.emptyList();
+        }
+        
+        if (maps.size() == 1) {
+            return maps.iterator().next().getResults();
+        }
+        
         CompositeCollection c = new CompositeCollection();
         for (DataMap map : maps) {
             c.addComposited(map.getResults());