Added a lazy initialization to cover connections that are closed by the container
This commit is contained in:
parent
562f1927e1
commit
3e1a874653
1 changed files with 12 additions and 0 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue