DBZ-7258 Use business methods
This commit is contained in:
parent
b63e5ce048
commit
54e6c855a2
@ -52,16 +52,8 @@ public RetriableConnection(String url, String user, String pwd, Duration waitRet
|
||||
createConnection();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOGGER.error("Unable to create connection. It will be re-attempted during its first use: " + e.getMessage(), e);
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// ignore
|
||||
}
|
||||
conn = null;
|
||||
}
|
||||
LOGGER.error("Unable to create connection. It will be re-attempted during its first use: {}", e.getMessage(), e);
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,8 +64,16 @@ private void createConnection() throws SQLException {
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
if (isConnectionCreated()) {
|
||||
try {
|
||||
conn.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.warn("Exception while closing connection", e);
|
||||
}
|
||||
}
|
||||
conn = null;
|
||||
}
|
||||
|
||||
public boolean isConnectionCreated() {
|
||||
return conn != null;
|
||||
@ -107,14 +107,14 @@ private synchronized <T> T executeWithRetry(ConnectionFunction<T> func, Connecti
|
||||
throws SQLException {
|
||||
int attempt = 1;
|
||||
while (true) {
|
||||
if (conn == null) {
|
||||
if (!isConnectionCreated()) {
|
||||
LOGGER.debug("Trying to reconnect (attempt {}).", attempt);
|
||||
try {
|
||||
createConnection();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
LOGGER.error("SQL Exception while trying to reconnect: " + e.getMessage(), e);
|
||||
conn = null;
|
||||
LOGGER.error("SQL Exception while trying to reconnect: {}", e.getMessage(), e);
|
||||
close();
|
||||
if (attempt >= maxRetryCount) {
|
||||
throw e;
|
||||
}
|
||||
@ -145,14 +145,7 @@ private synchronized <T> T executeWithRetry(ConnectionFunction<T> func, Connecti
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
try {
|
||||
conn.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// ignore
|
||||
}
|
||||
conn = null;
|
||||
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user