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

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Sep 09 2003 - 13:59:49 EDT

  • Next message: Mike Kienenberger: "Re: Equivalent for WebObjects localInstanceOfObject() or Toplink registerExistingObject()?"

    > 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.

    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 - 13:59:50 EDT