org.sadun.util.pool.connection
Class ConfigurableDataSource

java.lang.Object
  extended byorg.sadun.util.pool.connection.ConfigurableDataSource
All Implemented Interfaces:
javax.sql.DataSource, java.io.Serializable

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

A non-pooled data source (use ConnectionPool to pool it if needed) which can be externally configured via standard XML serialization.

An example of XML encoding follows:

 <?xml version="1.0" encoding="UTF-8"?>
 <java version="1.4.1_03" class="java.beans.XMLDecoder">
  <object class="org.sadun.util.pool.connection.ConfigurableDataSource">
   <void property="connectionProperties">
    <void method="put">
     <string>fooProperty</string>
     <string>fooValue</string>
    </void>
   </void>
   <void property="jdbcUrl">
    <string>jdbc:microsoft:sqlserver://localhost:1433;User=sa;Password=;DatabaseName=ipm</string>
   </void>
  </object>
 </java>
 

Author:
Cristiano Sadun
See Also:
Serialized Form

Constructor Summary
ConfigurableDataSource()
          Create an unitialized ConfigurableDataSource.
ConfigurableDataSource(java.io.File xmlPath)
          Create an datasource from an XMLEncoded file.
ConfigurableDataSource(java.io.InputStream xml)
          Create an datasource from an XMLEncoded stream.
ConfigurableDataSource(java.lang.String jdbcUrl)
          Create an datasource using the given JDBC url.
ConfigurableDataSource(java.lang.String jdbcUrl, java.util.Properties connectionProperties)
          Create an datasource using the given JDBC url and connection properties.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Return true if the given object is a ConfigurableDataSource with identical JDBC url and connection properties, else false.
 java.sql.Connection getConnection()
          See DataSource.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          See DataSource.
 java.util.Properties getConnectionProperties()
          Return the connection properties for this data source.
 java.lang.String getJdbcUrl()
          Return the JDBC url for this data source.
 int getLoginTimeout()
          See DataSource.
 java.io.PrintWriter getLogWriter()
          See DataSource.
 int hashCode()
          Return an hash code for the object.
static void main(java.lang.String[] args)
           
 void setConnectionProperties(java.util.Properties connectionProperties)
          Set the connection properties for this data source.
 void setJdbcUrl(java.lang.String jdbcUrl)
          Set the JDBC url for this data source.
 void setLoginTimeout(int seconds)
          See DataSource.
 void setLogWriter(java.io.PrintWriter out)
          See DataSource.
 java.lang.String toString()
          Return a description of the data source.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigurableDataSource

public ConfigurableDataSource()
Create an unitialized ConfigurableDataSource. setJdbcUrl() must be invoked before invoking getConnection().


ConfigurableDataSource

public ConfigurableDataSource(java.lang.String jdbcUrl)
Create an datasource using the given JDBC url.

Parameters:
jdbcUrl - the JDBC url to use.

ConfigurableDataSource

public ConfigurableDataSource(java.lang.String jdbcUrl,
                              java.util.Properties connectionProperties)
Create an datasource using the given JDBC url and connection properties.

Parameters:
jdbcUrl - the JDBC url to use.
connectionProperties - the connection properties to use.

ConfigurableDataSource

public ConfigurableDataSource(java.io.InputStream xml)
Create an datasource from an XMLEncoded stream.

Parameters:
xml - the XMLEncoded stream to create the datasource from.

ConfigurableDataSource

public ConfigurableDataSource(java.io.File xmlPath)
                       throws java.io.FileNotFoundException
Create an datasource from an XMLEncoded file.

Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
See DataSource.

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.getConnection()

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
See DataSource.

Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.getConnection(java.lang.String, java.lang.String)

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
See DataSource.

Specified by:
getLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.getLogWriter()

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
See DataSource.

Specified by:
setLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.setLogWriter(java.io.PrintWriter)

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
See DataSource.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.setLoginTimeout(int)

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
See DataSource.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Throws:
java.sql.SQLException
See Also:
DataSource.getLoginTimeout()

getConnectionProperties

public java.util.Properties getConnectionProperties()
Return the connection properties for this data source.

Returns:
the connection properties for this data source.

getJdbcUrl

public java.lang.String getJdbcUrl()
Return the JDBC url for this data source.

Returns:
the JDBC url for this data source.

setConnectionProperties

public void setConnectionProperties(java.util.Properties connectionProperties)
Set the connection properties for this data source.

Parameters:
connectionProperties -

setJdbcUrl

public void setJdbcUrl(java.lang.String jdbcUrl)
Set the JDBC url for this data source.

Parameters:
jdbcUrl -

toString

public java.lang.String toString()
Return a description of the data source.


equals

public boolean equals(java.lang.Object obj)
Return true if the given object is a ConfigurableDataSource with identical JDBC url and connection properties, else false.

Returns:
true if the given object is a ConfigurableDataSource with identical JDBC url and connection properties, else false.

hashCode

public int hashCode()
Return an hash code for the object.

Returns:
an hash code for the object.

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception