cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject cayenne git commit: CAY-2042 | Remove an arbitrary limitation on 1000 runtime DbRelationships
Date Thu, 14 Jan 2016 16:22:03 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-3.1 0e5f8b76d -> e7bff0cb3


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/e7bff0cb
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/e7bff0cb
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/e7bff0cb

Branch: refs/heads/STABLE-3.1
Commit: e7bff0cb311493213fadbadfc9cef203ea371944
Parents: 0e5f8b7
Author: Savva Kolbachev <s.kolbachev@gmail.com>
Authored: Thu Jan 14 19:19:18 2016 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Thu Jan 14 19:19:18 2016 +0300

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


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e7bff0cb/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 1cde398..0ec1605 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -13,6 +13,8 @@ Date: not yet released
 ----------------------------------
 Changes/New Features Since 3.1
 
+CAY-2042 Remove an arbitrary limitation on 1000 runtime DbRelationships
+
 Bug Fixes Since 3.1:
 
 CAY-1964 Fix convertAdditionalDataMaps() in CayenneGeneratorMojo.java

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e7bff0cb/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
----------------------------------------------------------------------
diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
index b99f00a..8d7fb1f 100644
--- a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
+++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
@@ -19,15 +19,6 @@
 
 package org.apache.cayenne.map;
 
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
@@ -44,6 +35,16 @@ import org.apache.commons.collections.collection.CompositeCollection;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
 /**
  * Represents a virtual shared namespace for zero or more DataMaps. Unlike DataMap,
  * EntityResolver is intended to work as a runtime container of mapping. DataMaps can be
@@ -59,6 +60,7 @@ public class EntityResolver implements MappingNamespace, Serializable {
     static final ObjEntity DUPLICATE_MARKER = new ObjEntity();
 
     protected static final Log logger = LogFactory.getLog(EntityResolver.class);
+    protected static AtomicLong incrementer = new AtomicLong();
 
     protected boolean indexedByClass;
 
@@ -137,7 +139,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);
 
@@ -176,7 +178,7 @@ public class EntityResolver implements MappingNamespace, Serializable
{
                                 .createReverseRelationship();
 
                         Entity targetEntity = reverse.getSourceEntity();
-                        reverse.setName(makeUniqueRelationshipName(targetEntity));
+                        reverse.setName(getUniqueRelationshipName(targetEntity));
                         reverse.setRuntime(true);
                         targetEntity.addRelationship(reverse);
 
@@ -190,16 +192,14 @@ public class EntityResolver implements MappingNamespace, Serializable
{
         }
     }
 
-    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;
     }
 
     /**


Mime
View raw message