Add UUID caching

This commit is contained in:
Alexander Söderberg
2020-05-20 15:12:09 +02:00
parent f82a111518
commit 2417dace2d
3 changed files with 80 additions and 18 deletions

View File

@ -37,6 +37,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.function.Consumer;
@ -121,4 +122,24 @@ public class SQLiteUUIDService implements UUIDService, Consumer<List<UUIDMapping
}
}
/**
* Read the entire cache at once
*
* @return All read mappings
*/
@NotNull public List<UUIDMapping> getAll() {
final List<UUIDMapping> mappings = new LinkedList<>();
try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
try (final ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")), resultSet.getString("username")));
}
}
} catch (final Exception e) {
e.printStackTrace();
}
return mappings;
}
}