Package org.apache.xalan.lib.sql
Class JNDIConnectionPool
- java.lang.Object
-
- org.apache.xalan.lib.sql.JNDIConnectionPool
-
- All Implemented Interfaces:
ConnectionPool
public class JNDIConnectionPool extends java.lang.Object implements ConnectionPool
A Connection Pool that wraps a JDBC datasource to provide connections. An instance of this class is created byXConnectionwhen it attempts to resolves aConnectionPoolname as a JNDI data source. Most methods in this implementation do nothing since configuration is handled by the underlying JDBC datasource. Users should always callXConnection.close()from their stylsheet to explicitely close their connection. However, since there is no way to enforce this (Yikes!), it is recommended that a relatively short datasource timeout be used to prevent dangling connections.
-
-
Constructor Summary
Constructors Constructor Description JNDIConnectionPool()Use of the default constructor requires the jndi path to be set via setJndiPath().JNDIConnectionPool(java.lang.String jndiDatasourcePath)Creates a connection pool with a specified JNDI path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfreeUnused()Intended to release unused connections from the pool.java.sql.ConnectiongetConnection()Returns a connection from the JDNI DataSource found at the JNDI Datasource path.java.lang.StringgetJndiPath()Returns the path for the jndi datasourcebooleanhasActiveConnections()Always returns false, indicating that this wrapper has no idea of what connections the underlying JNDI source is maintaining.booleanisEnabled()Always returns true.voidreleaseConnection(java.sql.Connection con)Return a connection to the pool, the connection may be closed if the pool is inactive or has exceeded the max number of free connectionsvoidreleaseConnectionOnError(java.sql.Connection con)Provide a mechinism to return a connection to the pool on Error.voidsetDriver(java.lang.String d)Not implemented and will throw an Error if called.voidsetJndiPath(java.lang.String jndiPath)Sets the path for the jndi datasourcevoidsetMinConnections(int n)Ignored in this implementation b/c the pooling is determined by the jndi dataosource.voidsetPassword(java.lang.String p)Sets the password for the connection.voidsetPoolEnabled(boolean flag)Releases the reference to the jndi datasource.voidsetProtocol(java.util.Properties p)Ignored in this implementation b/c the pooling is determined by the jndi dataosource.voidsetURL(java.lang.String url)Not implemented and will throw an Error if called.voidsetUser(java.lang.String u)Sets the user name for the connection.booleantestConnection()A simple test to see if the jndi datasource exists.
-
-
-
Constructor Detail
-
JNDIConnectionPool
public JNDIConnectionPool()
Use of the default constructor requires the jndi path to be set via setJndiPath().
-
JNDIConnectionPool
public JNDIConnectionPool(java.lang.String jndiDatasourcePath)
Creates a connection pool with a specified JNDI path.- Parameters:
jndiDatasourcePath- Complete path to the JNDI datasource
-
-
Method Detail
-
setJndiPath
public void setJndiPath(java.lang.String jndiPath)
Sets the path for the jndi datasource- Parameters:
jndiPath-
-
getJndiPath
public java.lang.String getJndiPath()
Returns the path for the jndi datasource- Parameters:
jndiPath-
-
isEnabled
public boolean isEnabled()
Always returns true. This method was intended to indicate if the pool was enabled, however, in this implementation that is not relavant.- Specified by:
isEnabledin interfaceConnectionPool- Returns:
-
setDriver
public void setDriver(java.lang.String d)
Not implemented and will throw an Error if called. Connection configuration is handled by the underlying JNDI DataSource.- Specified by:
setDriverin interfaceConnectionPool- Parameters:
d-
-
setURL
public void setURL(java.lang.String url)
Not implemented and will throw an Error if called. Connection configuration is handled by the underlying JNDI DataSource.- Specified by:
setURLin interfaceConnectionPool- Parameters:
d-
-
freeUnused
public void freeUnused()
Intended to release unused connections from the pool. Does nothing in this implementation.- Specified by:
freeUnusedin interfaceConnectionPool
-
hasActiveConnections
public boolean hasActiveConnections()
Always returns false, indicating that this wrapper has no idea of what connections the underlying JNDI source is maintaining.- Specified by:
hasActiveConnectionsin interfaceConnectionPool- Returns:
-
setPassword
public void setPassword(java.lang.String p)
Sets the password for the connection. If the jndi datasource does not require a password (which is typical), this can be left null.- Specified by:
setPasswordin interfaceConnectionPool- Parameters:
p- the password
-
setUser
public void setUser(java.lang.String u)
Sets the user name for the connection. If the jndi datasource does not require a user name (which is typical), this can be left null.- Specified by:
setUserin interfaceConnectionPool- Parameters:
u- the user name
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLExceptionReturns a connection from the JDNI DataSource found at the JNDI Datasource path.- Specified by:
getConnectionin interfaceConnectionPool- Returns:
- Throws:
java.sql.SQLException
-
releaseConnection
public void releaseConnection(java.sql.Connection con) throws java.sql.SQLExceptionDescription copied from interface:ConnectionPoolReturn a connection to the pool, the connection may be closed if the pool is inactive or has exceeded the max number of free connections- Specified by:
releaseConnectionin interfaceConnectionPool- Throws:
java.sql.SQLException
-
releaseConnectionOnError
public void releaseConnectionOnError(java.sql.Connection con) throws java.sql.SQLExceptionDescription copied from interface:ConnectionPoolProvide a mechinism to return a connection to the pool on Error. A good default behaviour is to close this connection and build a new one to replace it. Some JDBC impl's won't allow you to reuse a connection after an error occurs.- Specified by:
releaseConnectionOnErrorin interfaceConnectionPool- Throws:
java.sql.SQLException
-
setPoolEnabled
public void setPoolEnabled(boolean flag)
Releases the reference to the jndi datasource. The original intention of this method was to actually turn the pool *off*. Since we are not managing the pool, we simply release our reference to the datasource. Future calls to the getConnection will simply recreate the datasource.- Specified by:
setPoolEnabledin interfaceConnectionPool- Parameters:
flag- If false, the reference to the datasource is released.
-
setProtocol
public void setProtocol(java.util.Properties p)
Ignored in this implementation b/c the pooling is determined by the jndi dataosource.- Specified by:
setProtocolin interfaceConnectionPool- Parameters:
p-
-
setMinConnections
public void setMinConnections(int n)
Ignored in this implementation b/c the pooling is determined by the jndi dataosource.- Specified by:
setMinConnectionsin interfaceConnectionPool- Parameters:
n-
-
testConnection
public boolean testConnection()
A simple test to see if the jndi datasource exists. Note that this test does not ensure that the datasource will return valid connections.- Specified by:
testConnectionin interfaceConnectionPool
-
-