Fixed test failures, 3 bugs:

- RawDataContainer using getUnsafe in getValue which threw error where
  no error should be thrown
- BaseUserQueries#fetchServerBaseUsers had ambiguous registered column
- WorldTimesQueries#fetchPlayerWorldTimesOnServers had ambiguous
  server_uuid column
This commit is contained in:
Rsl1122 2019-02-11 18:05:44 +02:00
parent 4d951cea20
commit 70417f5359
5 changed files with 19 additions and 5 deletions

View File

@ -81,4 +81,17 @@ public class Key<T> {
public int hashCode() {
return Objects.hash(type, keyName);
}
/**
* Cast an object to the type of the key.
*
* @param object Object to cast.
* @return The object with the type of T.
*/
public T typeCast(Object object) {
// Since Type can have a List<Subtype>, Class can not be obtained in order to use Class while casting.
// This could be done since Google Gson does it, but I don't know how they do it since
// the implementation is hidden.
return (T) object;
}
}

View File

@ -68,7 +68,7 @@ public class RawDataContainer implements DataContainer {
@Override
public <T> Optional<T> getValue(Key<T> key) {
try {
return Optional.ofNullable(getUnsafe(key));
return Optional.ofNullable(key.typeCast(map.get(key)));
} catch (ClassCastException e) {
return Optional.empty();
}
@ -80,7 +80,7 @@ public class RawDataContainer implements DataContainer {
if (value == null) {
throw new IllegalArgumentException("Unsupported Key: " + key.getKeyName());
}
return (T) value;
return key.typeCast(value);
}
@Override

View File

@ -104,7 +104,7 @@ public class SupplierDataContainer implements DataContainer {
if (supplier == null) {
throw new IllegalArgumentException("Unsupported Key: " + key.getKeyName());
}
return (T) supplier.get();
return key.typeCast(supplier.get());
}
private void putAll(Map<Key, Supplier> toPut) {

View File

@ -71,7 +71,7 @@ public class BaseUserQueries {
String sql = "SELECT " +
UsersTable.TABLE_NAME + "." + UsersTable.USER_UUID + ", " +
UsersTable.USER_NAME + ", " +
UsersTable.REGISTERED + ", " +
UsersTable.TABLE_NAME + "." + UsersTable.REGISTERED + ", " +
UsersTable.TIMES_KICKED +
" FROM " + UsersTable.TABLE_NAME +
" INNER JOIN " + UserInfoTable.TABLE_NAME + " on " +

View File

@ -151,11 +151,12 @@ public class WorldTimesQueries {
"SUM(" + WorldTimesTable.CREATIVE + ") as creative, " +
"SUM(" + WorldTimesTable.ADVENTURE + ") as adventure, " +
"SUM(" + WorldTimesTable.SPECTATOR + ") as spectator, " +
WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID + ", " +
worldNameColumn +
" FROM " + WorldTimesTable.TABLE_NAME +
" INNER JOIN " + WorldTable.TABLE_NAME + " on " + worldIDColumn + "=" + WorldTimesTable.WORLD_ID +
" WHERE " + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.USER_UUID + "=?" +
" GROUP BY world, " + WorldTimesTable.SERVER_UUID;
" GROUP BY world, " + WorldTimesTable.TABLE_NAME + "." + WorldTimesTable.SERVER_UUID;
return new QueryStatement<Map<UUID, WorldTimes>>(sql, 1000) {
@Override