BEA Systems, Inc.

com.beasys.commerce.axiom.document
Class DataSourceHelper

java.lang.Object
  |
  +--com.beasys.commerce.axiom.document.DataSourceHelper

public class DataSourceHelper
extends java.lang.Object

A class to help getting a connection to a document jdbc connections.

The primary method is getConnection() taking either an EntityImpl or a SessionImpl. This has the following logic:

  1. If the environment property "UseDataSource" is "true", the the environment property "jdbc/docPool" will be used as a DataSource.
  2. Otherwise, this will use the environment property "DocPoolDriver" as the JDBC driver and "DocPoolURL" as the JDBC url of the connection to the docPool.

Since:
3.1.0

Field Summary
static java.util.Properties jdbcProperties
          The properties to give to the driver manager when getting a conection via a JDBC driver.
 
Constructor Summary
DataSourceHelper()
           
 
Method Summary
static java.sql.Connection getConnection(EntityImpl impl)
          Get a connection for the bean based upon it's environment settings.
static java.sql.Connection getConnection(SessionImpl impl)
          Get a connection for the bean based upon it's environment settings.
static java.lang.String getConnectionDriverClass(EntityImpl impl)
          Get the JDBC driver to the docPool for the specified entity.
static java.lang.String getConnectionDriverClass(SessionImpl impl)
          Get the JDBC driver to the docPool for the specified session bean.
static java.lang.String getConnectionURL(EntityImpl impl)
          Get the JDBC connection url to the docPool for the specified entity.
static java.lang.String getConnectionURL(SessionImpl impl)
          Get the JDBC connection url to the docPool for the specified session bean.
static java.sql.Driver getDriver(java.lang.String driverCl)
          Get a JDBC driver for the specified driver class name.
static java.sql.Driver getDriver(java.lang.String url, java.lang.String driverCl)
          Gets the driver for the specified url and driver class.
static java.lang.String getDriverClass(java.lang.String url)
          Try to determine the driver class for the specified url.
static boolean useDataSource(EntityImpl impl)
          Determine if the specified Entity should use a DataSource or a direct JDBC URL.
static boolean useDataSource(SessionImpl impl)
          Determine if the specified Session bean should use a DataSource or a direct JDBC URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jdbcProperties

public static final java.util.Properties jdbcProperties
The properties to give to the driver manager when getting a conection via a JDBC driver.
Constructor Detail

DataSourceHelper

public DataSourceHelper()
Method Detail

getDriver

public static java.sql.Driver getDriver(java.lang.String url,
                                        java.lang.String driverCl)
                                 throws java.sql.SQLException
Gets the driver for the specified url and driver class.

This does not use DriverManager at all.

Parameters:
url - the jdbc url.
driverCl - the preferred driver class name (will use getDriverClass if null).
Returns:
an instance of the driver or null on no driver for url.
Throws:
java.sql.SQLException - thrown on an error loading the driver.

getDriverClass

public static java.lang.String getDriverClass(java.lang.String url)
Try to determine the driver class for the specified url.

This does a best guess based upon some common JDBC drivers and their URL formats. It is generally better to specify the JDBC driver class name instead.

Parameters:
url - the JDBC url.
Returns:
the driver to try or null on unknown url.

getDriver

public static java.sql.Driver getDriver(java.lang.String driverCl)
                                 throws java.sql.SQLException
Get a JDBC driver for the specified driver class name.

This is simply wrapper around Class.forName() that throws SQLExceptions on error.

Parameters:
driverCl - the driver class name.
Returns:
a driver instance.
Throws:
java.sql.SQLException - thrown on an error loading a driver.

useDataSource

public static boolean useDataSource(EntityImpl impl)
Determine if the specified Entity should use a DataSource or a direct JDBC URL.

This checks the "UseDataSource" environment property of the entity. If this is missing or "true", then the "/jdbc/docPool" DataSource should be used. Otherwise, the "DocPoolURL" should be used.


getConnectionURL

public static java.lang.String getConnectionURL(EntityImpl impl)
Get the JDBC connection url to the docPool for the specified entity.

This will check the "DocPoolURL" environment property of the entity.

Returns:
the url, null on not found or error.

getConnectionDriverClass

public static java.lang.String getConnectionDriverClass(EntityImpl impl)
Get the JDBC driver to the docPool for the specified entity.

This will check the "DocPoolDriver" environment property of the entity.

Returns:
the url, null on not found or error.

getConnection

public static java.sql.Connection getConnection(EntityImpl impl)
                                         throws java.sql.SQLException
Get a connection for the bean based upon it's environment settings.

See the class notes for details.

This will cache the driver instance for the bean's DocPoolURL as needed.

Returns:
the connection, or null on configuration failure.
Throws:
java.sql.SQLException - thrown on an error getting a connection.
See Also:
useDataSource(com.beasys.commerce.foundation.EntityImpl), getConnectionURL(com.beasys.commerce.foundation.EntityImpl), getConnectionDriverClass(com.beasys.commerce.foundation.EntityImpl), getDriver(java.lang.String, java.lang.String)

useDataSource

public static boolean useDataSource(SessionImpl impl)
Determine if the specified Session bean should use a DataSource or a direct JDBC URL.

This checks the "UseDataSource" environment property of the entity. If this is missing or "true", then the "/jdbc/docPool" DataSource should be used. Otherwise, the "DocPoolURL" should be used.


getConnectionURL

public static java.lang.String getConnectionURL(SessionImpl impl)
Get the JDBC connection url to the docPool for the specified session bean.

This will check the "DocPoolURL" environment property of the entity.

Returns:
the url, null on not found or error.

getConnectionDriverClass

public static java.lang.String getConnectionDriverClass(SessionImpl impl)
Get the JDBC driver to the docPool for the specified session bean.

This will check the "DocPoolDriver" environment property of the entity.

Returns:
the url, null on not found or error.

getConnection

public static java.sql.Connection getConnection(SessionImpl impl)
                                         throws java.sql.SQLException
Get a connection for the bean based upon it's environment settings.

See the class notes for details.

This will cache the driver instance for the bean's DocPoolURL as needed.

Returns:
the connection, or null on configuration failure.
Throws:
java.sql.SQLException - thrown on an error getting a connection.
See Also:
useDataSource(com.beasys.commerce.foundation.SessionImpl), getConnectionURL(com.beasys.commerce.foundation.SessionImpl), getConnectionDriverClass(com.beasys.commerce.foundation.SessionImpl), getDriver(java.lang.String, java.lang.String)

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved