You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/11/17 00:24:10 UTC

svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Author: aadamchik
Date: Fri Nov 16 15:24:09 2007
New Revision: 595869

URL: http://svn.apache.org/viewvc?rev=595869&view=rev
Log:
java5 : generics

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectId.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/query/ParameterizedQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java?rev=595869&r1=595868&r2=595869&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java Fri Nov 16 15:24:09 2007
@@ -46,24 +46,24 @@
      * Returns a collection of objects that are registered with this ObjectContext and
      * have a state PersistenceState.NEW
      */
-    Collection newObjects();
+    Collection<?> newObjects();
 
     /**
      * Returns a collection of objects that are registered with this ObjectContext and
      * have a state PersistenceState.DELETED
      */
-    Collection deletedObjects();
+    Collection<?> deletedObjects();
 
     /**
      * Returns a collection of objects that are registered with this ObjectContext and
      * have a state PersistenceState.MODIFIED
      */
-    Collection modifiedObjects();
+    Collection<?> modifiedObjects();
 
     /**
      * Returns a collection of MODIFIED, DELETED or NEW objects.
      */
-    Collection uncommittedObjects();
+    Collection<?> uncommittedObjects();
 
     /**
      * Returns an object local to this ObjectContext and matching the ObjectId. If

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectId.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectId.java?rev=595869&r1=595868&r2=595869&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectId.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ObjectId.java Fri Nov 16 15:24:09 2007
@@ -62,7 +62,7 @@
     }
 
     /**
-     * Creates a TEMPORARY ObjectId. Assignes a generated unique key.
+     * Creates a TEMPORARY ObjectId. Assigns a generated unique key.
      * 
      * @since 1.2
      */

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=595869&r1=595868&r2=595869&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 Fri Nov 16 15:24:09 2007
@@ -539,13 +539,13 @@
      */
     List appendCustomColumns(List columns, SelectQuery query) {
 
-        List customAttributes = query.getCustomDbAttributes();
+        List<String> customAttributes = query.getCustomDbAttributes();
         DbEntity table = getRootDbEntity();
         int len = customAttributes.size();
 
         for (int i = 0; i < len; i++) {
-            DbAttribute attribute = (DbAttribute) table
-                    .getAttribute((String) customAttributes.get(i));
+            DbAttribute attribute = (DbAttribute) table.getAttribute(customAttributes
+                    .get(i));
             if (attribute == null) {
                 throw new CayenneRuntimeException("Attribute does not exist: "
                         + customAttributes.get(i));

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ParameterizedQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ParameterizedQuery.java?rev=595869&r1=595868&r2=595869&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ParameterizedQuery.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/ParameterizedQuery.java Fri Nov 16 15:24:09 2007
@@ -36,5 +36,5 @@
      * parameters. In case of select queries, it is up to the implementing query to name
      * the new query to avoid cache key conflicts.
      */
-    public Query createQuery(Map parameters);
+    public Query createQuery(Map<?,?> parameters);
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java?rev=595869&r1=595868&r2=595869&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/query/SelectQuery.java Fri Nov 16 15:24:09 2007
@@ -22,12 +22,10 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
@@ -50,8 +48,8 @@
     public static final String DISTINCT_PROPERTY = "cayenne.SelectQuery.distinct";
     public static final boolean DISTINCT_DEFAULT = false;
 
-    protected List customDbAttributes;
-    protected List orderings;
+    protected List<String> customDbAttributes;
+    protected List<Ordering> orderings;
     protected boolean distinct;
 
     SelectQueryMetadata selectInfo = new SelectQueryMetadata();
@@ -70,7 +68,7 @@
     }
 
     /**
-     * Creates a SelectQuery for the specifed ObjEntity with the given qualifier
+     * Creates a SelectQuery for the specified ObjEntity with the given qualifier
      * 
      * @param root the ObjEntity this SelectQuery is for.
      * @param qualifier an Expression indicating which objects should be fetched
@@ -85,7 +83,7 @@
      * 
      * @param rootClass the Class of objects fetched by this query.
      */
-    public SelectQuery(Class rootClass) {
+    public SelectQuery(Class<?> rootClass) {
         this(rootClass, null);
     }
 
@@ -95,12 +93,12 @@
      * 
      * @param rootClass the Class of objects fetched by this query.
      */
-    public SelectQuery(Class rootClass, Expression qualifier) {
+    public SelectQuery(Class<?> rootClass, Expression qualifier) {
         init(rootClass, qualifier);
     }
 
     /**
-     * Creates a SelectQuery for the specifed DbEntity.
+     * Creates a SelectQuery for the specified DbEntity.
      * 
      * @param root the DbEntity this SelectQuery is for.
      * @since 1.1
@@ -110,7 +108,7 @@
     }
 
     /**
-     * Creates a SelectQuery for the specifed DbEntity with the given qualifier.
+     * Creates a SelectQuery for the specified DbEntity with the given qualifier.
      * 
      * @param root the DbEntity this SelectQuery is for.
      * @param qualifier an Expression indicating which objects should be fetched
@@ -192,7 +190,7 @@
      * 
      * @since 1.1
      */
-    public void initWithProperties(Map properties) {
+    public void initWithProperties(Map<?,?> properties) {
 
         // must init defaults even if properties are empty
         if (properties == null) {
@@ -241,7 +239,7 @@
         }
         else if (root instanceof Class) {
             rootType = QueryBuilder.JAVA_CLASS_ROOT;
-            rootString = ((Class) root).getName();
+            rootString = ((Class<?>) root).getName();
         }
 
         if (rootType != null) {
@@ -271,9 +269,7 @@
 
         // encode orderings
         if (orderings != null && !orderings.isEmpty()) {
-            Iterator it = orderings.iterator();
-            while (it.hasNext()) {
-                Ordering ordering = (Ordering) it.next();
+            for (Ordering ordering : orderings) {
                 ordering.encodeAsXML(encoder);
             }
         }
@@ -286,7 +282,7 @@
      * A shortcut for {@link #queryWithParameters(Map, boolean)}that prunes parts of
      * qualifier that have no parameter value set.
      */
-    public SelectQuery queryWithParameters(Map parameters) {
+    public SelectQuery queryWithParameters(Map<?,?> parameters) {
         return queryWithParameters(parameters, true);
     }
 
@@ -297,7 +293,7 @@
      * @see org.apache.cayenne.exp.Expression#expWithParameters(java.util.Map, boolean)
      *      parameter substitution.
      */
-    public SelectQuery queryWithParameters(Map parameters, boolean pruneMissing) {
+    public SelectQuery queryWithParameters(Map<?,?> parameters, boolean pruneMissing) {
         // create a query replica
         SelectQuery query = new SelectQuery();
         query.setDistinct(distinct);
@@ -342,7 +338,7 @@
      * 
      * @since 1.1
      */
-    public Query createQuery(Map parameters) {
+    public Query createQuery(Map<?,?> parameters) {
         return queryWithParameters(parameters);
     }
 
@@ -356,18 +352,18 @@
     /**
      * Adds a list of orderings.
      */
-    public void addOrderings(List orderings) {
+    public void addOrderings(List<Ordering> orderings) {
         nonNullOrderings().addAll(orderings);
     }
 
     /** Adds ordering specification to this query orderings. */
     public void addOrdering(String sortPathSpec, boolean isAscending) {
-        this.addOrdering(new Ordering(sortPathSpec, isAscending));
+        addOrdering(new Ordering(sortPathSpec, isAscending));
     }
 
     /** Adds ordering specification to this query orderings. */
     public void addOrdering(String sortPathSpec, boolean isAscending, boolean ignoreCase) {
-        this.addOrdering(new Ordering(sortPathSpec, isAscending, ignoreCase));
+        addOrdering(new Ordering(sortPathSpec, isAscending, ignoreCase));
     }
 
     /**
@@ -384,7 +380,7 @@
     /**
      * Returns a list of orderings used by this query.
      */
-    public List getOrderings() {
+    public List<Ordering> getOrderings() {
         return (orderings != null) ? orderings : Collections.EMPTY_LIST;
     }
 
@@ -413,20 +409,13 @@
     /**
      * Returns a list of attributes that will be included in the results of this query.
      */
-    public List getCustomDbAttributes() {
+    public List<String> getCustomDbAttributes() {
         // if query root is DbEntity, and no custom attributes
         // are defined, return DbEntity attributes.
         if ((customDbAttributes == null || customDbAttributes.isEmpty())
                 && (root instanceof DbEntity)) {
-            Collection attributes = ((DbEntity) root).getAttributes();
-            List attributeNames = new ArrayList(attributes.size());
-            Iterator it = attributes.iterator();
-            while (it.hasNext()) {
-                DbAttribute attribute = (DbAttribute) it.next();
-                attributeNames.add(attribute.getName());
-            }
-
-            return attributeNames;
+            Collection<String> names = ((DbEntity) root).getAttributeMap().keySet();
+            return new ArrayList<String>(names);
         }
         else {
             return (customDbAttributes != null)
@@ -444,7 +433,7 @@
         nonNullCustomDbAttributes().add(attributePath);
     }
 
-    public void addCustomDbAttributes(List attrPaths) {
+    public void addCustomDbAttributes(List<String> attrPaths) {
         nonNullCustomDbAttributes().addAll(attrPaths);
     }
 
@@ -623,9 +612,9 @@
      * 
      * @since 1.2
      */
-    List nonNullCustomDbAttributes() {
+    List<String> nonNullCustomDbAttributes() {
         if (customDbAttributes == null) {
-            customDbAttributes = new ArrayList();
+            customDbAttributes = new ArrayList<String>();
         }
 
         return customDbAttributes;
@@ -636,9 +625,9 @@
      * 
      * @since 1.2
      */
-    List nonNullOrderings() {
+    List<Ordering> nonNullOrderings() {
         if (orderings == null) {
-            orderings = new ArrayList();
+            orderings = new ArrayList<Ordering>(3);
         }
 
         return orderings;

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java?rev=595869&r1=595868&r2=595869&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/remote/IncrementalSelectQuery.java Fri Nov 16 15:24:09 2007
@@ -200,7 +200,7 @@
         return query.getCachePolicy();
     }
 
-    public List getCustomDbAttributes() {
+    public List<String> getCustomDbAttributes() {
         return query.getCustomDbAttributes();
     }
 
@@ -212,7 +212,7 @@
         return query.getName();
     }
 
-    public List getOrderings() {
+    public List<Ordering> getOrderings() {
         return query.getOrderings();
     }
 



Re: svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 17/11/2007, at 11:34 AM, Aristedes Maniatis wrote:

>
> On 17/11/2007, at 11:19 AM, Andrus Adamchik wrote:
>
>> I have no idea. I am just overwhelmed with millions of Eclipse  
>> warnings :-)
>
>> Anyone else has a reference?
>>
>> Andrus
>
>
> I found these articles the best for tips and tricks when I was first  
> working on generics:
>
> http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html
> http://www.ibm.com/developerworks/java/library/j-jtp01255.html
>
>
> Ari


I came across that article about the subtleties of using <?> and  
<Object>:

http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html

down under the heading "Type Parameter Wildcards" especially. There is  
no clear rule about when to use each, but the notes there are quite  
helpful I think.


Ari





-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: svn commit: ec - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Robert Zeigler <ro...@puregumption.com>.
<?> is appropriate.
Unless you want to parameterize the method. But otherwise, yes, <?> is  
the right choice.
List<Object> says it's a list of objects. It can only be assigned to a  
to list of objects.
List<?> says it's a list of something, but you don't know what.
Those are two slightly different statements.
For example:

List<Object> foo1 = new ArrayList<Object>(); //legal
List<?> foo2 = new ArrayList<Object>(); //also legal.
List<Object> foo3 = new ArrayList<Persistent>(); //illegal; you'll get  
a compile-time error.
List<?> foo4 = new ArrayList<Persistent>();//this is legal.

other comments...
foo1.add(somePersistentObject); will be legal.
foo4.add(somePersistentObject) will NOT be legal, because foo4 is of  
wildctionard.

The other option, as i mentioned, is to parameterize your method...

public <T> List<T> getSomeCollection() { }

Or even
public <T extends Persistent> List<T> getSomeCollection();

Robert

On Nov 18, 2007, at 11/189:08 AM , Andrus Adamchik wrote:

> Didn't find an answer for this particular case in the articles below  
> (although they were informative otherwise)... Looking at the JDK's  
> own classes, I see a few of "Collection<?> getSomething()" methods  
> in various places.
>
> Andrus
>
>
> On Nov 16, 2007, at 7:34 PM, Aristedes Maniatis wrote:
>
>>
>> On 17/11/2007, at 11:19 AM, Andrus Adamchik wrote:
>>
>>> I have no idea. I am just overwhelmed with millions of Eclipse  
>>> warnings :-)
>>
>>> Anyone else has a reference?
>>>
>>> Andrus
>>
>>
>> I found these articles the best for tips and tricks when I was  
>> first working on generics:
>>
>> http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html
>> http://www.ibm.com/developerworks/java/library/j-jtp01255.html
>>
>>
>> Ari
>>
>>
>> -------------------------->
>> ish
>> http://www.ish.com.au
>> Level 1, 30 Wilson Street Newtown 2042 Australia
>> phone +61 2 9550 5001   fax +61 2 9550 4001
>> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>>
>>
>>
>


Re: svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Andrus Adamchik <an...@objectstyle.org>.
Didn't find an answer for this particular case in the articles below  
(although they were informative otherwise)... Looking at the JDK's  
own classes, I see a few of "Collection<?> getSomething()" methods in  
various places.

Andrus


On Nov 16, 2007, at 7:34 PM, Aristedes Maniatis wrote:

>
> On 17/11/2007, at 11:19 AM, Andrus Adamchik wrote:
>
>> I have no idea. I am just overwhelmed with millions of Eclipse  
>> warnings :-)
>
>> Anyone else has a reference?
>>
>> Andrus
>
>
> I found these articles the best for tips and tricks when I was  
> first working on generics:
>
> http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html
> http://www.ibm.com/developerworks/java/library/j-jtp01255.html
>
>
> Ari
>
>
> -------------------------->
> ish
> http://www.ish.com.au
> Level 1, 30 Wilson Street Newtown 2042 Australia
> phone +61 2 9550 5001   fax +61 2 9550 4001
> GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A
>
>
>


Re: svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Aristedes Maniatis <ar...@ish.com.au>.
On 17/11/2007, at 11:19 AM, Andrus Adamchik wrote:

> I have no idea. I am just overwhelmed with millions of Eclipse  
> warnings :-)

> Anyone else has a reference?
>
> Andrus


I found these articles the best for tips and tricks when I was first  
working on generics:

http://www.onjava.com/pub/a/onjava/excerpt/javaian5_chap04/index.html
http://www.ibm.com/developerworks/java/library/j-jtp01255.html


Ari


-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A



Re: svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Andrus Adamchik <an...@objectstyle.org>.
I have no idea. I am just overwhelmed with millions of Eclipse  
warnings :-)

Anyone else has a reference?

Andrus

On Nov 16, 2007, at 6:56 PM, Aristedes Maniatis wrote:
>
> On 17/11/2007, at 10:24 AM, aadamchik@apache.org wrote:
>
>>      * Returns a collection of objects that are registered with  
>> this ObjectContext and
>>      * have a state PersistenceState.NEW
>>      */
>> -    Collection newObjects();
>> +    Collection<?> newObjects();
>
> Is that right? As I understand it, <?> should be used when you have  
> one type of object and you don't know which which type it is, but  
> <Object> should be used when you have a mixture of different types  
> of object.
>
> I don't have a reference for that right now, but that was my  
> recollection.
>
> Ari
>
>
>
> -------------------------->
> Aristedes Maniatis
> phone +61 2 9660 9700
> PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8
>
>
>


Re: svn commit: r595869 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: ./ access/trans/ query/ remote/

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 17/11/2007, at 10:24 AM, aadamchik@apache.org wrote:

>      * Returns a collection of objects that are registered with this  
> ObjectContext and
>      * have a state PersistenceState.NEW
>      */
> -    Collection newObjects();
> +    Collection<?> newObjects();

Is that right? As I understand it, <?> should be used when you have  
one type of object and you don't know which which type it is, but  
<Object> should be used when you have a mixture of different types of  
object.

I don't have a reference for that right now, but that was my  
recollection.

Ari



-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2  A9 BF 2D 48 C2 20 0C C8