That makes some sense to me. We're using ODMG, and I noticed this
happening on "supporting objects" (i.e., not an object *I* locked). Which
layer is responsible for determining all the objects that need to be
written? ODMG or PB?
David
|---------+--------------------------->
| | Thomas Mahler |
| | <[EMAIL PROTECTED]> |
| | Sent by: |
| | [EMAIL PROTECTED] |
| | |
| | |
| | 02/13/2003 03:22|
| | PM |
| | Please respond |
| | to "OJB Users |
| | List" |
| | |
|---------+--------------------------->
>--------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
| To: OJB Users List <[EMAIL PROTECTED]>
|
| cc:
|
| Subject: Re: Why is this done this way?
|
|
|
>--------------------------------------------------------------------------------------------------------------------------------------------------|
Hi David,
[EMAIL PROTECTED] wrote:
> Can someone explain the WHY behind this code fragment? It's from
> org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(Object). I
> thought there was a state kept, to determine if it's an insert or new.
The PB is a very low level kernel. It does not track states of objects.
This must be done in client code (maybe your own PB client or in a high
level object transaction manager like ODMG or JDO).
The Broker is designed in this way to keep it lean and for a clear
separation of concerns.
The broker is for basic persistence operations. ODMG and JDO are Object
level transaction managers.
> Having to load the object from the database just to write it back out
seems
> very wasteful.
If you don't know if an object is new or not you have to find out first.
this is checked by (dbAccess.materializeObject(cld, oid) == null).
If you do know that an object requires an update only you can use a
different PB method store(Object, ObjectModification) do tell OJB to not
perform a check, but use either INSERT or UPDATE as signalled by the
ObjectModification.
In fact the ODMG and JDO layers use this method as they track the state
of persistent instances.
They do things like
broker.store(instance, ObjectModificationDefaultImpl.UPDATE);
to perform an UPDATE without a prior sanity check!
cheers,
Thomas
>
> boolean doInsert = false;
> // lookup cache or db to see whether object needs insert or
> update
> if (dbAccess.materializeObject(cld, oid) == null)
> {
> doInsert = true;
> // now store it:
> }
>
>
>
> This message contains information from Equifax Inc. which may be
> confidential and privileged. If you are not an intended recipient,
please
> refrain from any disclosure, copying, distribution or use of this
> information and note that such actions are prohibited. If you have
> received this transmission in error, please notify by e-mail
> [EMAIL PROTECTED]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]