cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [1/2] cayenne git commit: CAY-2042 | Remove an arbitrary limitation on 1000 runtime DbRelationships
Date Thu, 14 Jan 2016 15:41:29 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master e48da188e -> 5d23f9b5d


CAY-2042 | Remove an arbitrary limitation on 1000 runtime DbRelationships


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/8735d658
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/8735d658
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/8735d658

Branch: refs/heads/master
Commit: 8735d6588cc56ef9e17c362a301be3e79ee117a6
Parents: e48da18
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Thu Jan 14 18:38:38 2016 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Thu Jan 14 18:38:38 2016 +0300

----------------------------------------------------------------------
 .../org/apache/cayenne/map/EntityResolver.java  | 20 ++++++++++----------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 2 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/8735d658/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
index 020b590..fbd8b55 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/map/EntityResolver.java
@@ -19,7 +19,6 @@
 
 package org.apache.cayenne.map;
 
-import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.query.Query;
@@ -39,6 +38,7 @@ import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.concurrent.atomic.AtomicLong;
 
 /**
  * Represents a virtual shared namespace for zero or more DataMaps. Unlike
@@ -53,6 +53,7 @@ import java.util.Collections;
 public class EntityResolver implements MappingNamespace, Serializable {
 
     protected static final Log logger = LogFactory.getLog(EntityResolver.class);
+    protected static AtomicLong incrementer = new AtomicLong();
 
     @Deprecated
     protected boolean indexedByClass;
@@ -107,7 +108,7 @@ public class EntityResolver implements MappingNamespace, Serializable
{
                         DbRelationship reverse = relationship.createReverseRelationship();
 
                         Entity targetEntity = reverse.getSourceEntity();
-                        reverse.setName(makeUniqueRelationshipName(targetEntity));
+                        reverse.setName(getUniqueRelationshipName(targetEntity));
                         reverse.setRuntime(true);
                         targetEntity.addRelationship(reverse);
 
@@ -130,15 +131,14 @@ public class EntityResolver implements MappingNamespace, Serializable
{
         // noop
     }
 
-    private String makeUniqueRelationshipName(Entity entity) {
-        for (int i = 0; i < 1000; i++) {
-            String name = "runtimeRelationship" + i;
-            if (entity.getRelationship(name) == null) {
-                return name;
-            }
-        }
+    private String getUniqueRelationshipName(Entity entity) {
+        String name;
+
+        do {
+            name = "runtimeRelationship" + incrementer.getAndIncrement();
+        } while(entity.getRelationship(name) != null);
 
-        throw new CayenneRuntimeException("Could not come up with a unique relationship name");
+        return name;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/8735d658/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index b96d0bd..5587f63 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -36,6 +36,7 @@ CAY-2028 Wrap DataChannelFilter calls in the main transaction
 CAY-2029 Allow out-of-order insertion into DI lists
 CAY-2030 Capturing a stream of commit changes
 CAY-2035 Autobind items added to collections (Cayenne DI)
+CAY-2042 Remove an arbitrary limitation on 1000 runtime DbRelationships
 CAY-2043 ServerRuntimeBuilder: use DataDomain name for the default DataNode
 CAY-2044 Collection setter for to-many relationships
 


Mime
View raw message