org.objectweb.cjdbc.driver
Class DataSource

java.lang.Object
  extended byorg.objectweb.cjdbc.driver.DataSource
All Implemented Interfaces:
javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable

public class DataSource
extends java.lang.Object
implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable

An implementation of the JDBC 2.0 optional package DataSource interface. It allows to set the URL, user name, and password to its properties. It can be bound via JNDI so that the properties can be set by an "application server" and a "ready-to-use" reference to DataSource can be retrieved via JNDI.

Version:
1.0
Author:
Marek Prochazka
See Also:
Serialized Form

Field Summary
protected static java.lang.String DESCRIPTION_PROPERTY
           
protected static Driver driver
          Wrapped driver for to get connections.
protected static java.lang.String DRIVER_CLASSNAME
           
protected static java.lang.String FACTORY_CLASSNAME
           
protected  java.io.PrintWriter logWriter
           
protected  java.lang.String password
           
protected static java.lang.String PASSWORD_PROPERTY
           
protected  java.lang.String url
          DataSource properties
protected static java.lang.String URL_PROPERTY
          DataSource properties
protected  java.lang.String user
           
protected static java.lang.String USER_PROPERTY
           
 
Constructor Summary
DataSource()
          Default constructor.
 
Method Summary
 java.sql.Connection getConnection()
          Gets connection.
protected  java.sql.Connection getConnection(java.util.Properties props)
          Creates a connection using the specified properties.
 java.sql.Connection getConnection(java.lang.String user, java.lang.String password)
          Gets connection.
 java.lang.String getDescription()
          Return the description of this Datasource with the Driver version number.
 int getLoginTimeout()
          Gets the login timeout.
 java.io.PrintWriter getLogWriter()
          Gets the log writer.
 javax.naming.Reference getReference()
          Gets a reference to this.
 java.lang.String getUrl()
          Gets url of the C-JDBC controller(s) to connect.
 java.lang.String getURL()
          Gets URL of the C-JDBC controller(s) to connect.
 java.lang.String getUser()
          Gets user name to be used to connect the C-JDBC controller(s).
 void setLoginTimeout(int seconds)
          Sets the timeout.
 void setLogWriter(java.io.PrintWriter output)
          Sets the log writer for this data source.
 void setPassword(java.lang.String pwd)
          Sets password to be used to connect the C-JDBC controller(s).
 void setUrl(java.lang.String url)
          Sets url of the C-JDBC controller(s) to connect.
 void setURL(java.lang.String url)
          Sets URL of the C-JDBC controller(s) to connect.
 void setUser(java.lang.String userName)
          Sets user name to be used to connect the C-JDBC controller(s).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

URL_PROPERTY

protected static final java.lang.String URL_PROPERTY
DataSource properties

See Also:
Constant Field Values

USER_PROPERTY

protected static final java.lang.String USER_PROPERTY
See Also:
Constant Field Values

PASSWORD_PROPERTY

protected static final java.lang.String PASSWORD_PROPERTY
See Also:
Constant Field Values

DRIVER_CLASSNAME

protected static final java.lang.String DRIVER_CLASSNAME
See Also:
Constant Field Values

FACTORY_CLASSNAME

protected static final java.lang.String FACTORY_CLASSNAME
See Also:
Constant Field Values

DESCRIPTION_PROPERTY

protected static final java.lang.String DESCRIPTION_PROPERTY
See Also:
Constant Field Values

driver

protected static Driver driver
Wrapped driver for to get connections.


url

protected java.lang.String url
DataSource properties


user

protected java.lang.String user

password

protected java.lang.String password

logWriter

protected java.io.PrintWriter logWriter
Constructor Detail

DataSource

public DataSource()
Default constructor.

Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Gets connection. Retrieves a new connection using the user name and password that have been already set.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
a new connection.
Throws:
java.sql.SQLException - if an error occurs.

getConnection

public java.sql.Connection getConnection(java.lang.String user,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Gets connection. Retrieves a new connection using the user name and password specified.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
user - user name.
password - password.
Returns:
a new connection.
Throws:
java.sql.SQLException - if an error occurs.

setLogWriter

public void setLogWriter(java.io.PrintWriter output)
                  throws java.sql.SQLException
Sets the log writer for this data source.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
output - print writer.
Throws:
java.sql.SQLException - in case of an error occurs.

getLogWriter

public java.io.PrintWriter getLogWriter()
Gets the log writer.

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
log writer.

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Sets the timeout. Actually does nothing.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - timeout in seconds.
Throws:
java.sql.SQLException - in case of an error occurs.

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Gets the login timeout.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
login timeout
Throws:
java.sql.SQLException - in case of an error occurs.

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Gets a reference to this. The factory used for this class is the DataSourceFactoryclass.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
a reference to this.
Throws:
javax.naming.NamingException - if DataSourceFactory not found.

getDescription

public java.lang.String getDescription()
Return the description of this Datasource with the Driver version number.

Returns:
Datasource description

setUrl

public void setUrl(java.lang.String url)
Sets url of the C-JDBC controller(s) to connect. The method is used by the "application server" to set the URL (potentially according a deployment descriptor). The url is stored in the URL_PROPERTYproperty.

Parameters:
url - URL to be used to connect C-JDBC controller(s)

setURL

public void setURL(java.lang.String url)
Sets URL of the C-JDBC controller(s) to connect. The method is used by the "application server" to set the URL (potentially according a deployment descriptor). The URL is stored in the "url" property.

Parameters:
url - URL to be used to connect C-JDBC controller(s).

getUrl

public java.lang.String getUrl()
Gets url of the C-JDBC controller(s) to connect. The URL is stored in the URL_PROPERTYproperty.

Returns:
URL to be used to connect C-JDBC controller(s).

getURL

public java.lang.String getURL()
Gets URL of the C-JDBC controller(s) to connect. The URL is stored in the URL_PROPERTYproperty.

Returns:
URL to be used to connect C-JDBC controller(s).

setUser

public void setUser(java.lang.String userName)
Sets user name to be used to connect the C-JDBC controller(s). The method can be used by the "application server" to set the user name (potentially according a deployment descriptor). The user name is stored in the USER_PROPERTYproperty.

Parameters:
userName - user name to be used to connect C-JDBC controller(s).

getUser

public java.lang.String getUser()
Gets user name to be used to connect the C-JDBC controller(s). The user name is stored in the USER_PROPERTYproperty.

Returns:
user name to be used to connect C-JDBC controller(s).

setPassword

public void setPassword(java.lang.String pwd)
Sets password to be used to connect the C-JDBC controller(s). The method can be used by the "application server" to set the password (potentially according a deployment descriptor). The password is stored in the PASSWORD_PROPERTYproperty. Note that there is not a getPassword method.

Parameters:
pwd - password to be used to connect C-JDBC controller(s).

getConnection

protected java.sql.Connection getConnection(java.util.Properties props)
                                     throws java.sql.SQLException
Creates a connection using the specified properties.

Parameters:
props - connection properties.
Returns:
a new connection.
Throws:
java.sql.SQLException - if an error occurs.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.