Hello, All!
I have an idea to make 2 enhancements at once:
1)Performance
2)Loading object twice or more.
Problem of loading the same object twice(pseudocode):
tx.begin();
Object a = load(1);
Object b = load(1);//the same identity
a.setVar(x);
b.setVar(y);
tx.commit();

Only "a" object changes will be stored.


The idea is to check if requested object is already in current
transaction, and if it exist , get it from current transaction.
So there is not requests to cache, and if you load the same object
twice, in both cases you'll have the same instance of it inside
current transaction.

See example:
I have wrapper for org.odmg.Database
public class MyDatabase
{
public Object getByIdentity( int id, Class clazz ) throws Exception
  {
    //obtain current ODMG transaction
    TransactionImpl tx = ( TransactionImpl 
)OJBFactory.getInstance().currentTransaction();

    // obtain a broker instance from the current transaction
    PersistenceBroker broker = ( ( HasBroker )tx ).getBroker();

    Object[] pkValues = new Integer[ 1 ];
    pkValues[ 0 ] = new Integer( id );


    // identities must be unique accross extents!
    clazz = broker.getExtentClass( clazz );

    Identity identity = new Identity( clazz, pkValues );

    Object result = null;
    Object objectFromTransaction = tx.getObjectFromEnvelopeTable( identity );

    // search an object first in envelopetable, and only after
    //that - in cache.
    if( objectFromTransaction != null )
      result = objectFromTransaction;
    else
      result = broker.getObjectByIdentity( identity );

    if( result != null )
      tx.lock( result, tx.READ );

    return result;
  }

}

Changes in TransactionImpl:
new method
public Object getObjectFromEnvelopeTable( Identity id )
  {
    ObjectEnvelope env = objectEnvelopeTable.get( id );
    if( env != null)
     return env.getObject();
    else
     return null;
  }

The effect is significant: in some complicated operations code may
work 2 times faster.

Any comments?

Thank you!
Best regards,
Andrey Chernyh<[EMAIL PROTECTED]>
Plesk Inc.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to