cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1085358 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/ashwood/ main/java/org/apache/cayenne/map/ test/java/org/apache/cayenne/ashwood/
Date Fri, 25 Mar 2011 13:34:19 GMT
Author: aadamchik
Date: Fri Mar 25 13:34:19 2011
New Revision: 1085358

URL: http://svn.apache.org/viewvc?rev=1085358&view=rev
Log:
CAY-1553 cayenne-lifecycle: @SortWeight annotation

preliminary refactoring

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ashwood/AshwoodEntitySorterTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomain.java
Fri Mar 25 13:34:19 2011
@@ -886,7 +886,7 @@ public class DataDomain implements Query
 
     void refreshEntitySorter() {
         if (entitySorter != null) {
-            entitySorter.setDataMaps(getDataMaps());
+            entitySorter.setEntityResolver(getEntityResolver());
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataPort.java
Fri Mar 25 13:34:19 2011
@@ -31,6 +31,7 @@ import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.util.IteratedSelectObserver;
 import org.apache.cayenne.ashwood.AshwoodEntitySorter;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.query.InsertBatchQuery;
 import org.apache.cayenne.query.Query;
@@ -103,7 +104,7 @@ public class DataPort {
         // sort entities for insertion
         List sorted = new ArrayList(entities);
         EntitySorter sorter = new AshwoodEntitySorter();
-        sorter.setDataMaps(destinationNode.getDataMaps());
+        sorter.setEntityResolver(new EntityResolver(destinationNode.getDataMaps()));
         sorter.sortDbEntities(sorted, false);
 
         if (cleaningDestination) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DbGenerator.java
Fri Mar 25 13:34:19 2011
@@ -45,6 +45,7 @@ import org.apache.cayenne.map.DbAttribut
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
@@ -54,7 +55,6 @@ import org.apache.commons.logging.LogFac
 /**
  * Utility class that generates database schema based on Cayenne mapping. It is a logical
  * counterpart of DbLoader class.
- * 
  */
 public class DbGenerator {
 
@@ -569,7 +569,7 @@ public class DbGenerator {
         // sort table list
         if (tables.size() > 1) {
             EntitySorter sorter = new AshwoodEntitySorter();
-            sorter.setDataMaps(Collections.singleton(map));
+            sorter.setEntityResolver(new EntityResolver(Collections.singleton(map)));
             sorter.sortDbEntities(tables, false);
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ashwood/AshwoodEntitySorter.java
Fri Mar 25 13:34:19 2011
@@ -58,19 +58,18 @@ import org.apache.commons.collections.co
  */
 public class AshwoodEntitySorter implements EntitySorter {
 
-    protected Collection<DataMap> dataMaps;
+    protected EntityResolver entityResolver;
     protected Map<DbEntity, ComponentRecord> components;
     protected Map<DbEntity, List<DbRelationship>> reflexiveDbEntities;
 
-    protected DbEntityComparator dbEntityComparator;
-    protected ObjEntityComparator objEntityComparator;
+    protected Comparator<DbEntity> dbEntityComparator;
+    protected Comparator<ObjEntity> objEntityComparator;
 
     private volatile boolean dirty;
 
     public AshwoodEntitySorter() {
         dbEntityComparator = new DbEntityComparator();
         objEntityComparator = new ObjEntityComparator();
-        dataMaps = Collections.EMPTY_LIST;
         dirty = true;
     }
 
@@ -105,7 +104,10 @@ public class AshwoodEntitySorter impleme
         }
     }
 
-    private void doIndexSorter() {
+    /**
+     * Reindexes internal sorter without synchronization.
+     */
+    protected void doIndexSorter() {
 
         Map<DbEntity, List<DbRelationship>> reflexiveDbEntities = new HashMap<DbEntity,
List<DbRelationship>>(
                 32);
@@ -113,8 +115,9 @@ public class AshwoodEntitySorter impleme
         Digraph<DbEntity, List<DbAttribute>> referentialDigraph = new MapDigraph<DbEntity,
List<DbAttribute>>();
 
         Map<String, DbEntity> tableMap = new HashMap<String, DbEntity>();
-        for (DataMap map : dataMaps) {
-            for (DbEntity entity : map.getDbEntities()) {
+
+        if (entityResolver != null) {
+            for (DbEntity entity : entityResolver.getDbEntities()) {
                 tableMap.put(entity.getFullyQualifiedName(), entity);
                 referentialDigraph.addVertex(entity);
             }
@@ -185,9 +188,19 @@ public class AshwoodEntitySorter impleme
 
     /**
      * @since 1.1
+     * @deprecated since 3.1, {@link #setEntityResolver(EntityResolver)} is used instead.
      */
     public void setDataMaps(Collection<DataMap> dataMaps) {
-        this.dataMaps = dataMaps != null ? dataMaps : Collections.EMPTY_LIST;
+        setEntityResolver(new EntityResolver(dataMaps != null
+                ? dataMaps
+                : Collections.EMPTY_LIST));
+    }
+
+    /**
+     * @since 3.1
+     */
+    public void setEntityResolver(EntityResolver entityResolver) {
+        this.entityResolver = entityResolver;
         this.dirty = true;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntitySorter.java
Fri Mar 25 13:34:19 2011
@@ -31,10 +31,21 @@ public interface EntitySorter {
 
     /**
      * Initializes a list of DataMaps used by the sorter.
+     * 
+     * @deprecated since 3.1 {@link #setEntityResolver(EntityResolver)} is used, and this
+     *             method is never called.
      */
     void setDataMaps(Collection<DataMap> dataMaps);
 
     /**
+     * Sets EntityResolver for this sorter. All entities present in the resolver will be
+     * used to determine sort ordering.
+     * 
+     * @since 3.1
+     */
+    void setEntityResolver(EntityResolver resolver);
+
+    /**
      * Sorts a list of DbEntities.
      */
     void sortDbEntities(List<DbEntity> dbEntities, boolean deleteOrder);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ashwood/AshwoodEntitySorterTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ashwood/AshwoodEntitySorterTest.java?rev=1085358&r1=1085357&r2=1085358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ashwood/AshwoodEntitySorterTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ashwood/AshwoodEntitySorterTest.java
Fri Mar 25 13:34:19 2011
@@ -68,7 +68,7 @@ public class AshwoodEntitySorterTest ext
         tReflexiveAndToOne.insert(3, 2, 1, "r3");
         
         AshwoodEntitySorter sorter = new AshwoodEntitySorter();
-        sorter.setDataMaps(context.getEntityResolver().getDataMaps());
+        sorter.setEntityResolver(context.getEntityResolver());
 
         ObjEntity entity = context.getEntityResolver().lookupObjEntity(
                 ReflexiveAndToOne.class);



Mime
View raw message