Thomas,

I have a modified version of castor that provides the ability to expire a
single object, or a class of objects, from the performance cache.  I have
attached a javadoc page that contains a description of the method
"expireCache" that I added to class "Database" that exposes this
functionality.  This is a modified version of a similar enhancement I posted
awhile back.  This enhancement has been tested using the base set of tests
provided by the castor test framework, in addition to two new test cases I
developed specifically to test this functionality.  I have also tested it in
our internal development environment under load.

I have not submitted this enhancement for integration into the castor
project since we are not yet using this code in a production environment.  I
would prefer to wait until it has been proven in a production environment
before submitting it for integration into the project.  But, I will provide
the code and/or a modified set of 0.9.3.19 jars, to whomever requests a
copy.  Please let me know if you are interested.

Vince


-----Original Message-----
From: Thomas Phan [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 15, 2002 12:57 AM
To: [EMAIL PROTECTED]
Subject: [castor-dev] Performance cache in a clustered environment


Hi,

> Got the below from a previous post on Thu, 16 Aug 2001 01:37:32 -0700 by
Tim Fox:
>
> We're considering building clustering on top of castor using JMS - just in
the ideas stage at the moment but goes something like the following:
> 1. Object is inserted/update/deleted in the db (Castor cache is
write-through so all changes committed in db at end of transaction)
> 2. Send a message via JMS topic - with the object class and id
> 3. When message arrives at other instances of Castor - invalidate object
from cache so it is reread when next requested.
> This should be quite easy to set-up
>
> Only problem is there doesn't seem to be a Castor method that invalidates
an object from the cache as far as I know (anyone please correct me if I'm
wrong) - see (one of my) previous mails.
> I guess you could explicitly load the object using an OQL query
(apparently this always bypasses the cache and goes straight to the db) -
although I don't see how this would deal with the case when the object has
been deleted - (since the object won't be in the results of the query in
that case).
> So the question is.. does such a method exist??

I wonder about the clustering feature in Castor? Will something like the
above be implemented, or has been implemented? I personally think that the
above design is great for a distributed J2EE application. It'd be cool to
use Castor with JBoss 3 Cluster. Otherwise, we will consider OJB, or EJB2

Thanks

Thomas

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Title: Castor JavaDoc: Interface Database

org.exolab.castor.jdo
Interface Database

All Known Implementing Classes:
DatabaseImpl

public interface Database

An open connection to the database. This object represents an open connection to the database that can be used to perform transactional operations on the database.

Database operations can only be performed in the context of a transaction. Client applications should begin and commit a transaction using the begin() and commit() methods. Server applications should use implicit transaction demaraction by the container or explicit transaction demarcation using javax.transaction.UserTransaction.

All objects queried and created during a transaction are persistent. Changes to persistent objects will be stored in the database when the transaction commits. Changes will not be stored if the transaction is rolled back or fails to commit.

Once the transaction has committed or rolled back, all persistent objects become transient. Opening a new transaction does not make these objects persistent.

For example:

 Database     db;
 Query        oql;
 QueryResults results;
 Product      prod;

 // Open a database and start a transaction
 db = jdo.getDatabase();
 db.begin();
 // Select all the products in a given group
 oql = db.getOQLQuery( "SELECT p FROM Product p WHERE group=$");
 oql.bind( groupId );
 results = oql.execute();
 while ( results.hasMore() ) {
   // A 25% mark down for each product and mark as sale
   prod = (Product) results.next();
   prod.markDown( 0.25 );
   prod.setOnSale( true );
 }
 // Commit all changes, close the database
 db.commit();
 db.close();
 

Version:
$Revision: 1.30 $ $Date: 2002/02/15 20:48:46 $
Author:
Assaf Arkin
See Also:
JDO.getDatabase(), Query

Field Summary
static short DbLocked
          Database lock access.
static short Exclusive
          Exclusive access.
static short ReadOnly
          Read only access.
static short Shared
          Shared access.
 
Method Summary
 void begin()
          Begin a new transaction.
 void checkpoint()
          Deprecated. Use commit() and rollback() instead; this method cannot be implemented properly with multiple type of locks and will not be supported in future versions of the API
 void close()
          Closes the database.
 void commit()
          Commits and closes the transaction.
 void create(java.lang.Object object)
          Creates a new object in persistent storage.
 void deletePersistent(java.lang.Object object)
          Deprecated. See remove(java.lang.Object)
 void expireCache(java.lang.Class[] type, java.lang.Object[] identity)
          Expire objects from the cache.
 java.lang.ClassLoader getClassLoader()
          Returns the current ClassLoader if one has been set for this Database instance.
 java.lang.Object getIdentity(java.lang.Object object)
          Returns the object's identity.
 OQLQuery getOQLQuery()
          Creates an OQL query with no statement.
 OQLQuery getOQLQuery(java.lang.String oql)
          Creates an OQL query from the supplied statement.
 Query getQuery()
          Creates an empty query.
 PersistenceInfoGroup getScope()
           
 boolean isActive()
          Returns true if a transaction is currently active.
 boolean isAutoStore()
          Return if the current transaction is set to autoStore, it there is transaction active.
 boolean isClosed()
          Returns true if the database is closed.
 boolean isPersistent(java.lang.Object object)
          Returns true if the object is persistent.
 java.lang.Object load(java.lang.Class type, Complex identity)
          Load an object of the specified type and given identity which spans on more than one fields.
 java.lang.Object load(java.lang.Class type, Complex identity, short accessMode)
          Experimental
 java.lang.Object load(java.lang.Class type, java.lang.Object identity)
          Load an object of the specified type and given identity.
 java.lang.Object load(java.lang.Class type, java.lang.Object identity, java.lang.Object object)
          Experimental
 java.lang.Object load(java.lang.Class type, java.lang.Object identity, short accessMode)
          Experimental
 void lock(java.lang.Object object)
          Acquire a soft write lock on the object.
 void makePersistent(java.lang.Object object)
          Deprecated. See create(java.lang.Object)
 void remove(java.lang.Object object)
          Removes the object from persistent storage.
 void rollback()
          Rolls back and closes the transaction.
 void setAutoStore(boolean autoStore)
          True if autoStore is set on.
 void update(java.lang.Object object)
          Update a data object which is queried/loaded/created in another transaction.
 

Field Detail

ReadOnly

public static final short ReadOnly
Read only access. Used with queries and the load(java.lang.Class, java.lang.Object) method to load objects as read-only.

Read-only objects are not persistent and changes to these objects are not reflected in the database when the transaction commits.


Shared

public static final short Shared
Shared access. Used with queries and the load(java.lang.Class, java.lang.Object) method to load objects with shared access.

Shared access allows the same record to be accessed by two concurrent transactions, each with it's own view (object).

These objects acquire a read lock which escalated to a write lock when the transaction commits if the object has been modified. Dirty checking is enabled for all fields marked as such, and a cached copy is used to populate the object.


Exclusive

public static final short Exclusive
Exclusive access. Used with queries and the load(java.lang.Class, java.lang.Object) method to load objects with exclusive access.

Exclusive access prevents two concurrent transactions from accessing the same record. In exclusive mode objects acquire a write lock, and concurrent transactions will block until the lock is released at commit time.

Dirty checking is enabled for all fields marked as such. When an object is first loaded in the transaction, it will be synchronized with the database and not populated from the cache.


DbLocked

public static final short DbLocked
Database lock access. Used with queries and the load(java.lang.Class, java.lang.Object) method to load objects with a database lock.

Database lock prevents two concurrent transactions from accessing the same record either through Castor or direct database access by acquiring a write lock in the select statement. Concurrent transactions will block until the lock is released at commit time.

When an object is first loaded in the transaction, it will be synchronized with the database and not populated from the cache. Dirty checking is not required.

Method Detail

getOQLQuery

public OQLQuery getOQLQuery()
Creates an OQL query with no statement. OQLQuery.create(java.lang.String) must be called before the query can be executed.
Returns:
An OQL query

getOQLQuery

public OQLQuery getOQLQuery(java.lang.String oql)
                     throws QueryException
Creates an OQL query from the supplied statement.
Parameters:
query - An OQL query statement
Returns:
An OQL query
Throws:
QueryException - The query syntax is invalid

getQuery

public Query getQuery()
Creates an empty query. The query must be created before it can be executed.
Returns:
A query

getScope

public PersistenceInfoGroup getScope()

load

public java.lang.Object load(java.lang.Class type,
                             java.lang.Object identity)
                      throws TransactionNotInProgressException,
                             ObjectNotFoundException,
                             LockNotGrantedException,
                             PersistenceException
Load an object of the specified type and given identity. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object. If the identity spans on more than one field, all of the identity fields can be wrapped in a Complex object.
Parameters:
type - The object's type
identity - The object's identity
Throws:
ObjectNotFoundException - No object of the given type and identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while transaction is not in progress
PersistenceException - An error reported by the persistence engine

load

public java.lang.Object load(java.lang.Class type,
                             Complex identity)
                      throws ObjectNotFoundException,
                             LockNotGrantedException,
                             TransactionNotInProgressException,
                             PersistenceException
Load an object of the specified type and given identity which spans on more than one fields.
Parameters:
type - The object's type
identity - The object's identity
Throws:
ObjectNotFoundException - No object of the given type and identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while transaction is not in progress
PersistenceException - An error reported by the persistence engine

load

public java.lang.Object load(java.lang.Class type,
                             java.lang.Object identity,
                             short accessMode)
                      throws TransactionNotInProgressException,
                             ObjectNotFoundException,
                             LockNotGrantedException,
                             PersistenceException
Experimental

Load an object of the specified type and given identity. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object.

Parameters:
type - The object's type
identity - The object's identity
accessMode - The access mode
Throws:
ObjectNotFoundException - No object of the given type and identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while transaction is not in progress
PersistenceException - An error reported by the persistence engine

load

public java.lang.Object load(java.lang.Class type,
                             Complex identity,
                             short accessMode)
                      throws ObjectNotFoundException,
                             LockNotGrantedException,
                             TransactionNotInProgressException,
                             PersistenceException
Experimental

Load an object of the specified type and given identity. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object. If the identity spans on more than one field, all of the identity fields can be wrapped in a Complex object.

Parameters:
type - The object's type
identity - The object's identity
accessMode - The access mode
Throws:
ObjectNotFoundException - No object of the given type and identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while transaction is not in progress
PersistenceException - An error reported by the persistence engine

load

public java.lang.Object load(java.lang.Class type,
                             java.lang.Object identity,
                             java.lang.Object object)
                      throws ObjectNotFoundException,
                             LockNotGrantedException,
                             TransactionNotInProgressException,
                             PersistenceException
Experimental

Load an object of the specified type and given identity into a given instance of object. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object. If the identity spans on more than one field, all of the identity fields can be wrapped in a Complex object.

Parameters:
type - The object's type
identity - The object's identity
object - The object instance to be loaded into
Throws:
ObjectNotFoundException - No object of the given type and identity was found in persistent storage
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
TransactionNotInProgressException - Method called while transaction is not in progress
PersistenceException - An error reported by the persistence engine

create

public void create(java.lang.Object object)
            throws ClassNotPersistenceCapableException,
                   DuplicateIdentityException,
                   TransactionNotInProgressException,
                   PersistenceException
Creates a new object in persistent storage. The object will be persisted only if the transaction commits.

If the object has an identity then duplicate identity check happens in this method, and the object is visible to queries in this transaction. If the identity is null, duplicate identity check occurs when the transaction completes and the object is not visible to queries until the transaction commits.

Parameters:
object - The object to create
Throws:
TransactionNotInProgressException - Method called while transaction is not in progress
DuplicateIdentityException - An object with this identity already exists in persistent storage
ClassNotPersistenceCapableException - The class is not persistent capable
PersistenceException - An error reported by the persistence engine

remove

public void remove(java.lang.Object object)
            throws ObjectNotPersistentException,
                   LockNotGrantedException,
                   TransactionNotInProgressException,
                   PersistenceException
Removes the object from persistent storage. The deletion will take effect only if the transaction is committed, but the object is no longer visible to queries in the current transaction and locks for access from other transactions will block until this transaction completes.
Parameters:
object - The object to remove
Throws:
TransactionNotInProgressException - Method called while transaction is not in progress
ObjectNotPersistentException - The object has not been queried or created in this transaction
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
PersistenceException - An error reported by the persistence engine

update

public void update(java.lang.Object object)
            throws ClassNotPersistenceCapableException,
                   TransactionNotInProgressException,
                   PersistenceException
Update a data object which is queried/loaded/created in another transaction. This method is used only for long transaction support. Calling this method for data object queried/loaded/created in the same transaction results in Exception.

For example, the data object may be sent to a client application and dispayed to a user. After that the objects is being modified in the client application, the object returns back and is update to the database in the second transaction.

See Long Transaction on Castor website.

Parameters:
object - The object to create
Throws:
TransactionNotInProgressException - Method called while transaction is not in progress
ClassNotPersistenceCapableException - The class is not persistent capable
PersistenceException - An error reported by the persistence engine

lock

public void lock(java.lang.Object object)
          throws LockNotGrantedException,
                 ObjectNotPersistentException,
                 TransactionNotInProgressException,
                 PersistenceException
Acquire a soft write lock on the object. Read locks are implicitly available when the object is queried. A write lock is only granted for objects that are created or deleted or for objects loaded in exclusive mode - this method can obtain such a lock explicitly.

A soft lock is acquired in memory, not in the database. To acquire a lock in the database, use the locked access mode.

If the object already has a write lock in this transaction or a read lock in this transaction but no read lock in any other transaction, a write lock is obtained. If this object has a read lock in any other transaction this method will block until the other transaction will release its lock. If the timeout has elapsed or a deadlock has been detected, an exception will be thrown but the current lock will be retained.

Parameters:
object - The object to lock
Throws:
TransactionNotInProgressException - Method called while transaction is not in progress
ObjectNotPersistentException - The object has not been queried or created in this transaction
LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
PersistenceException - An error reported by the persistence engine

begin

public void begin()
           throws PersistenceException
Begin a new transaction. A transaction must be open in order to query and persist objects.
Throws:
PersistenceException - A transaction is already open on this database, or an error reported by the persistence engine

isAutoStore

public boolean isAutoStore()
Return if the current transaction is set to autoStore, it there is transaction active. If there is no active transaction, return if the next transaction will be set to autoStore.

If autoStore is set on. AutoStore will create all reachable object if the object is not loaded from the transaction. If it is turn off, only dependent object will be created automatically.


setAutoStore

public void setAutoStore(boolean autoStore)
True if autoStore is set on.

This method should be called before begin().

If autoStore is set, and db.create( theDataObject ) is called, Castor will create theDataObject, and create each object that does not exist in the transaction and reachable from theDataObject.

If db.update( theDataObject ), and theDataObject is loaded/queuied/created in a previous transaction, Castor will let theDataObject, and all reachable object from theDataObject, participate in the current transaction.

If autoStore is not set, Castor will only create/update/store dependent object, and related objects must be created/update explicitly.


commit

public void commit()
            throws TransactionNotInProgressException,
                   TransactionAbortedException
Commits and closes the transaction. All changes made to persistent objects during the transaction are made persistent; objects created during the transaction are made durable; and, objects removed during the transaction are removed from the database.

In other words, any modifications to any data objects which are queried/loaded/created/update to this database is automatically stored to the database and visible to subsequence transactions. (ie. update is solely used for long transaction support and should not be called for any data object queried/loaded/created in the this transaction.)

If the transaction cannot commit, the entire transaction rolls back and a TransactionAbortedException exception is thrown.

After this method returns, the transaction is closed and all persistent objects are transient. Using begin() to open a new transaction will not restore objects to their persistent stage.

Throws:
TransactionNotInProgressException - Method called while transaction is not in progress
TransactionAbortedException - The transaction cannot commit and has been rolled back

rollback

public void rollback()
              throws TransactionNotInProgressException
Rolls back and closes the transaction. All changes made to persistent objects during the transaction are lost, objects created during the transaction are not made durable and objects removed during the transaction continue to exist.
Throws:
TransactionNotInProgressException - Method called while transaction is not in progress

isActive

public boolean isActive()
Returns true if a transaction is currently active.
Returns:
True if a transaction is active

isClosed

public boolean isClosed()
Returns true if the database is closed.
Returns:
True if the database is closed

close

public void close()
           throws PersistenceException
Closes the database. If a client transaction is in progress the transaction will be rolled back and an exception thrown. If an app-server transaction is in progress, the transaction will commit/rollback when triggered by the application server.
Throws:
PersistenceException - An error occured while attempting to close the database

isPersistent

public boolean isPersistent(java.lang.Object object)
Returns true if the object is persistent. An object is persistent if it was created or queried in this transaction. If the object was created or queried in another transaction, or there is no open transaction, this method returns null.
Parameters:
object - The object
Returns:
True if persistent in this transaction

getIdentity

public java.lang.Object getIdentity(java.lang.Object object)
Returns the object's identity. If the identity was determined when the object was created, or if the object was retrieved, that identity is returned. If the identity has been modified, this will not be reflected until the transaction commits. Null is returned if the identity is null, the object does not have any identity, or the object is not persistent.
Parameters:
object - The object
Returns:
The object's identity, or null

getClassLoader

public java.lang.ClassLoader getClassLoader()
Returns the current ClassLoader if one has been set for this Database instance.
Returns:
ClassLoader the current ClassLoader instance, null if no ClassLoader's instance has been explicitely set.

makePersistent

public void makePersistent(java.lang.Object object)
                    throws ClassNotPersistenceCapableException,
                           DuplicateIdentityException,
                           PersistenceException
Deprecated. See create(java.lang.Object)


deletePersistent

public void deletePersistent(java.lang.Object object)
                      throws ObjectNotPersistentException,
                             LockNotGrantedException,
                             PersistenceException
Deprecated. See remove(java.lang.Object)


checkpoint

public void checkpoint()
                throws TransactionNotInProgressException,
                       TransactionAbortedException
Deprecated. Use commit() and rollback() instead; this method cannot be implemented properly with multiple type of locks and will not be supported in future versions of the API


expireCache

public void expireCache(java.lang.Class[] type,
                        java.lang.Object[] identity)
                 throws PersistenceException
Expire objects from the cache. Objects expired from the cache will be read from persistent storage, as opposed to being read from [either] the performance [or persistent] cache, during subsequent load/query operations.

Objects may be expired from the cache individually, using explicit type/identity pairs in the argument list, or whole classes of objects may be expired by specifying a class type without a corresponding entry in the identity array.

When objects are expired from the cache individually, by identity, objects contained within a "master" object, for example objects maintained in a one-to-many relationship, will automatically be expired from the cache, without the need to explicitly identify them. This does not apply when expiring objects by type. Each type, both container and contained objects need to be specified.

Parameters:
type - An array of class types.
identity - An array of object identifiers.


Intalio Inc. (C) 1999-2002. All rights reserved http://www.intalio.com

Reply via email to