org.mmbase.storage.database
Class DatabaseTransaction

java.lang.Object
  extended byorg.mmbase.storage.database.DatabaseTransaction
All Implemented Interfaces:
Transaction

Deprecated. This code is scheduled for removal once MMBase has been fully converted to the new StorageManager implementation.

public class DatabaseTransaction
extends java.lang.Object
implements Transaction

Database transaction object. Used to maintain context (connection) between separate database statements, allowing for rollback in complex database transactions (if supported). This class is a base class for making connections and submitting changes to the database.

Since:
MMBase-1.6
Version:
$Id: DatabaseTransaction.java,v 1.9.2.1 2004/06/15 21:38:36 robmaris Exp $
Author:
Pierre van Rooden

Constructor Summary
DatabaseTransaction(DatabaseStorage database, boolean useRollback)
          Deprecated. Instantiate a database transaction.
 
Method Summary
 boolean commit()
          Deprecated. Closes and commits the transaction.
 boolean databaseSupportsRollback()
          Deprecated. Queries the database metadata to test whether this database supports rollback.
 java.sql.ResultSet executeQuery(java.lang.String sql)
          Deprecated. Execute a SQL statement on the database, and return the Resultset.
 boolean executeUpdate(java.lang.String sql)
          Deprecated. Execute a SQL statement on the database.
 boolean executeUpdate(java.lang.String sql, java.util.List fields, MMObjectNode node)
          Deprecated. Execute a SQL statement on the database.
 int getIntegerResult()
          Deprecated. Attempts to return a single integer result from the last retrieved resultset.
 MMObjectNode getNodeResult(MMObjectBuilder builder)
          Deprecated. Attempts to return a single Node from the last retrieved resultset.
 java.util.Set getTables(java.lang.String baseName)
          Deprecated. Queries the database metadata to obtain a list of tables following a specified pattern.
 boolean hasTable(java.lang.String tableName)
          Deprecated. Queries the database metadata to test whether a given table exists.
 void registerChanged(MMObjectNode node, java.lang.String change)
          Deprecated. Register changes for broadcasting after commit
 boolean rollback()
          Deprecated. Rolls back (cancels) the transaction.
 boolean supportsRollback()
          Deprecated. Returns true if this transaction supports rollback.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseTransaction

public DatabaseTransaction(DatabaseStorage database,
                           boolean useRollback)
                    throws StorageException
Deprecated. 
Instantiate a database transaction. Attempts to obtain a connection with the database. You can explicitly turn off rollback facilities (which might slow down database access) for internal routines by specifying useRollbacka s false.

Parameters:
database - the database for which to make the transaction
useRollback - if true, the transaction should use rollback facilities if the database supports them
Throws:
StorageException - when a connection could not be made
Method Detail

databaseSupportsRollback

public boolean databaseSupportsRollback()
                                 throws StorageException
Deprecated. 
Queries the database metadata to test whether this database supports rollback. Rollback of a transaction is defined as making undone any changes to the persistent storage used (i.e. a database), since the transaction started.

Returns:
true if the database supports rollback
Throws:
StorageException - when the metadata could not be retrieved

supportsRollback

public boolean supportsRollback()
Deprecated. 
Returns true if this transaction supports rollback. Rollback of a transaction is defined as making undone any changes to the persistent storage used (i.e. a database), since the transaction started.

Specified by:
supportsRollback in interface Transaction
Returns:
true if the transaction supports rollback

hasTable

public boolean hasTable(java.lang.String tableName)
                 throws StorageException
Deprecated. 
Queries the database metadata to test whether a given table exists.

Parameters:
tableName - nam of the table to look for
Returns:
true if the table exists
Throws:
StorageException - when the metadata could not be retrieved

getTables

public java.util.Set getTables(java.lang.String baseName)
                        throws StorageException
Deprecated. 
Queries the database metadata to obtain a list of tables following a specified pattern.

Parameters:
baseName - the prefix (base name) of the names of the tables to look for
Returns:
a Set of tablenames
Throws:
StorageException - when the metadata could not be retrieved

commit

public boolean commit()
Deprecated. 
Closes and commits the transaction. This method catches any exceptions that occur. If closing or committing fails, the function returns false, rather than throwing an exception (though the error is logged).

Specified by:
commit in interface Transaction
Returns:
true if committed and closed successfully

registerChanged

public void registerChanged(MMObjectNode node,
                            java.lang.String change)
Deprecated. 
Register changes for broadcasting after commit

Parameters:
node - the node to register
change - the type of change: "n": new, "c": commit, "d": delete

rollback

public boolean rollback()
Deprecated. 
Rolls back (cancels) the transaction. If cancelling fails, the function returns false, rather than throwing an exception (though the error is logged).

Specified by:
rollback in interface Transaction
Returns:
true if cancelled successfully

executeQuery

public java.sql.ResultSet executeQuery(java.lang.String sql)
                                throws StorageException
Deprecated. 
Execute a SQL statement on the database, and return the Resultset.

Parameters:
sql - the sql query to execute
Returns:
the ResultSet
Throws:
StorageException - when the query failed

executeUpdate

public boolean executeUpdate(java.lang.String sql)
                      throws StorageException
Deprecated. 
Execute a SQL statement on the database. The statement should be an 'update' sql query (one that does not return a resultset).

Parameters:
sql - the sql query to execute.
Returns:
true if the execution was succesfull
Throws:
StorageException - when the statement failed

executeUpdate

public boolean executeUpdate(java.lang.String sql,
                             java.util.List fields,
                             MMObjectNode node)
                      throws StorageException
Deprecated. 
Execute a SQL statement on the database. The statement should be an 'update' sql query (one that does not return a resultset).

Parameters:
sql - the sql query to execute.
fields - the list of FieldDefs whose values should be added as the query parameters.
node - the node that contains the field data
Returns:
true if the execution was succesfull
Throws:
StorageException - when the statement failed

getIntegerResult

public int getIntegerResult()
Deprecated. 
Attempts to return a single integer result from the last retrieved resultset. Use this method to return the result of a query which returns a resultset of records containing one single numeric field If the query failed, or returned an unexpected result, or if the resultset is exhausted, the function returns -1. If this is due to an error then the error is logged.

Returns:
the integer result

getNodeResult

public MMObjectNode getNodeResult(MMObjectBuilder builder)
Deprecated. 
Attempts to return a single Node from the last retrieved resultset. Use this method to return the result of a query which returns a resultset of records containing fields from a builder table If the query failed, or returned an unexpected result, or if the resultset is exhausted, the function returns null. If this is due to an error then the error is logged.

Parameters:
builder - the builder to use for creating the node
Returns:
the node


MMBase build 1.7.1.20041002