mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-8656: messages on SQL exception in DbUtils!
This commit is contained in:
parent
87ae150159
commit
1f460f4174
|
|
@ -158,12 +158,14 @@ public class ConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String
|
||||||
@Override
|
@Override
|
||||||
public boolean update(String name, String category, String value) {
|
public boolean update(String name, String category, String value) {
|
||||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||||
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
|
try {
|
||||||
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);) {
|
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
|
||||||
stmt.setString(1, value);
|
try (PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);) {
|
||||||
stmt.setString(2, name);
|
stmt.setString(1, value);
|
||||||
stmt.executeUpdate();
|
stmt.setString(2, name);
|
||||||
return true;
|
stmt.executeUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
s_logger.warn("Unable to update Configuration Value", e);
|
s_logger.warn("Unable to update Configuration Value", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,7 @@ public class DbUtil {
|
||||||
try {
|
try {
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
try {
|
closeAutoCloseable(connection, "error closing connection for global locks");
|
||||||
connection.close();
|
|
||||||
} catch (SQLException sqlException) {
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
s_connectionForGlobalLocks.put(name, connection);
|
s_connectionForGlobalLocks.put(name, connection);
|
||||||
|
|
@ -203,37 +200,28 @@ public class DbUtil {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(GET_LOCK(?, ?),0)");) {
|
||||||
ResultSet rs = null;
|
|
||||||
try {
|
|
||||||
pstmt = conn.prepareStatement("SELECT COALESCE(GET_LOCK(?, ?),0)");
|
|
||||||
|
|
||||||
pstmt.setString(1, name);
|
pstmt.setString(1, name);
|
||||||
pstmt.setInt(2, timeoutSeconds);
|
pstmt.setInt(2, timeoutSeconds);
|
||||||
|
|
||||||
rs = pstmt.executeQuery();
|
try (ResultSet rs = pstmt.executeQuery();) {
|
||||||
if (rs != null && rs.first()) {
|
if (rs != null && rs.first()) {
|
||||||
if (rs.getInt(1) > 0) {
|
if (rs.getInt(1) > 0) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (s_logger.isDebugEnabled())
|
if (s_logger.isDebugEnabled())
|
||||||
s_logger.debug("GET_LOCK() timed out on lock : " + name);
|
s_logger.debug("GET_LOCK() timed out on lock : " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
s_logger.error("GET_LOCK() throws exception ", e);
|
s_logger.error("GET_LOCK() throws exception ", e);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
s_logger.error("GET_LOCK() throws exception ", e);
|
s_logger.error("GET_LOCK() throws exception ", e);
|
||||||
} finally {
|
|
||||||
closeStatement(pstmt);
|
|
||||||
closeResultSet(rs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeConnectionForGlobalLocks(name);
|
removeConnectionForGlobalLocks(name);
|
||||||
try {
|
closeAutoCloseable(conn, "connection for global lock");
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -285,45 +273,27 @@ public class DbUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeResultSet(final ResultSet resultSet) {
|
public static void closeResultSet(final ResultSet resultSet) {
|
||||||
|
closeAutoCloseable(resultSet, "exception while closing result set.");
|
||||||
try {
|
|
||||||
|
|
||||||
if (resultSet != null) {
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
s_logger.warn("Ignored exception while closing result set.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeStatement(final Statement statement) {
|
public static void closeStatement(final Statement statement) {
|
||||||
|
closeAutoCloseable(statement, "exception while closing statement.");
|
||||||
try {
|
|
||||||
|
|
||||||
if (statement != null) {
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
s_logger.warn("Ignored exception while closing statement.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void closeConnection(final Connection connection) {
|
public static void closeConnection(final Connection connection) {
|
||||||
|
closeAutoCloseable(connection, "exception while close connection.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void closeAutoCloseable(AutoCloseable ac, String message) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (connection != null) {
|
if (ac != null) {
|
||||||
connection.close();
|
ac.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
s_logger.warn("Ignored exception while close connection.", e);
|
s_logger.warn("[ignored] " + message, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue