Re: Equivalent for WebObjects localInstanceOfObject() or Toplink registerExistingObject()?

From: Mike Kienenberger (mkienen..laska.net)
Date: Tue Sep 09 2003 - 14:22:46 EDT

  • Next message: Mike Kienenberger: "Can I use java.util.Date for DataObject attribute type?"

    Andrus Adamchik <andru..bjectstyle.org> wrote:
    > > How can I use/copy an object that exists in one DataContext into another
    > > DataContext?
    > >
    > > The equivalent for WebObjects was EOUtilities.localInstanceOfObject().
    > > The equivalent for Toplink was UnitOfWork.registerExistingObject().
    > >
    > > Thanks!
    > >
    > > -Mike
    >
    > It didn't make it to 1.0. Anyway, here is a little utility method that I
    > wrote for one of my projects that does exactly that (for a list of
    > objects)
    >
    > Should probably stick it to the FAQ for now.

    Maybe you should throw it into

    ...\cayenne-1.0rc2\doc\userguide\datactxt\statemanagement.html

    otherwise users will assume that you can just use DataObjects interchangably
    between DataContexts....

    > Andrus
    >
    > public static List getLocalObjects(DataContext context, List objects)
    {
    > List localList = new ArrayList(objects.size());
    > Iterator it = objects.iterator();
    > while (it.hasNext()) {
    > DataObject obj = (DataObject) it.next();
    > if (obj.getDataContext() != context) {
    > ObjEntity ent =
    > context.getEntityResolver().lookupObjEntity(
    > obj.getObjectId().getObjClass());
    > obj =
    > context.objectFromDataRow(
    > ent,
    > obj.getCurrentSnapshot(),
    > true);
    > }
    >
    > localList.add(obj);
    > }
    > return localList;
    > }
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Sep 09 2003 - 14:19:55 EDT