Search in sources :

Example 1 with Pair

use of com.voxelgameslib.voxelgameslib.util.Pair in project VoxelGamesLibv2 by VoxelGamesLib.

the class HibernatePersistenceProvider method getTopWithName.

@Override
public List<Pair<Component, Double>> getTopWithName(Trackable type, int amount) {
    return session(session -> {
        Query query = session.createQuery("select user.displayName, stat.val from StatInstance stat, UserData user\n" + "where user.uuid = stat.uuid\n" + "and stat.statType = :type\n" + "order by stat.val desc");
        query.setParameter("type", type);
        query.setMaxResults(amount);
        List<Pair<Component, Double>> result = new ArrayList<>();
        // noinspection unchecked
        for (Object[] row : (List<Object[]>) query.getResultList()) {
            result.add(new Pair<>((Component) row[0], (Double) row[1]));
        }
        return result;
    });
}
Also used : Query(org.hibernate.query.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Component(net.kyori.text.Component) Pair(com.voxelgameslib.voxelgameslib.util.Pair)

Example 2 with Pair

use of com.voxelgameslib.voxelgameslib.util.Pair in project VoxelGamesLibv2 by VoxelGamesLib.

the class HibernatePersistenceProvider method getTopWithUUID.

@Override
public List<Pair<UUID, Double>> getTopWithUUID(Trackable type, int amount) {
    return session(session -> {
        Query query = session.createQuery("select stat.uuid, stat.val from StatInstance stat\n" + "where stat.statType = :type\n" + "order by stat.val desc");
        query.setParameter("type", type);
        query.setMaxResults(amount);
        List<Pair<UUID, Double>> result = new ArrayList<>();
        // noinspection unchecked
        for (Object[] row : (List<Object[]>) query.getResultList()) {
            result.add(new Pair<>((UUID) row[0], (Double) row[1]));
        }
        return result;
    });
}
Also used : Query(org.hibernate.query.Query) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Pair(com.voxelgameslib.voxelgameslib.util.Pair)

Aggregations

Pair (com.voxelgameslib.voxelgameslib.util.Pair)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Query (org.hibernate.query.Query)2 UUID (java.util.UUID)1 Component (net.kyori.text.Component)1