Not sure if this forum is the correct place for education on how (or why) a
specific code block works (or does not;). However, the following cited
inference
"it seems like within one DistributedBrokerImpl, you can only persist
against one slice"
is not true.
What the code body realizes is:
Every instance X that is an explicit argument of EntityManager.persist() and
the set of instanes {Y} that are reachable directly or indirectly from X at
the time of persist() call will be stored in Slice A where A designates that
slice as returned by DistributionPolicy.distribute(X).
So if we consider to calls in the same transaction
EntityManager.persist(X1);
EntityManager.persist(X2);
and DistributionPolicy.distribute(X1) and DistributionPolicy.distribute(X2)
return different Slices then X1 and X2 will be stored in different slices.
Fernando Padilla wrote:
>
> Still reviewing code :)
>
> So I'm looking over this, and it seems like within one
> DistributedBrokerImpl, you can only persist against one slice. Since
> the _rootSlice is set on the very first object that it tries to persist,
> and never again.
>
> So I'm new here, so I am assuming that one Broker is used per
> EntityManager, but what if I want to use one EntityManager to persist
> two kinds of objects that live in different slices.. am I just reading
> this wrong?
>
> The persist would be called on object A, the the persist would be called
> on object B, but it would use the rootSlice determined by A?
>
> Or is a broker used once per transaction. But even then I might want to
> create an object A and object B within the same "transaction".
>
> please help.
>
>
>
> /**
> * Assigns slice identifier to the resultant StateManager as initialized
> by
> * the super class implementation. The slice identifier is decided by
> * [EMAIL PROTECTED] DistributionPolicy} for given <code>pc</code> if
> it is a root
> * instance i.e. the argument of the user application's persist() call.
> The
> * cascaded instances are detected by non-empty status of the current
> * operating set. The slice is assigned only if a StateManager has never
> * been assigned before.
> */
> @Override
> public OpenJPAStateManager persist(Object pc, Object id, boolean
> explicit,
> OpCallbacks call) {
> OpenJPAStateManager sm = getStateManager(pc);
> String[] targets = null;
> boolean replicated = SliceImplHelper.isReplicated(sm);
> if (getOperatingSet().isEmpty()
> && (sm == null || sm.getImplData() == null)) {
> targets = SliceImplHelper.getSlicesByPolicy(pc,
> getConfiguration(),
> this);
> if (!replicated) {
> _rootSlice = targets[0];
> }
> }
> sm = super.persist(pc, id, explicit, call);
> if (sm.getImplData() == null) {
> if (targets == null) {
> targets = replicated
> ? SliceImplHelper.getSlicesByPolicy(pc,
> getConfiguration(), this)
> : new String[]{_rootSlice};
> }
> sm.setImplData(targets, true);
> }
> return sm;
> }
>
>
--
View this message in context:
http://n2.nabble.com/slices%2C-persist--tp1564100p1569365.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.