Jwma

dtw.webmail.util
Class CastorDatabase

java.lang.Object
  |
  +--dtw.webmail.util.CastorDatabase
Direct Known Subclasses:
JwmaDatabase

public abstract class CastorDatabase
extends java.lang.Object

Abstract class that encapsulates a Database from the Castor lib, to enhance performance by adding the reuse of queries (which is perfectly possible).

Version:
0.9.7 07/02/2003
Author:
Dieter Wimberger

Field Summary
protected  org.exolab.castor.jdo.Database m_Database
           
protected  java.util.HashMap m_Queries
           
 
Constructor Summary
CastorDatabase()
          Simple and empty constructor, to create a lightweight instance that serves only as factory object for "real" instances.
 
Method Summary
 void begin()
          Delegates beginning a new transaction to the encapsulated Database.
 void close()
          Closes the database.
 void commit()
          Delegates the commit method to the encapsulated Database instance.
 void create(java.lang.Object object)
          Delegates creation of a new object in persistent storage to the encapsulated Database.
abstract  CastorDatabase createCastorDatabase()
           
 org.exolab.castor.jdo.Database getDatabase()
          Returns the encapsulated Database instance.
 java.lang.Object getIdentity(java.lang.Object object)
          Delegates checking an object's identity to the encapsulated Database.
 org.exolab.castor.jdo.OQLQuery getOQLQuery()
          Delegates creation of an OQL query with no statement.
 org.exolab.castor.jdo.OQLQuery getOQLQuery(java.lang.String oql)
          Delegates creation of an OQL query from the supplied statement.
 org.exolab.castor.jdo.OQLQuery getQuery(java.lang.String identifier)
           
 boolean isActive()
          Tests if a transaction is currently active.
 boolean isAutoStore()
          Delegates testing of the current transaction autoStore flag state to the encapsulated Database.
 boolean isClosed()
          Tests if a database has been closed.
 boolean isPersistent(java.lang.Object object)
          Delegates testing of a given object's persistency state.
 java.lang.Object load(java.lang.Class type, java.lang.Object identity)
          Delegates loading of an object of the specified type and given identity to the encapsulated Database.
 void putQuery(java.lang.String identifier, org.exolab.castor.jdo.OQLQuery query)
           
 void remove(java.lang.Object object)
          Delegates removal of the object from persistent storage.
 void rollback()
          Delegates the rollback method to the encapsulated Database instance.
 void setAutoStore(boolean autoStore)
          Delegates setting of the autoStore flag state to the encapsulated Database.
 void update(java.lang.Object object)
          Delegates updating a data object which is queried/loaded/created in another transaction to the encapsulated Database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Database

protected org.exolab.castor.jdo.Database m_Database

m_Queries

protected java.util.HashMap m_Queries
Constructor Detail

CastorDatabase

public CastorDatabase()
Simple and empty constructor, to create a lightweight instance that serves only as factory object for "real" instances.

Method Detail

getOQLQuery

public org.exolab.castor.jdo.OQLQuery getOQLQuery()
Delegates creation of an OQL query with no statement. OQLQuery.create(java.lang.String) must be called before the query can be executed.

Returns:
a new nonprepared OQL query.

getOQLQuery

public org.exolab.castor.jdo.OQLQuery getOQLQuery(java.lang.String oql)
                                           throws org.exolab.castor.jdo.QueryException
Delegates creation of an OQL query from the supplied statement.

Returns:
An OQL query
Throws:
org.exolab.castor.jdo.QueryException - The query syntax is invalid

load

public java.lang.Object load(java.lang.Class type,
                             java.lang.Object identity)
                      throws org.exolab.castor.jdo.TransactionNotInProgressException,
                             org.exolab.castor.jdo.ObjectNotFoundException,
                             org.exolab.castor.jdo.LockNotGrantedException,
                             org.exolab.castor.jdo.PersistenceException
Delegates loading of an object of the specified type and given identity to the encapsulated Database.

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

create

public void create(java.lang.Object object)
            throws org.exolab.castor.jdo.ClassNotPersistenceCapableException,
                   org.exolab.castor.jdo.DuplicateIdentityException,
                   org.exolab.castor.jdo.TransactionNotInProgressException,
                   org.exolab.castor.jdo.PersistenceException
Delegates creation of a new object in persistent storage to the encapsulated Database. The object will only be persisted if the transaction commits.

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

remove

public void remove(java.lang.Object object)
            throws org.exolab.castor.jdo.ObjectNotPersistentException,
                   org.exolab.castor.jdo.LockNotGrantedException,
                   org.exolab.castor.jdo.TransactionNotInProgressException,
                   org.exolab.castor.jdo.PersistenceException
Delegates removal of 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:
org.exolab.castor.jdo.TransactionNotInProgressException - Method called while transaction is not in progress.
org.exolab.castor.jdo.ObjectNotPersistentException - The object has not been queried or created in this transaction.
org.exolab.castor.jdo.LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object.
org.exolab.castor.jdo.PersistenceException - An error reported by the persistence engine.

update

public void update(java.lang.Object object)
            throws org.exolab.castor.jdo.ClassNotPersistenceCapableException,
                   org.exolab.castor.jdo.TransactionNotInProgressException,
                   org.exolab.castor.jdo.PersistenceException
Delegates updating a data object which is queried/loaded/created in another transaction to the encapsulated Database. 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.

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

isAutoStore

public boolean isAutoStore()
Delegates testing of the current transaction autoStore flag state to the encapsulated Database.

Returns:
true if autostoring is on, false otherwise.

setAutoStore

public void setAutoStore(boolean autoStore)
Delegates setting of the autoStore flag state to the encapsulated Database.

Parameters:
autoStore - true if on, false otherwise.

begin

public void begin()
           throws org.exolab.castor.jdo.PersistenceException
Delegates beginning a new transaction to the encapsulated Database. A transaction must be open in order to query and persist objects.

Throws:
org.exolab.castor.jdo.PersistenceException - A transaction is already open on this database, or an error reported by the persistence engine

rollback

public void rollback()
              throws org.exolab.castor.jdo.TransactionNotInProgressException
Delegates the rollback method to the encapsulated Database instance.

org.exolab.castor.jdo.TransactionNotInProgressException

commit

public void commit()
            throws org.exolab.castor.jdo.TransactionNotInProgressException,
                   org.exolab.castor.jdo.TransactionAbortedException
Delegates the commit method to the encapsulated Database instance.

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

isActive

public boolean isActive()
Tests if a transaction is currently active.

Returns:
true if a transaction is active, false otherwise.

isClosed

public boolean isClosed()
Tests if a database has been closed.

Returns:
true if the database has been closed, false otherwise.

close

public void close()
           throws org.exolab.castor.jdo.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:
org.exolab.castor.jdo.PersistenceException - An error occured while attempting to close the database

isPersistent

public boolean isPersistent(java.lang.Object object)
Delegates testing of a given object's persistency state. 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 to be tested.
Returns:
True if persistent in this transaction

getIdentity

public java.lang.Object getIdentity(java.lang.Object object)
Delegates checking an object's identity to the encapsulated Database.

Parameters:
object - the object to be checked.
Returns:
the object's identity, or null if nonexistant.

getDatabase

public org.exolab.castor.jdo.Database getDatabase()
Returns the encapsulated Database instance.

Returns:
the encapsulated database instance.

getQuery

public org.exolab.castor.jdo.OQLQuery getQuery(java.lang.String identifier)

putQuery

public void putQuery(java.lang.String identifier,
                     org.exolab.castor.jdo.OQLQuery query)

createCastorDatabase

public abstract CastorDatabase createCastorDatabase()
                                             throws JwmaException
JwmaException

Jwma

Copyright © 2000-2003 jwma team (All Rights Reserved.)