org.mmbase.storage.implementation.database
Class GenericDataSource

java.lang.Object
  extended byorg.mmbase.storage.implementation.database.GenericDataSource
All Implemented Interfaces:
javax.sql.DataSource

public final class GenericDataSource
extends java.lang.Object
implements javax.sql.DataSource

This class functions as a Datasource wrapper around the JDBC Module. It is intended for use when MMBase runs outside an applicationserver, or when the server does not (or poorly) support pooled datasources. I can also be used by older systems that use the JDBC Module and do not want to change their configuration. Note that the JDBC Module will likely be fased out as a module at some point in the future, with code and supporting classes to be moved to this class instead.

Since:
MMBase-1.7
Version:
$Id: GenericDataSource.java,v 1.4 2004/01/21 09:06:02 michiel Exp $
Author:
Pierre van Rooden

Constructor Summary
GenericDataSource(MMBase mmbase)
          Constructs a datasource for accessing the database belonging to the given MMBase module.
 
Method Summary
 java.sql.Connection getConnection()
          Attempt to establish a database connection.
 java.sql.Connection getConnection(java.lang.String userName, java.lang.String password)
          Attempt to establish a database connection.
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this data source.
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Set the log writer for this data source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDataSource

public GenericDataSource(MMBase mmbase)
                  throws StorageInaccessibleException
Constructs a datasource for accessing the database belonging to the given MMBase module. The MMBase parameter is not currently used, but is included for future expansion

Parameters:
mmbase - the MMBase instance
Throws:
StorageInaccessibleException - if the JDBC module used in creating the datasource is inaccessible
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
a Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String userName,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
userName - - the database user on whose behalf the Connection is being made
password - - the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

getLoginTimeout

public int getLoginTimeout()
Gets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a DataSource object is created the login timeout is initially zero.
Note: the default system timeout is 30 seconds (unless otherwise specified in the JDBC configuration file)

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
the data source login time limit
Throws:
java.sql.SQLException - - if a database-access error occurs.

getLogWriter

public java.io.PrintWriter getLogWriter()
Get the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.DriverManager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
the log writer for this data source, null if disabled
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLoginTimeout

public void setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a DataSource object is created the login timeout is initially zero.
Note: currently this code does not actually change the timeout.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - - the data source login time limit
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
Set the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out - - the new log writer; to disable, set to null
Throws:
java.sql.SQLException - - if a database-access error occurs.


MMBase build 1.7.1.20041002