DataObjectUtils: [Was [JIRA] Created: (CAY-772)]

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Mon Mar 26 2007 - 11:57:08 EDT

  • Next message: Andrus Adamchik: "Re: Summer of Code 2007"

    > Index: framework/cayenne-jdk1.4-unpublished/src/main/java/org/
    > apache/cayenne/DataObjectUtils.java
    > ===================================================================

    >.. -51,6 +53,15 @@
    >
    > + /**
    > + * Returns a long primary key value for a persistent object.
    > Only works for single
    > + * column numeric primary keys. If an object is transient or
    > has an ObjectId that can
    > + * not be converted to a long PK, an exception is thrown.
    > + */
    > + public static long longPKForObject(Persistent dataObject) {
    > Object value = pkForObject(dataObject);
    >
    > if (!(value instanceof Number)) {
    >.. -58,7 +69,7 @@
    > + dataObject.getObjectId());
    > }
    >
    > - return ((Number) value).intValue();
    > + return ((Number) value).longValue();
    > }

    Just like with ObjectContext, we need to complete the backend work,
    before we can make it available via DataObjectUtils. Long PK support
    is defined in CAY-329.

    > + public Object objectFromDataRow(
    > + ObjectContext context,
    > + Class dataObjectClass,
    > + DataRow dataRow) {
    > + return objectFromDataRow(context, dataObjectClass,
    > dataRow, false);
    > + }
    > +
    > + public Object objectFromDataRow(
    > + ObjectContext context,
    > + Class dataObjectClass,
    > + DataRow dataRow,
    > + boolean refresh) {
    > +
    > + if (dataObjectClass == null) {
    > + throw new IllegalArgumentException("Null DataObject
    > class.");
    > + }
    > +
    > + if (dataRow == null) {
    > + return null;
    > + }
    > +
    > + ObjEntity objEntity = context
    > + .getEntityResolver()
    > + .lookupObjEntity(dataObjectClass);
    > +
    > + ObjectId rowId = buildId(dataRow, objEntity, null);
    > + int cacheType = refresh ? ObjectIdQuery.CACHE_REFRESH :
    > ObjectIdQuery.CACHE;
    > + ObjectIdQuery rowQuery = new ObjectIdQuery(rowId, false,
    > cacheType);
    > +
    > + return objectForQuery(context, rowQuery);
    > + }

    +1 for functionality, -1 for implementation. Doing an ObjectIDQuery
    here is not very efficient... This is one place where DataContext and
    client-side CayenneContext are very different... So maybe define this
    in ObjectContext???

    > + static ObjectId buildId(DataRow dataRow, ObjEntity objEntity,
    > String namePrefix) {
    > + List pk;
    > + boolean hasPrefix;
    > + Map idMap;
    > + Iterator iter;
    > +

    Seems redundant. DataRow.createObjectId() does the same thing?

    Andrus



    This archive was generated by hypermail 2.0.0 : Mon Mar 26 2007 - 11:58:00 EDT