mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-20 15:11:29 +01:00
Added more try-with-resource to auto-close prepared statement
This commit is contained in:
parent
fdc7a62990
commit
2e89a2654f
@ -440,11 +440,12 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Collection
|
// Collection
|
||||||
// The table is cleared for this uniqueId every time the data is stored
|
// The table is cleared for this uniqueId every time the data is stored
|
||||||
String clearTableSql = "DELETE FROM `" + dataObject.getCanonicalName() + "." + field.getName() + "` WHERE uniqueId = ?";
|
String clearTableSql = "DELETE FROM `" + dataObject.getCanonicalName() + "." + field.getName() + "` WHERE uniqueId = ?";
|
||||||
PreparedStatement collStatement = connection.prepareStatement(clearTableSql);
|
try (PreparedStatement collStatement = connection.prepareStatement(clearTableSql)) {
|
||||||
collStatement.setString(1, uniqueId);
|
collStatement.setString(1, uniqueId);
|
||||||
collStatement.execute();
|
collStatement.execute();
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString());
|
plugin.getLogger().info("DEBUG: collStatement " + collStatement.toString());
|
||||||
|
}
|
||||||
// Insert into the table
|
// Insert into the table
|
||||||
String setSql = "INSERT INTO `" + dataObject.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
String setSql = "INSERT INTO `" + dataObject.getCanonicalName() + "." + field.getName() + "` (uniqueId, ";
|
||||||
// Get the columns we are going to insert, just the names of them
|
// Get the columns we are going to insert, just the names of them
|
||||||
@ -452,7 +453,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Get all the ?'s for the columns
|
// Get all the ?'s for the columns
|
||||||
setSql += "VALUES ('" + uniqueId + "'," + getCollectionColumnString(propertyDescriptor.getWriteMethod(), true, false) + ")";
|
setSql += "VALUES ('" + uniqueId + "'," + getCollectionColumnString(propertyDescriptor.getWriteMethod(), true, false) + ")";
|
||||||
// Prepare the statement
|
// Prepare the statement
|
||||||
collStatement = connection.prepareStatement(setSql);
|
try (PreparedStatement collStatement = connection.prepareStatement(setSql)) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
plugin.getLogger().info("DEBUG: collection insert =" + setSql);
|
||||||
// Do single dimension types (set and list)
|
// Do single dimension types (set and list)
|
||||||
@ -506,6 +507,7 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
|||||||
// Set value for the main insert. For collections, this is just a dummy value because the real values are in the
|
// Set value for the main insert. For collections, this is just a dummy value because the real values are in the
|
||||||
// additional table.
|
// additional table.
|
||||||
value = true;
|
value = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the value is not a collection, it just needs to be serialized to go into the database.
|
// If the value is not a collection, it just needs to be serialized to go into the database.
|
||||||
value = serialize(value, propertyDescriptor.getPropertyType());
|
value = serialize(value, propertyDescriptor.getPropertyType());
|
||||||
|
Loading…
Reference in New Issue
Block a user