cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amania...@apache.org
Subject svn commit: r604858 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/trans/ main/java/org/apache/cayenne/exp/parser/ main/java/org/apache/cayenne/map/ test/java/org/apache/cayenne/map/
Date Mon, 17 Dec 2007 12:51:43 GMT
Author: amaniatis
Date: Mon Dec 17 04:51:42 2007
New Revision: 604858

URL: http://svn.apache.org/viewvc?rev=604858&view=rev
Log:
PathIterator now iterates through CayenneMapEntry items, making the generics a little nicer.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Entity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/EntityTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/QueryAssemblerHelper.java
Mon Dec 17 04:51:42 2007
@@ -37,6 +37,7 @@
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.util.CayenneMapEntry;
 
 /** 
  * Translates parts of the query to SQL.
@@ -85,11 +86,11 @@
     /** Processes parts of the OBJ_PATH expression. */
     protected void appendObjPath(StringBuffer buf, Expression pathExp) {
 
-        Iterator<Object> it = getObjEntity().resolvePathComponents(pathExp);
+        Iterator<CayenneMapEntry> it = getObjEntity().resolvePathComponents(pathExp);
         ObjRelationship lastRelationship = null;
 
         while (it.hasNext()) {
-            Object pathComp = it.next();
+            CayenneMapEntry pathComp = it.next();
 
             if (pathComp instanceof ObjRelationship) {
                 ObjRelationship rel = (ObjRelationship) pathComp;
@@ -122,10 +123,10 @@
     }
 
     protected void appendDbPath(StringBuffer buf, Expression pathExp) {
-        Iterator<Object> it = getDbEntity().resolvePathComponents(pathExp);
+        Iterator<CayenneMapEntry> it = getDbEntity().resolvePathComponents(pathExp);
 
         while (it.hasNext()) {
-            Object pathComp = it.next();
+            CayenneMapEntry pathComp = it.next();
             if (pathComp instanceof DbRelationship) {
                 DbRelationship rel = (DbRelationship) pathComp;
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/trans/SelectTranslator.java
Mon Dec 17 04:51:42 2007
@@ -49,6 +49,7 @@
 import org.apache.cayenne.reflect.PropertyVisitor;
 import org.apache.cayenne.reflect.ToManyProperty;
 import org.apache.cayenne.reflect.ToOneProperty;
+import org.apache.cayenne.util.CayenneMapEntry;
 
 /**
  * A builder of JDBC PreparedStatements based on Cayenne SelectQueries. Translates
@@ -377,10 +378,10 @@
                 String path = (String) extraPaths.next();
                 Expression pathExp = oe.translateToDbPath(Expression.fromString(path));
 
-                Iterator it = table.resolvePathComponents(pathExp);
+                Iterator<CayenneMapEntry> it = table.resolvePathComponents(pathExp);
 
                 // add joins and find terminating element
-                Object pathComponent = null;
+                CayenneMapEntry pathComponent = null;
                 while (it.hasNext()) {
                     pathComponent = it.next();
 
@@ -430,13 +431,7 @@
         // handle joint prefetches directly attached to this query...
         if (query.getPrefetchTree() != null) {
 
-            Iterator jointPrefetches = query
-                    .getPrefetchTree()
-                    .adjacentJointNodes()
-                    .iterator();
-
-            while (jointPrefetches.hasNext()) {
-                PrefetchTreeNode prefetch = (PrefetchTreeNode) jointPrefetches.next();
+            for (PrefetchTreeNode prefetch : query.getPrefetchTree().adjacentJointNodes())
{
 
                 // for each prefetch add all joins plus columns from the target entity
                 Expression prefetchExp = Expression.fromString(prefetch.getPath());

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ASTPath.java
Mon Dec 17 04:51:42 2007
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.util.CayenneMapEntry;
 
 /**
  * Generic path expression.
@@ -68,9 +69,9 @@
     /**
      * Helper method to evaluate path expression with Cayenne Entity.
      */
-    protected Object evaluateEntityNode(Entity entity) {
-        Iterator path = entity.resolvePathComponents(this);
-        Object next = null;
+    protected CayenneMapEntry evaluateEntityNode(Entity entity) {
+        Iterator<CayenneMapEntry> path = entity.resolvePathComponents(this);
+        CayenneMapEntry next = null;
         while (path.hasNext()) {
             next = path.next();
         }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbEntity.java
Mon Dec 17 04:51:42 2007
@@ -258,7 +258,7 @@
         return (Collection<DbRelationship>) super.getRelationships();
     }
 
-    public Iterator<Object> resolvePathComponents(Expression pathExp)
+    public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp)
             throws ExpressionException {
         if (pathExp.getType() != Expression.DB_PATH) {
             throw new ExpressionException("Invalid expression type: '"
@@ -603,7 +603,7 @@
             if (path.equals(relationshipPath)) {
 
                 LinkedList<String> finalPath = new LinkedList<String>();
-                Iterator<Object> it = resolvePathComponents(path);
+                Iterator<CayenneMapEntry> it = resolvePathComponents(path);
 
                 // just do one step back and one step forward to create correct joins...
                 // find last rel...
@@ -629,8 +629,8 @@
             }
 
             // case (3)
-            Iterator<Object> pathIt = resolvePathComponents(path);
-            Iterator<Object> relationshipIt = resolvePathComponents(relationshipPath);
+            Iterator<CayenneMapEntry> pathIt = resolvePathComponents(path);
+            Iterator<CayenneMapEntry> relationshipIt = resolvePathComponents(relationshipPath);
 
             // for inserts from the both ends use LinkedList
             LinkedList<String> finalPath = new LinkedList<String>();
@@ -640,7 +640,7 @@
                 DbRelationship nextDBR = (DbRelationship) relationshipIt.next();
 
                 // expression components may be attributes or relationships
-                CayenneMapEntry next = (CayenneMapEntry) pathIt.next();
+                CayenneMapEntry next = pathIt.next();
 
                 if (nextDBR != next) {
                     // found split point
@@ -662,7 +662,7 @@
 
             while (pathIt.hasNext()) {
                 // components may be attributes or relationships
-                CayenneMapEntry next = (CayenneMapEntry) pathIt.next();
+                CayenneMapEntry next = pathIt.next();
                 appendPath(finalPath, next);
             }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Entity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Entity.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Entity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Entity.java
Mon Dec 17 04:51:42 2007
@@ -281,8 +281,8 @@
      * @see #resolvePathComponents(Expression)
      */
     public Object lastPathComponent(Expression pathExp) {
-        Object last = null;
-        Iterator<Object> it = resolvePathComponents(pathExp);
+        CayenneMapEntry last = null;
+        Iterator<CayenneMapEntry> it = resolvePathComponents(pathExp);
         while (it.hasNext()) {
             last = it.next();
         }
@@ -297,7 +297,7 @@
      * return an Iterator, but an attempt to read the first invalid path component will
      * result in ExpressionException.
      */
-    public abstract Iterator<Object> resolvePathComponents(Expression pathExp)
+    public abstract Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp)
             throws ExpressionException;
 
     /**
@@ -306,13 +306,13 @@
      * entity, this method will still return an Iterator, but an attempt to read the first
      * invalid path component will result in ExpressionException.
      */
-    public Iterator<Object> resolvePathComponents(String path) throws ExpressionException
{
+    public Iterator<CayenneMapEntry> resolvePathComponents(String path) throws ExpressionException
{
         return new PathIterator(path);
     }
 
     // An iterator resolving mapping components represented by the path string.
     // This entity is assumed to be the root of the path.
-    final class PathIterator implements Iterator<Object> {
+    final class PathIterator implements Iterator<CayenneMapEntry> {
 
         private StringTokenizer toks;
         private Entity currentEnt;
@@ -329,7 +329,7 @@
             return toks.hasMoreTokens();
         }
 
-        public Object next() {
+        public CayenneMapEntry next() {
             String pathComp = toks.nextToken();
 
             // see if this is an attribute

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjAttribute.java
Mon Dec 17 04:51:42 2007
@@ -22,6 +22,7 @@
 import java.util.Iterator;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.util.CayenneMapEntry;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.util.XMLEncoder;
 import org.apache.commons.collections.IteratorUtils;
@@ -138,15 +139,15 @@
      * Returns a DbAttribute mapped by this ObjAttribute.
      */
     public DbAttribute getDbAttribute() {
-        Iterator<Object> pathIterator = getDbPathIterator();
-        Object o = null;
+        Iterator<CayenneMapEntry> pathIterator = getDbPathIterator();
+        CayenneMapEntry o = null;
         while (pathIterator.hasNext()) {
             o = pathIterator.next();
         }
         return (DbAttribute) o;
     }
 
-    public Iterator<Object> getDbPathIterator() {
+    public Iterator<CayenneMapEntry> getDbPathIterator() {
         if (dbAttributePath == null) {
             return IteratorUtils.EMPTY_ITERATOR;
         }
@@ -163,7 +164,7 @@
 
         int lastPartStart = dbAttributePath.lastIndexOf('.');
         if (lastPartStart < 0) {
-            Attribute attribute = dbEnt.getAttribute(dbAttributePath);
+            DbAttribute attribute = (DbAttribute) dbEnt.getAttribute(dbAttributePath);
             if (attribute == null) {
                 return IteratorUtils.EMPTY_ITERATOR;
             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Mon Dec 17 04:51:42 2007
@@ -812,7 +812,7 @@
         return (superEntity != null) ? superEntity.isSubentityOf(entity) : false;
     }
 
-    public Iterator<Object> resolvePathComponents(Expression pathExp) throws ExpressionException
{
+    public Iterator<CayenneMapEntry> resolvePathComponents(Expression pathExp) throws
ExpressionException {
 
         // resolve DB_PATH if we can
         if (pathExp.getType() == Expression.DB_PATH) {
@@ -896,7 +896,7 @@
 
         // TODO: make it a public method - resolveDBPathComponents or something...
         // seems generally useful
-        String toDbPath(Iterator<Object> objectPathComponents) {
+        String toDbPath(Iterator<CayenneMapEntry> objectPathComponents) {
             StringBuffer buf = new StringBuffer();
             while (objectPathComponents.hasNext()) {
                 Object component = objectPathComponents.next();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
Mon Dec 17 04:51:42 2007
@@ -31,6 +31,7 @@
 import org.apache.cayenne.exp.ExpressionException;
 import org.apache.cayenne.exp.parser.ASTDbPath;
 import org.apache.cayenne.map.event.RelationshipEvent;
+import org.apache.cayenne.util.CayenneMapEntry;
 import org.apache.cayenne.util.Util;
 import org.apache.cayenne.util.XMLEncoder;
 import org.apache.commons.lang.builder.ToStringBuilder;
@@ -539,7 +540,7 @@
         StringBuffer validPath = new StringBuffer();
 
         try {
-            Iterator<Object> it = entity.resolvePathComponents(new ASTDbPath(path));
+            Iterator<CayenneMapEntry> it = entity.resolvePathComponents(new ASTDbPath(path));
             while (it.hasNext()) {
                 DbRelationship relationship = (DbRelationship) it.next();
 
@@ -594,7 +595,7 @@
 
                 try {
                     // add new relationships from path
-                    Iterator<Object> it = entity.resolvePathComponents(new ASTDbPath(
+                    Iterator<CayenneMapEntry> it = entity.resolvePathComponents(new
ASTDbPath(
                             this.dbRelationshipPath));
 
                     while (it.hasNext()) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/EntityTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/EntityTest.java?rev=604858&r1=604857&r2=604858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/EntityTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/map/EntityTest.java
Mon Dec 17 04:51:42 2007
@@ -26,6 +26,7 @@
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.remote.hessian.service.HessianUtil;
 import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.util.CayenneMapEntry;
 import org.apache.cayenne.util.Util;
 
 public class EntityTest extends CayenneCase {
@@ -168,7 +169,7 @@
         // itertator should be returned, but when trying to read 1st component,
         // it should throw an exception....
         ObjEntity galleryEnt = getObjEntity("Gallery");
-        Iterator it = galleryEnt.resolvePathComponents(pathExpr);
+        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
         assertTrue(it.hasNext());
 
         try {
@@ -200,7 +201,7 @@
         pathExpr.setOperand(0, "galleryName");
 
         ObjEntity galleryEnt = getObjEntity("Gallery");
-        Iterator it = galleryEnt.resolvePathComponents(pathExpr);
+        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
 
         // iterator must contain a single ObjAttribute
         assertNotNull(it);
@@ -221,7 +222,7 @@
         entity.addAttribute(attribute1);
         entity.addAttribute(attribute2);
 
-        Collection attributes = entity.getAttributes();
+        Collection<? extends Attribute> attributes = entity.getAttributes();
         assertEquals(2, attributes.size());
 
         entity.removeAttribute("a1");



Mime
View raw message