The Java Data Objects API
The class JDOManager
provides the Castor JDO engine used for
obtaining a database connection. A JDO object is constructed with the name of a database
and other properties, and getDatabase is used to obtain a new database connection.
The class Database
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.
The class OQLQuery
is obtained from the database and used to
construct and execute a query on that database. All query operations are bound to the database
transaction.
The following example opens a connection to the database 'mydb' configured from the configuration file 'database.xml', retrieves all the products in the specified groups and marks them down with a 25% discount and on-sale status.
JDOManager jdo; Database db; Query oql; QueryResults results; // Define a new database source JDOManager.loadConfiguration ("jdo-conf.xml"); JDOManager jdo = JDOManager.createInstance ( "mydb" ); // Open a new database, begin a transaction db = jdo.getDatabase(); db.begin(); // Select all the products in a given group oql = db.getQuery( "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();
A CacheManager
instance can be obtained by issuing the
following code:
Database db = jdo.getDatabase();
CacheManager manager = ((DatabaseImpl) db.getCacheManager();
This instance can subsequently be used to selectively clear the Castor performance
cache. Use one of the CacheManager.expireCache()
methods.
Interface | Description |
---|---|
Database |
An open connection to the database.
|
DataObjects |
A factory for
Database connections. |
OQLQuery |
An OQL query object.
|
Persistent |
A callback informs objects about changes to their state.
|
Query |
A query object.
|
QueryResults |
An iteration of the results of a query.
|
TimeStampable |
A call-back get/set the time stamp.
|
Class | Description |
---|---|
CacheManager |
CacheManager handles expiring objects from the cache.
|
DbMetaInfo |
Database meta information encapsulation
This is currently used to get the database version out of a
JDBC database connection and enable comparing against some
required version string.
|
JDOManager |
Implementation of the JDOManager engine used for obtaining database
connections.
|
Exception | Description |
---|---|
ClassNotPersistenceCapableException |
Exception thrown to indicate objects of this class are not persistent
capable.
|
ConnectionFailedException |
An attempt to open a JDBC connection failed.
|
DatabaseNotFoundException |
This exception is thrown when attempting to open a database that
does not exist.
|
DataObjectAccessException |
An exception encapsulating another exception which occurs during
operation to data object.
|
DuplicateIdentityException |
Exception indicating that a duplicate identity has been found and
an object with the same identity already exists in persistent
storage.
|
FatalPersistenceException |
A fatal exception indicates the persistence engine is no longer usable.
|
LockNotGrantedException |
Exception thrown when failed to acquire a lock on an object, a timeout
occured waiting to acquire the lock, or a deadlock has been detected.
|
ObjectDeletedException |
This exception is thrown when accessing an object that was deleted.
|
ObjectModifiedException |
Indicates transaction has been aborted as a result of object
being modified by a concurrent transaction.
|
ObjectNotFoundException |
An attempt to load an object failed, an object of that type with
that primary key was not found in persistent storage.
|
ObjectNotPersistentException |
Exception indicating object is not persistent.
|
PersistenceException |
An exception representing another exception (an SQL exception, a JNDI
naming exception, etc) raised by the underlying persistence engine.
|
QueryException |
Reports an exception with the query, either syntax, query parameters
or inability to perform the query against the persistence engine.
|
TransactionAbortedException |
Informs that the user transaction has been explicitly aborted by
the database due to some failure and the reason for that failure.
|
TransactionNotInProgressException |
Indicates the operation cannot be performed since a transaction is not
in progress.
|
Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com