cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r990578 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/unit/
Date Sun, 29 Aug 2010 13:58:03 GMT
Author: aadamchik
Date: Sun Aug 29 13:58:03 2010
New Revision: 990578

URL: http://svn.apache.org/viewvc?rev=990578&view=rev
Log:
CAY-1479 EntitySorter refactoring: make it DI-based, internalize Ashowood lib

* stopped using DataNode.entitySorter

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/DataNode.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/test/java/org/apache/cayenne/access/DataNodeTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataNode.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.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=990578&r1=990577&r2=990578&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
Sun Aug 29 13:58:03 2010
@@ -106,7 +106,7 @@ public class DataDomain implements Query
     /**
      * @since 1.2
      */
-    EntitySorter entitySorter;
+    protected EntitySorter entitySorter;
 
     /**
      * @since 3.0
@@ -155,25 +155,14 @@ public class DataDomain implements Query
     }
 
     /**
-     * @since 1.2
+     * @since 3.1
      */
-    // TODO: andrus, 4/12/2006 - after 1.2 API freeze is over, replace DataNode
-    // EntitySorter with this one ... maybe even make it a part of server-side
-    // EntityResolver?
-    EntitySorter getEntitySorter() {
+    public EntitySorter getEntitySorter() {
 
         if (entitySorter == null) {
             synchronized (this) {
                 if (entitySorter == null) {
-
-                    // backwards compatibility mode... only possible in a single-node case
-                    // see TODO above
-                    if (nodes.size() == 1) {
-                        entitySorter = nodes.values().iterator().next().getEntitySorter();
-                    }
-                    else {
-                        entitySorter = new AshwoodEntitySorter(getDataMaps());
-                    }
+                    entitySorter = new AshwoodEntitySorter(getDataMaps());
                 }
             }
         }
@@ -185,9 +174,9 @@ public class DataDomain implements Query
      * Exists as a backdoor to override domain sorter until the sorter API is moved from
      * DataNode.
      * 
-     * @since 1.2
+     * @since 3.1
      */
-    void setEntitySorter(EntitySorter entitySorter) {
+    public void setEntitySorter(EntitySorter entitySorter) {
         this.entitySorter = entitySorter;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java?rev=990578&r1=990577&r2=990578&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
Sun Aug 29 13:58:03 2010
@@ -55,6 +55,9 @@ public class DataNode implements QueryEn
     protected EntityResolver entityResolver;
     protected SchemaUpdateStrategy schemaUpdateStrategy;
 
+    /**
+     * @deprecated since 3.1 EntitySorter is located at the DataDomain level.
+     */
     protected EntitySorter entitySorter;
     protected Map<String, DataMap> dataMaps;
 
@@ -313,6 +316,8 @@ public class DataNode implements QueryEn
 
     /**
      * Returns EntitySorter used by the DataNode.
+     * 
+     * @deprecated since 3.1 EntitySorter only exists at the DataDomain level.
      */
     public EntitySorter getEntitySorter() {
         return entitySorter;
@@ -322,6 +327,7 @@ public class DataNode implements QueryEn
      * Sets an EntitySorter that is used to order objects on commit.
      * 
      * @since 1.2
+     * @deprecated since 3.1 EntitySorter only exists at the DataDomain level.
      */
     public void setEntitySorter(EntitySorter entitySorter) {
         this.entitySorter = entitySorter;

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=990578&r1=990577&r2=990578&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
Sun Aug 29 13:58:03 2010
@@ -29,7 +29,9 @@ import java.util.Map;
 import org.apache.cayenne.CayenneException;
 import org.apache.cayenne.DataRow;
 import org.apache.cayenne.access.util.IteratedSelectObserver;
+import org.apache.cayenne.map.AshwoodEntitySorter;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.query.InsertBatchQuery;
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
@@ -100,7 +102,8 @@ public class DataPort {
 
         // sort entities for insertion
         List sorted = new ArrayList(entities);
-        destinationNode.getEntitySorter().sortDbEntities(sorted, false);
+        EntitySorter sorter = new AshwoodEntitySorter(destinationNode.getDataMaps());
+        sorter.sortDbEntities(sorted, false);
 
         if (cleaningDestination) {
             // reverse insertion order for deletion

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=990578&r1=990577&r2=990578&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
Sun Aug 29 13:58:03 2010
@@ -39,11 +39,13 @@ import org.apache.cayenne.conn.DriverDat
 import org.apache.cayenne.dba.DbAdapter;
 import org.apache.cayenne.dba.PkGenerator;
 import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.AshwoodEntitySorter;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.EntitySorter;
 import org.apache.cayenne.validation.SimpleValidationFailure;
 import org.apache.cayenne.validation.ValidationResult;
 import org.apache.commons.logging.Log;
@@ -566,9 +568,8 @@ public class DbGenerator {
 
         // sort table list
         if (tables.size() > 1) {
-            DataNode node = new DataNode("temp");
-            node.addDataMap(map);
-            node.getEntitySorter().sortDbEntities(tables, false);
+            EntitySorter sorter = new AshwoodEntitySorter(Collections.singleton(map));
+            sorter.sortDbEntities(tables, false);
         }
 
         this.dbEntitiesInInsertOrder = tables;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeTest.java?rev=990578&r1=990577&r2=990578&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataNodeTest.java
Sun Aug 29 13:58:03 2010
@@ -22,7 +22,6 @@ package org.apache.cayenne.access;
 import junit.framework.TestCase;
 
 import org.apache.cayenne.dba.JdbcAdapter;
-import org.apache.cayenne.map.EntitySorter;
 
 public class DataNodeTest extends TestCase {
 
@@ -62,22 +61,16 @@ public class DataNodeTest extends TestCa
     public void testAdapter() throws Exception {
         DataNode node = new DataNode();
 
-        // entity sorter should have been created ... and since 1.2 shouldn't change no
-        // matter what adapter we use.
-        EntitySorter sorter = node.getEntitySorter();
-        assertNotNull(sorter);
         assertNull(node.getAdapter());
 
         JdbcAdapter a1 = new JdbcAdapter();
         node.setAdapter(a1);
 
         assertSame(a1, node.getAdapter());
-        assertSame(sorter, node.getEntitySorter());
 
         JdbcAdapter a2 = new JdbcAdapter();
         node.setAdapter(a2);
 
         assertSame(a2, node.getAdapter());
-        assertSame(sorter, node.getEntitySorter());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataNode.java?rev=990578&r1=990577&r2=990578&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataNode.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/MockDataNode.java
Sun Aug 29 13:58:03 2010
@@ -150,6 +150,9 @@ public class MockDataNode extends DataNo
         return node.getEntityResolver();
     }
 
+    /**
+     * @deprecated since 3.1
+     */
     @Override
     public EntitySorter getEntitySorter() {
         return node.getEntitySorter();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java?rev=990578&r1=990577&r2=990578&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/SimpleAccessStack.java
Sun Aug 29 13:58:03 2010
@@ -29,13 +29,11 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.access.DataNode;
 import org.apache.cayenne.access.DbGenerator;
 import org.apache.cayenne.access.QueryLogger;
@@ -86,11 +84,7 @@ public class SimpleAccessStack implement
         return resources.getAccessStackAdapter(node.getAdapter().getClass().getName());
     }
 
-    protected DataDomain getDomain() {
-        return domain;
-    }
-
-    protected void initNode(DataMap map) throws Exception {
+    private void initNode(DataMap map) throws Exception {
         DataNode node = resources.newDataNode(map.getName());
 
         // setup test extended types
@@ -176,19 +170,19 @@ public class SimpleAccessStack implement
      * Helper method that orders DbEntities to satisfy referential constraints and returns
      * an ordered list.
      */
-    protected List dbEntitiesInInsertOrder(DataNode node, DataMap map) {
-        List entities = new ArrayList(map.getDbEntities());
+    private List<DbEntity> dbEntitiesInInsertOrder(DataNode node, DataMap map) {
+        List<DbEntity> entities = new ArrayList<DbEntity>(map.getDbEntities());
 
-        // filter varios unsupported tests...
+        // filter various unsupported tests...
 
         // LOBs
         boolean excludeLOB = !getAdapter(node).supportsLobs();
         boolean excludeBinPK = !getAdapter(node).supportsBinaryPK();
         if (excludeLOB || excludeBinPK) {
-            Iterator it = entities.iterator();
-            List filtered = new ArrayList();
-            while (it.hasNext()) {
-                DbEntity ent = (DbEntity) it.next();
+
+            List<DbEntity> filtered = new ArrayList<DbEntity>();
+
+            for (DbEntity ent : entities) {
 
                 // check for LOB attributes
                 if (excludeLOB) {
@@ -236,14 +230,14 @@ public class SimpleAccessStack implement
             entities = filtered;
         }
 
-        node.getEntitySorter().sortDbEntities(entities, false);
+        domain.getEntitySorter().sortDbEntities(entities, false);
         return entities;
     }
 
-    protected void deleteTestData(DataNode node, DataMap map) throws Exception {
+    private void deleteTestData(DataNode node, DataMap map) throws Exception {
 
         Connection conn = node.getDataSource().getConnection();
-        List list = this.dbEntitiesInInsertOrder(node, map);
+        List<DbEntity> list = dbEntitiesInInsertOrder(node, map);
         try {
             if (conn.getAutoCommit()) {
                 conn.setAutoCommit(false);
@@ -251,9 +245,9 @@ public class SimpleAccessStack implement
 
             Statement stmt = conn.createStatement();
 
-            ListIterator it = list.listIterator(list.size());
+            ListIterator<DbEntity> it = list.listIterator(list.size());
             while (it.hasPrevious()) {
-                DbEntity ent = (DbEntity) it.previous();
+                DbEntity ent = it.previous();
 
                 boolean status;
                 if (ent.getDataMap() != null
@@ -297,14 +291,14 @@ public class SimpleAccessStack implement
         }
     }
 
-    protected void dropSchema(DataNode node, DataMap map) throws Exception {
+    private void dropSchema(DataNode node, DataMap map) throws Exception {
         Connection conn = node.getDataSource().getConnection();
-        List list = dbEntitiesInInsertOrder(node, map);
+        List<DbEntity> list = dbEntitiesInInsertOrder(node, map);
 
         try {
             DatabaseMetaData md = conn.getMetaData();
             ResultSet tables = md.getTables(null, null, "%", null);
-            List allTables = new ArrayList();
+            List<String> allTables = new ArrayList<String>();
 
             while (tables.next()) {
                 // 'toUpperCase' is needed since most databases
@@ -321,9 +315,9 @@ public class SimpleAccessStack implement
             // drop all tables in the map
             Statement stmt = conn.createStatement();
 
-            ListIterator it = list.listIterator(list.size());
+            ListIterator<DbEntity> it = list.listIterator(list.size());
             while (it.hasPrevious()) {
-                DbEntity ent = (DbEntity) it.previous();
+                DbEntity ent = it.previous();
                 if (!allTables.contains(ent.getName().toUpperCase())) {
                     continue;
                 }
@@ -349,25 +343,24 @@ public class SimpleAccessStack implement
 
     }
 
-    protected void dropPKSupport(DataNode node, DataMap map) throws Exception {
-        List filteredEntities = dbEntitiesInInsertOrder(node, map);
+    private void dropPKSupport(DataNode node, DataMap map) throws Exception {
+        List<DbEntity> filteredEntities = dbEntitiesInInsertOrder(node, map);
         node.getAdapter().getPkGenerator().dropAutoPk(node, filteredEntities);
     }
 
-    protected void createPKSupport(DataNode node, DataMap map) throws Exception {
-        List filteredEntities = dbEntitiesInInsertOrder(node, map);
+    private void createPKSupport(DataNode node, DataMap map) throws Exception {
+        List<DbEntity> filteredEntities = dbEntitiesInInsertOrder(node, map);
         node.getAdapter().getPkGenerator().createAutoPk(node, filteredEntities);
     }
 
-    protected void createSchema(DataNode node, DataMap map) throws Exception {
+    private void createSchema(DataNode node, DataMap map) throws Exception {
         Connection conn = node.getDataSource().getConnection();
 
         try {
             getAdapter(node).willCreateTables(conn, map);
             Statement stmt = conn.createStatement();
-            Iterator it = tableCreateQueries(node, map);
-            while (it.hasNext()) {
-                String query = (String) it.next();
+
+            for (String query : tableCreateQueries(node, map)) {
                 QueryLogger.logQuery(query, Collections.EMPTY_LIST);
                 stmt.execute(query);
             }
@@ -381,33 +374,29 @@ public class SimpleAccessStack implement
     /**
      * Returns iterator of preprocessed table create queries.
      */
-    protected Iterator tableCreateQueries(DataNode node, DataMap map) throws Exception {
+    private Collection<String> tableCreateQueries(DataNode node, DataMap map)
+            throws Exception {
         DbAdapter adapter = node.getAdapter();
-        DbGenerator gen = new DbGenerator(adapter, map, null, getDomain());
+        DbGenerator gen = new DbGenerator(adapter, map, null, domain);
 
-        List orderedEnts = dbEntitiesInInsertOrder(node, map);
-        List queries = new ArrayList();
+        List<DbEntity> orderedEnts = dbEntitiesInInsertOrder(node, map);
+        List<String> queries = new ArrayList<String>();
 
         // table definitions
-        Iterator it = orderedEnts.iterator();
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
+        for (DbEntity ent : orderedEnts) {
             queries.add(adapter.createTable(ent));
         }
 
         // FK constraints
-
-        it = orderedEnts.iterator();
-        while (it.hasNext()) {
-            DbEntity ent = (DbEntity) it.next();
+        for (DbEntity ent : orderedEnts) {
             if (!getAdapter(node).supportsFKConstraints(ent)) {
                 continue;
             }
 
-            List qs = gen.createConstraintsQueries(ent);
+            List<String> qs = gen.createConstraintsQueries(ent);
             queries.addAll(qs);
         }
 
-        return queries.iterator();
+        return queries;
     }
 }



Mime
View raw message