Re: Reconnecting serialized DataObjects

From: Mike Kienenberger (mkienen..mail.com)
Date: Mon Sep 26 2005 - 12:32:14 EDT

  • Next message: Andrus Adamchik: "Re: Reconnecting serialized DataObjects"

    No, the current behavior of cayenne is to not serialize the data context.

    Here's a few threads.

    http://www.objectstyle.org/cayenne/lists/cayenne-user/2003/02/0073.html

    http://www.objectstyle.org/cayenne/lists/cayenne-user/2005/03/0103.html

    http://www.objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-298

    On 9/26/05, Cris Daniluk <cris.danilu..mail.com> wrote:
    > Wouldn't the data context be serialized alongside the objects, and if
    > so, why would the context and object ever mismatch? Maybe I'm missing
    > something...
    >
    > Cris
    >
    > On 9/23/05, Mike Kienenberger <mkienen..mail.com> wrote:
    > > What are others doing to handle reconnecting serialized DataObjects
    > > back to a DataContext?
    > >
    > > My current situation is that JSF serializes all of my DataObjects
    > > between requests, and I'm using this code to restore them. However, I
    > > suspect this code doesn't properly handle the case where the data
    > > context may change.
    > >
    > > Kevin's thread "CayenneDataObject#setDataContext()" has me worried
    > > that I need to do more than what I'm currently doing.
    > >
    > > [In the code below, currentDataContext may or may not be the original
    > > DataContext, although I think my dataContext has remained unchanged so
    > > far.]
    > >
    > > public void reconnect(Object object)
    > > {
    > > if (null == object) return;
    > >
    > > if (false == (object instanceof DataObject))
    > > throw new
    > > IllegalArgumentException(object.getClass().getName() + " is not a
    > > DataObject.");
    > >
    > > DataObject dataObject = (DataObject)object;
    > >
    > > if (null != dataObject.getDataContext()) return;
    > >
    > > dataObject.setDataContext(currentDataContext);
    > >
    > > EntityResolver entityResolver = currentDataContext.getEntityResolver();
    > > ObjEntity objEntity = entityResolver.lookupObjEntity(dataObject);
    > >
    > > // initialize to-many relationships with a fault
    > > Iterator it = objEntity.getRelationships().iterator();
    > > while (it.hasNext()) {
    > > ObjRelationship rel = (ObjRelationship) it.next();
    > > if (rel.isToMany()) {
    > > dataObject.writePropertyDirectly(rel.getName(),
    > > Fault.getToManyFault());
    > > Object relObject =
    > > dataObject.readPropertyDirectly(rel.getName());
    > > if (relObject instanceof List)
    > > {
    > > List relList = (List)relObject;
    > > Iterator relObjectIterator = relList.iterator();
    > > while (relObjectIterator.hasNext())
    > > {
    > > DataObject relDataObject = (DataObject)
    > > relObjectIterator.next();
    > > reconnect(relDataObject);
    > > }
    > > }
    > > }
    > > else
    > > {
    > > Object relObject =
    > > dataObject.readPropertyDirectly(rel.getName());
    > > if (relObject instanceof DataObject) reconnect(relObject);
    > > }
    > > }
    > > }
    > >
    >



    This archive was generated by hypermail 2.0.0 : Mon Sep 26 2005 - 12:32:16 EDT