Hi,

I'm trying to understand Castor's locking mechanism for object graphs.

Say I have the following classes:

class Book {

    int id;

    String author;

    ...
}

class Customer {

    int id;

    // Assume this will be a collection of Books that
    // has been browsed by each customer.
    Collection booksBrowsed;

    // Assume that this is the transaction history of
    // each customer, so a collection of Transaction
    // objects
    Collection transactions;

    Date lastLoginTime;

    ...
}

class Transaction {

    int id;

    Date purchaseTime;

    Book item;

    ...
}

If I have client code that does something like the following:


Database db = getDatabase();
db.begin();
db.load(Customer.class, 3, Database.Shared);

// do some long operation here

customer.setLastLoginTime(Calendar.getInstance().getTime());
db.commit();
db.close();


Is there a lock held on all of the objects in the collections in the Customer object? Or is a lock only obtained on the Customer object when the transaction is ending and Castor can examine each object, see if it's dirty and thus needs to get a lock to update the object?

Second related part. I'm very familiar with http://www.castor.org/jdo-best-practice.html, but I was curious about another aspect. Assume that I re-write the client to try to minimize the transaction:


Database db = getDatabase();
db.begin();
db.load(Customer.class, 3, Database.ReadOnly);
db.commit();
db.close();

// do some long operation here
db.begin();
db.load(Customer.class, 3, Database.Shared);
customer.setLastLoginTime(Calendar.getInstance().getTime());
db.commit();
db.close();


Again, what gets locked? Is it the entire object graph, or just the dirty objects?

Presumably the latter code sample is the recommended way to go, irrespective of how the object graph gets locked?

Cheers,

James

---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email

Reply via email to