diff --git a/bukkit/src/main/java/com/github/dig/endervaults/bukkit/storage/HikariMySQLStorage.java b/bukkit/src/main/java/com/github/dig/endervaults/bukkit/storage/HikariMySQLStorage.java index 02c4098..395aa04 100644 --- a/bukkit/src/main/java/com/github/dig/endervaults/bukkit/storage/HikariMySQLStorage.java +++ b/bukkit/src/main/java/com/github/dig/endervaults/bukkit/storage/HikariMySQLStorage.java @@ -139,7 +139,7 @@ private void createTableIfNotExist(String table, String TABLE_SQL) { } private Vault create(UUID id, UUID ownerUUID, int size, String contents) { - Map metadata = getVaultMetadata(ownerUUID, id); + Map metadata = getMetadata(ownerUUID, id); String title = plugin.getLanguage().get(Lang.VAULT_TITLE, metadata); BukkitVault vault = new BukkitVault(id, title, size, ownerUUID, metadata); @@ -148,31 +148,6 @@ private Vault create(UUID id, UUID ownerUUID, int size, String contents) { return vault; } - private Map getVaultMetadata(UUID ownerUUID, UUID id) { - VaultMetadataRegistry metadataRegistry = plugin.getMetadataRegistry(); - - Map metadata = new HashMap<>(); - String sql = String.format(DatabaseConstants.SQL_SELECT_VAULT_METADATA_BY_ID_AND_OWNER, metadataTable); - try (Connection conn = hikariDataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { - stmt.setString(1, id.toString()); - stmt.setString(2, ownerUUID.toString()); - - ResultSet rs = stmt.executeQuery(); - if (rs.next()) { - String key = rs.getString("name"); - Optional converterOptional = metadataRegistry.get(key); - if (converterOptional.isPresent()) { - MetadataConverter converter = converterOptional.get(); - metadata.put(key, converter.to(rs.getString("value"))); - } - } - } catch (SQLException ex) { - log.log(Level.SEVERE, "[EnderVaults] Error while executing query.", ex); - } - - return metadata; - } - private void insert(UUID id, UUID ownerUUID, int size, String contents) { String sql = String.format(DatabaseConstants.SQL_INSERT_VAULT, vaultTable); try (Connection conn = hikariDataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { @@ -266,6 +241,31 @@ private List get(UUID ownerUUID) { return vaults; } + private Map getMetadata(UUID ownerUUID, UUID id) { + VaultMetadataRegistry metadataRegistry = plugin.getMetadataRegistry(); + + Map metadata = new HashMap<>(); + String sql = String.format(DatabaseConstants.SQL_SELECT_VAULT_METADATA_BY_ID_AND_OWNER, metadataTable); + try (Connection conn = hikariDataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, id.toString()); + stmt.setString(2, ownerUUID.toString()); + + ResultSet rs = stmt.executeQuery(); + while (rs.next()) { + String key = rs.getString("name"); + Optional converterOptional = metadataRegistry.get(key); + if (converterOptional.isPresent()) { + MetadataConverter converter = converterOptional.get(); + metadata.put(key, converter.to(rs.getString("value"))); + } + } + } catch (SQLException ex) { + log.log(Level.SEVERE, "[EnderVaults] Error while executing query.", ex); + } + + return metadata; + } + private boolean exists(UUID id, UUID ownerUUID, String key) { String sql = String.format(DatabaseConstants.SQL_SELECT_VAULT_METADATA_BY_ID_AND_OWNER_AND_KEY, metadataTable); boolean has;