Clean up SQLDatabaseManager

This commit is contained in:
t00thpick1 2015-07-18 10:48:40 -04:00
parent 30adac5e63
commit 9934ab972e

View File

@ -133,22 +133,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
massUpdateLock.unlock(); massUpdateLock.unlock();
} }
@ -178,22 +164,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
massUpdateLock.unlock(); massUpdateLock.unlock();
} }
@ -223,22 +195,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
if (success) { if (success) {
@ -362,22 +320,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return success; return success;
@ -412,30 +356,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return stats; return stats;
@ -527,30 +450,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return skills; return skills;
@ -567,14 +469,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (connection != null) { tryClose(connection);
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -610,22 +505,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return -1; return -1;
} }
@ -722,30 +603,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
// Problem, nothing was returned // Problem, nothing was returned
@ -801,30 +661,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(e); printErrors(e);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -848,22 +687,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
return false; return false;
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -902,22 +727,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
return false; return false;
} }
finally { finally {
if (statement != null) { tryClose(statement);
try { tryClose(connection);
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -940,30 +751,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(e); printErrors(e);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return users; return users;
@ -1105,38 +895,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(createStatement);
} tryClose(connection);
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (createStatement != null) {
try {
createStatement.close();
}
catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1228,14 +990,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1269,14 +1024,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (statement != null) { tryClose(statement);
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1388,14 +1136,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "ADD INDEX `user` (`user`(20) ASC)"); + "ADD INDEX `user` (`user`(20) ASC)");
} catch (SQLException ex) { } catch (SQLException ex) {
} finally { } finally {
if (resultSet != null) { tryClose(resultSet);
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1477,14 +1218,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1514,14 +1248,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
new GetUUIDUpdatesRequired().runTaskLaterAsynchronously(mcMMO.p, 100); // wait until after first purge new GetUUIDUpdatesRequired().runTaskLaterAsynchronously(mcMMO.p, 100); // wait until after first purge
@ -1546,27 +1273,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
} catch (SQLException ex) { } catch (SQLException ex) {
printErrors(ex); printErrors(ex);
} finally { } finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close(); tryClose(connection);
} catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
// Ignore
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
// Ignore
}
}
} }
if (!names.isEmpty()) { if (!names.isEmpty()) {
@ -1603,14 +1312,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
@ -1639,19 +1341,12 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try {
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
} }
private int getUserID(final Connection connection, final String playerName, final UUID uuid) { private int getUserID(final Connection connection, final String playerName, final UUID uuid) {
if (cachedUserIDs.containsKey(uuid)) { if (uuid != null && cachedUserIDs.containsKey(uuid)) {
return cachedUserIDs.get(uuid); return cachedUserIDs.get(uuid);
} }
@ -1667,7 +1362,9 @@ public final class SQLDatabaseManager implements DatabaseManager {
if (resultSet.next()) { if (resultSet.next()) {
int id = resultSet.getInt("id"); int id = resultSet.getInt("id");
cachedUserIDs.put(uuid, id); if (uuid != null) {
cachedUserIDs.put(uuid, id);
}
return id; return id;
} }
@ -1676,26 +1373,23 @@ public final class SQLDatabaseManager implements DatabaseManager {
printErrors(ex); printErrors(ex);
} }
finally { finally {
if (resultSet != null) { tryClose(resultSet);
try { tryClose(statement);
resultSet.close();
}
catch (SQLException e) {
// Ignore
}
}
if (statement != null) {
try {
statement.close();
}
catch (SQLException e) {
// Ignore
}
}
} }
return -1; return -1;
} }
private void tryClose(AutoCloseable closeable) {
if (closeable != null) {
try {
closeable.close();
}
catch (Exception e) {
// Ignore
}
}
}
@Override @Override
public void onDisable() { public void onDisable() {