Commit 64e834f2 authored by Ing. František DVOŘÁK's avatar Ing. František DVOŘÁK
Browse files

Reconnect locally

parent ed1c58f6
......@@ -106,14 +106,21 @@ public class ScriptedSQLConnection {
/**
* If internal connection is not usable, throw IllegalStateException
*/
public void test() {
synchronized public void test() {
try {
if (null == getSqlConnection())
throw new ConnectionBrokenException("JDBC connection is broken (connect failed)");
if (sqlConn.isClosed())
throw new ConnectionBrokenException("JDBC connection is broken (closed)");
if (!sqlConn.isValid(_configuration.getValidConnectionTimeout()))
throw new ConnectionBrokenException("JDBC connection is broken (not valid)");
// dirty hack - try to reconnect here
for (int attempt = 1; attempt <= 5; attempt++) {
if (null == getSqlConnection())
throw new ConnectionBrokenException("JDBC connection is broken - connect failed");
if (sqlConn.isClosed())
throw new ConnectionBrokenException("JDBC connection is broken - closed");
if (sqlConn.isValid(_configuration.getValidConnectionTimeout()))
return;
LOG.error("JDBC connection is broken - closed, attempt {0}", attempt);
SQLUtil.closeQuietly(sqlConn);
sqlConn = null;
}
throw new ConnectionBrokenException("JDBC connection is broken - not vali)");
} catch (SQLException e) {
throw ConnectionBrokenException.wrap(e);
}
......@@ -124,7 +131,7 @@ public class ScriptedSQLConnection {
*
* @return the connection
*/
public Connection getSqlConnection() {
synchronized public Connection getSqlConnection() {
if (sqlConn == null) {
sqlConn = connect(_configuration);
}
......@@ -136,7 +143,7 @@ public class ScriptedSQLConnection {
*
* @param connection
*/
public void setSqlConnection(Connection connection) {
synchronized public void setSqlConnection(Connection connection) {
this.sqlConn = connection;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment