FAQ
Hi,

I am doing today my usual updated maven depencies for our future product
release, so I am migrating my 3.1 code to the new 3.2 generics style and
I missed that all the generics code uses just T as "T extends Object"
and not "T extends DataObject" (or maybe another superinterface wich
makes sense) it is not a serious issue but it can help avoiding runtime
errors if you miss the correct class name.

Also I miss a generics typed version of objectForQuery I did it for
myself so maybe you can include it in the next version:

// Must add context as parameter
      protected <U extends DataObject, T extends Select<U>> U
objectForQuery (T query) {
          List<U> objects = getThreadDataContext().select(query);

          if (objects.size() == 0) {
              return null;
          } else if (objects.size() > 1) {
              throw new CayenneRuntimeException("Expected zero or one
object, instead query matched: " + objects.size());
          }

          return objects.get(0);
      }

I will tell you if I find something worth noting.

Best regards.

Ramiro Aparicio

Search Discussions

  • John Huss at Nov 11, 2013 at 5:58 pm
    objectForQuery = ObjectContext.selectOne

    I'm not in front of the code right now, but I believe the type parameter is
    unbounded to allow for fetching data rows as well, which are not
    DataObjects or Persistent or anything.

    John

    On Mon, Nov 11, 2013 at 11:48 AM, Ramiro Aparicio wrote:

    Hi,

    I am doing today my usual updated maven depencies for our future product
    release, so I am migrating my 3.1 code to the new 3.2 generics style and I
    missed that all the generics code uses just T as "T extends Object" and
    not "T extends DataObject" (or maybe another superinterface wich makes
    sense) it is not a serious issue but it can help avoiding runtime errors if
    you miss the correct class name.

    Also I miss a generics typed version of objectForQuery I did it for myself
    so maybe you can include it in the next version:

    // Must add context as parameter
    protected <U extends DataObject, T extends Select<U>> U objectForQuery
    (T query) {
    List<U> objects = getThreadDataContext().select(query);

    if (objects.size() == 0) {
    return null;
    } else if (objects.size() > 1) {
    throw new CayenneRuntimeException("Expected zero or one
    object, instead query matched: " + objects.size());
    }

    return objects.get(0);
    }

    I will tell you if I find something worth noting.

    Best regards.

    Ramiro Aparicio
  • Andrus Adamchik at Nov 11, 2013 at 6:07 pm
    Hi,

    Thanks for the feedback! Good to have that for 3.2.
    all the generics code uses just T as "T extends Object" and not "T extends DataObject" (or maybe another superinterface wich makes sense)
    Some of it is because query result can be a DataRow, or an Object[]. Other places (like “deleteObjects”) should indeed be changed to something like T extends Peristent. Agreed.
    Also I miss a generics typed version of objectForQuery I did it for myself so maybe you can include it in the next version:
    This API continues to evolve on trunk. E.g. we don’t have Cayenne.objectForSelect, but there’s a better method now - ObjectContext.selectOne(..) :

    http://svn.apache.org/repos/asf/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/ObjectContext.java

    Further comments are certainly welcomed.

    Andrus
    On Nov 11, 2013, at 8:48 PM, Ramiro Aparicio wrote:

    Hi,

    I am doing today my usual updated maven depencies for our future product release, so I am migrating my 3.1 code to the new 3.2 generics style and I missed that all the generics code uses just T as "T extends Object" and not "T extends DataObject" (or maybe another superinterface wich makes sense) it is not a serious issue but it can help avoiding runtime errors if you miss the correct class name.

    Also I miss a generics typed version of objectForQuery I did it for myself so maybe you can include it in the next version:

    // Must add context as parameter
    protected <U extends DataObject, T extends Select<U>> U objectForQuery (T query) {
    List<U> objects = getThreadDataContext().select(query);

    if (objects.size() == 0) {
    return null;
    } else if (objects.size() > 1) {
    throw new CayenneRuntimeException("Expected zero or one object, instead query matched: " + objects.size());
    }

    return objects.get(0);
    }

    I will tell you if I find something worth noting.

    Best regards.

    Ramiro Aparicio

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedNov 11, '13 at 5:48p
activeNov 11, '13 at 6:07p
posts3
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase