org.objectledge.database
Interface Database

All Known Implementing Classes:
DefaultDatabase

public interface Database

A convenience wrapper around database related components.

Use this component to reduce the number of required constructor parameters in your database dependant components, and make sure that they'll access the right data source, if you are using the ThreadDataSource decorator.

Version:
$Id: Database.java,v 1.7 2005/04/04 11:38:08 rafal Exp $
Author:
Rafal Krzewski

Method Summary
 boolean beginTransaction()
          Begin the transaction, if there is none active.
 void commitTransaction(boolean controller)
          Commit the transaction, if the caller is the controller.
 Connection getConnection()
          Returns a database Connection produced by the DataSource.
 Connection getConnection(String user, String password)
          Returns a database Connection produced by the DataSource.
 long getNextId(String table)
          Get the next row identifier for the table.
 void rollbackTransaction(boolean controller)
          Rollback the transaction, if the caller is the controller.
 void setTransactionTimeout(int seconds)
          Sets the transaction timeout for the current transaction.
 

Method Detail

getConnection

Connection getConnection()
                         throws SQLException
Returns a database Connection produced by the DataSource.

Returns:
a database Connection.
Throws:
SQLException - if the conneciton could not be obtained.

getConnection

Connection getConnection(String user,
                         String password)
                         throws SQLException
Returns a database Connection produced by the DataSource.

Parameters:
user - the user to connect as.
password - the user's password.
Returns:
a database Connection.
Throws:
SQLException - if the conneciton could not be obtained.

getNextId

long getNextId(String table)
               throws SQLException
Get the next row identifier for the table.

Parameters:
table - the table name.
Returns:
the identifier.
Throws:
SQLException - if the id could not be generated.

setTransactionTimeout

void setTransactionTimeout(int seconds)
                           throws SQLException
Sets the transaction timeout for the current transaction.

Parameters:
seconds - the requested length of timeout period in seconds.
Throws:
SQLException - if the timeout could not be set.

beginTransaction

boolean beginTransaction()
                         throws SQLException
Begin the transaction, if there is none active.

Returns:
true if the requestor become the controler.
Throws:
SQLException - if the operation fails.

commitTransaction

void commitTransaction(boolean controller)
                       throws SQLException
Commit the transaction, if the caller is the controller.

Parameters:
controller - true if the caller is the controler.
Throws:
SQLException - if the commit fails.

rollbackTransaction

void rollbackTransaction(boolean controller)
                         throws SQLException
Rollback the transaction, if the caller is the controller.

Parameters:
controller - true if the caller is the controler.
Throws:
SQLException - if the rollback fails.


Copyright © 2003-2006 objectledge.org. All Rights Reserved.