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

This commit is contained in:
travismccauley 2003-12-23 20:40:07 +00:00
parent 562f1927e1
commit 3e1a874653

View file

@ -85,6 +85,12 @@ public class LexRepository
*/ */
private Connection getConnection() private Connection getConnection()
{ {
if ( null == connection || connection.isClosed() )
{
Context context = new InitialContext();
DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME );
setConnection( source.getConnection() );
}
return connection; return connection;
} }
@ -97,6 +103,12 @@ public class LexRepository
*/ */
public Statement getQueryStatement() public Statement getQueryStatement()
{ {
if ( getConnection().isClosed() )
{
Context context = new InitialContext();
DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME );
setConnection( source.getConnection() );
}
return queryStatement; return queryStatement;
} }