You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Fernando Padilla <fe...@alum.mit.edu> on 2008/11/22 01:19:48 UTC

slices, persist?

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;
	}

Re: slices, persist?

Posted by Pinaki Poddar <pp...@apache.org>.
> it looks like an "operation" just maps to one single call of the broker, no
matter how many calls are done within one transaction.
> ust like when you persist one object, but the system actually persists
> many objects as a side effect..

Correct.

>> Not sure if this forum is the correct place for education on how (or why)
>> a
>> specific code block works (or does not;). 

> very weird you should say this..

I stand by my statement. The code written in a formal language can not be
explained in a natural language. 



-- 
View this message in context: http://n2.nabble.com/slices%2C-persist--tp1564100p1577429.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: slices, persist?

Posted by Fernando Padilla <fe...@alum.mit.edu>.
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;
>> 	}
>>
>>
> 

Re: slices, persist?

Posted by Craig L Russell <Cr...@Sun.COM>.
The dev list is the best place ever!

Craig

On Nov 23, 2008, at 11:24 AM, 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
>

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: slices, persist?

Posted by Pinaki Poddar <pp...@apache.org>.
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
> 	 * {@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;
> 	}
> 
> 

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