openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fernando Padilla <f...@alum.mit.edu>
Subject Re: slices, persist?
Date Sun, 23 Nov 2008 19:37:26 GMT
Cool thank you.

The code is just complicated, I just need to wrap my head around the 
Broker code some more.  I got confused because I imagined that an 
"operation" would match a transaction.  But reviewing more code, and 
your response, it looks like an "operation" just maps to one single call 
of the broker, no matter how many calls are done within one transaction.

I guess demarcating an operation within a transaction is there to track 
all of the side-effects of an operation.. just like when you persist one 
object, but the system actually persists many objects as a side effect..

thanx


Pinaki Poddar wrote:
> 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

very weird you should say this..

> 
> "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
>> 	 * {@link 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;
>> 	}
>>
>>
> 

Mime
View raw message