Added a lazy initialization to cover connections that are closed by the container

This commit is contained in:
travismccauley 2003-12-23 21:02:41 +00:00
parent 3e1a874653
commit 0df6a89cc3

View file

@ -81,9 +81,12 @@ public class LexRepository
* Gets the connection attribute of the LexRepository object * Gets the connection attribute of the LexRepository object
* *
* @return The connection value * @return The connection value
* @exception LexRepositoryException Description of the Exception
* @since * @since
*/ */
private Connection getConnection() private Connection getConnection() throws LexRepositoryException
{
try
{ {
if ( null == connection || connection.isClosed() ) if ( null == connection || connection.isClosed() )
{ {
@ -91,17 +94,26 @@ public class LexRepository
DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME ); DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME );
setConnection( source.getConnection() ); setConnection( source.getConnection() );
} }
}
catch ( Exception se )
{
throw new LexRepositoryException( se );
}
return connection; return connection;
} }
/** /**
* Gets the queryStatement attribute of the LexRepository object * Gets the queryStatement attribute of the LexRepository object
* *
* @return The queryStatement value * @return The queryStatement value
* @exception LexRepositoryException Description of the Exception
* @since * @since
*/ */
public Statement getQueryStatement() public Statement getQueryStatement() throws LexRepositoryException
{
try
{ {
if ( getConnection().isClosed() ) if ( getConnection().isClosed() )
{ {
@ -109,6 +121,11 @@ public class LexRepository
DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME ); DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME );
setConnection( source.getConnection() ); setConnection( source.getConnection() );
} }
}
catch ( Exception se )
{
throw new LexRepositoryException( se );
}
return queryStatement; return queryStatement;
} }