cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <blackn...@gmail.com>
Subject Re: Creating a fault for an ObjectId
Date Wed, 15 Feb 2017 16:31:12 GMT
Hi Maik,

Would it be possible to use child DataContexts and then push the changes up
to the parent?


On Wed, Feb 15, 2017 at 11:17 AM, Musall, Maik <maik@selbstdenker.ag> wrote:

> The use case is as follows.
>
> I have a large collection of objects which I want some function to be
> executed on. I want to use multiple threads to do this, so AFAIK I have to
> use separate ObjectContexts per thread like in EOF. So, I will then
> instantiate those objects in the per-thread contexts, do the processing,
> but then the wrapper function should return the entire collection of
> processed objects in the original context that they were in at the
> beginning.
>
> With EOF, I have a snapshot cache that will contain the changed
> attributes, but the EO instances in the original context have their
> original values. So, I will then call ec.faultForGlobalID() to have them
> refaulted from the snapshot cache, avoiding to refetch 100.000 objects from
> db.
>
> I suppose using a shared cache would make the problem obsolete, as those
> objects would receive changed attributes automatically, but I'm still on
> the fence whether or not to use a shared cache, because it's a major
> behavioural difference to EOF and I still have to think about that while
> migrating my project.
>
> Maik
>
>
> > Am 15.02.2017 um 15:49 schrieb Ken Anderson <ken.anderson@amphorainc.com
> >:
> >
> > Yes, use the objectID to pass around, but on the receiving end, you
> should turn it into a fault and release it into the wild.  Then, if some
> code needs it, the fault fires, otherwise – no DB activity.
> >
> > Ken Anderson
> > CTO Amphora, Inc.
> > Mobile:   +1 914 262 8540
> >
> >
> >
> > www.amphorainc.com <http://www.amphorainc.com/>
> >
> >
> >
> >
> > On 2/15/17, 10:47 AM, "Amedeo Mantica" <amedeomantica@me.com> wrote:
> >
> >    I would just use the ObjectId
> >
> >> On 15 Feb 2017, at 16:45, Hugi Thordarson <hugi@karlmenn.is> wrote:
> >>
> >> It can be useful in some cases—one example is if you want to be able to
> pass objects around in an API without triggering a DB fetch unless they are
> actually used.
> >>
> >> Cheers,
> >> - hugi
> >>
> >>
> >>> On 15. feb. 2017, at 15:28, Amedeo Mantica <amedeomantica@me.com>
> wrote:
> >>>
> >>> no worries, but I cannot understand your goal, why do you want to get
> the fault ?
> >>>
> >>>> On 15 Feb 2017, at 16:25, Hugi Thordarson <hugi@karlmenn.is> wrote:
> >>>>
> >>>> Thanks Ken, but the immediate fetch performed by Cayenne.objectForPk
> is precisely what I’d like to avoid.
> >>>>
> >>>> Cheers,
> >>>> - hugi
> >>>>
> >>>> S: Amedeo, sorry about calling you “Amadeo” in my last post. I have
> been properly lambasted.
> >>>>
> >>>>
> >>>>> On 15. feb. 2017, at 15:20, Ken Anderson <
> ken.anderson@amphorainc.com> wrote:
> >>>>>
> >>>>> I do this:
> >>>>>
> >>>>> dataObject = (DataObject) Cayenne.objectForPK(getObjectContext(),
> MyEntity.class, oid);
> >>>>>
> >>>>> But it will do the fetch if it’s not already in cache.
> >>>>>
> >>>>> Ken
> >>>>>
> >>>>> Ken Anderson
> >>>>> CTO Amphora, Inc.
> >>>>> Mobile:   +1 914 262 8540
> >>>>>
> >>>>>
> >>>>>
> >>>>> www.amphorainc.com <http://www.amphorainc.com/>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> On 2/15/17, 9:59 AM, "Hugi Thordarson" <hugi@karlmenn.is>
wrote:
> >>>>>
> >>>>> Thanks Amadeo, but I ended up creating a method that looks like
> this. It would be nice to get some feedback on it, if I’m violating any
> Cayenne Commandments.
> >>>>>
> >>>>> /**
> >>>>> * @return An existing object or fault if registered with the OC,
> otherwise creates a new hollow object based on the given ObjectId.
> >>>>> */
> >>>>> public static Persistent faultForObjectId( ObjectContext oc,
> ObjectId objectId ) {
> >>>>> Persistent object = (Persistent) oc.getGraphManager().getNode(
> objectId );
> >>>>>
> >>>>> if( object == null ) {
> >>>>> ClassDescriptor descriptor = oc.getEntityResolver().
> getClassDescriptor(objectId.getEntityName());
> >>>>>
> >>>>> object = (Persistent) descriptor.createObject();
> >>>>>
> >>>>> object.setPersistenceState(PersistenceState.HOLLOW);
> >>>>> object.setObjectContext(oc);
> >>>>> object.setObjectId(objectId);
> >>>>>
> >>>>> oc.getGraphManager().registerNode(objectId, object);
> >>>>> }
> >>>>>
> >>>>> return object;
> >>>>> }
> >>>>>
> >>>>> Cheers,
> >>>>> - hugi
> >>>>>
> >>>>>
> >>>>>> On 15. feb. 2017, at 14:41, Amedeo Mantica <amedeomantica@me.com>
> wrote:
> >>>>>>
> >>>>>> may be you want invalidateObject ?
> >>>>>>
> >>>>>>> On 15 Feb 2017, at 14:15, Hugi Thordarson <hugi@karlmenn.is>
> wrote:
> >>>>>>>
> >>>>>>> Hi all,
> >>>>>>> I need to get a fault for an ObjectId from an ObjectContext.
How
> would I do this?
> >>>>>>>
> >>>>>>> I don’t see any public API for this—the implementation
of
> createFault in CayenneContext seems to get me halfway there, but it will
> not return an existing fault, only create new ones.
> >>>>>>>
> >>>>>>> Cheers,
> >>>>>>> - hugi
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> Confidentiality Notice: This e-mail and accompanying documents
> contain confidential information intended for a specific individual and
> purpose. This e-mailed information is private and protected by law. If you
> are not the intended recipient, you are hereby notified that any
> disclosure, copying, or distribution, or the taking of any action based on
> the contents of this information, is strictly prohibited.
> >>>>
> >>>
> >>
> >
> >
> >
> > Confidentiality Notice: This e-mail and accompanying documents contain
> confidential information intended for a specific individual and purpose.
> This e-mailed information is private and protected by law. If you are not
> the intended recipient, you are hereby notified that any disclosure,
> copying, or distribution, or the taking of any action based on the contents
> of this information, is strictly prohibited.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message