mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Fix connection leaking on batch inserts; fix IDEA analyser warning
This commit is contained in:
parent
a8fea0fc49
commit
4c93bf7cf0
@ -43,6 +43,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
@ -103,7 +104,7 @@ public class SQLBacking extends AbstractBacking {
|
||||
return provider.runQuery(query, queryRS);
|
||||
}
|
||||
|
||||
public boolean tableExists(String table) throws SQLException {
|
||||
private boolean tableExists(String table) throws SQLException {
|
||||
return provider.getConnection().getMetaData().getTables(null, null, table.toUpperCase(), null).next();
|
||||
}
|
||||
|
||||
@ -292,7 +293,8 @@ public class SQLBacking extends AbstractBacking {
|
||||
}
|
||||
|
||||
List<NodeDataHolder> data = user.getNodes().stream().map(NodeDataHolder::fromNode).collect(Collectors.toList());
|
||||
try (PreparedStatement ps = provider.getConnection().prepareStatement(prefix.apply(USER_PERMISSIONS_INSERT))) {
|
||||
try (Connection connection = provider.getConnection()) {
|
||||
try (PreparedStatement ps = connection.prepareStatement(prefix.apply(USER_PERMISSIONS_INSERT))) {
|
||||
for (NodeDataHolder nd : data) {
|
||||
ps.setString(1, user.getUuid().toString());
|
||||
ps.setString(2, nd.getPermission());
|
||||
@ -304,6 +306,7 @@ public class SQLBacking extends AbstractBacking {
|
||||
ps.addBatch();
|
||||
}
|
||||
ps.executeBatch();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user