Search in sources :

Example 1 with HIGH_SCORES

use of com.skelril.skree.db.schema.tables.HighScores.HIGH_SCORES in project Skree by Skelril.

the class HighScoreDatabaseUtil method getTop.

public static List<Clause<Optional<GameProfile>, Integer>> getTop(ScoreType scoreType, int count) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        Result<Record2<String, Integer>> results = create.select(PLAYERS.UUID, HIGH_SCORES.VALUE).from(HIGH_SCORES).join(PLAYERS).on(PLAYERS.ID.equal(HIGH_SCORES.PLAYER_ID)).where(HIGH_SCORES.SCORE_TYPE_ID.equal(scoreType.getId())).orderBy(scoreType.getOrder() == ScoreType.Order.ASC ? HIGH_SCORES.VALUE.asc() : HIGH_SCORES.VALUE.desc()).limit(count).fetch();
        return results.stream().map(record -> new Clause<>(getProfile(record.getValue(PLAYERS.UUID)), record.getValue(HIGH_SCORES.VALUE))).collect(Collectors.toList());
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return Lists.newArrayList();
}
Also used : DSL(org.jooq.impl.DSL) Connection(java.sql.Connection) Sponge(org.spongepowered.api.Sponge) PLAYERS(com.skelril.skree.db.schema.Tables.PLAYERS) UUID(java.util.UUID) Result(org.jooq.Result) Collectors(java.util.stream.Collectors) HIGH_SCORES(com.skelril.skree.db.schema.tables.HighScores.HIGH_SCORES) SQLHandle(com.skelril.skree.db.SQLHandle) ExecutionException(java.util.concurrent.ExecutionException) Record2(org.jooq.Record2) SQLException(java.sql.SQLException) List(java.util.List) Lists(com.google.common.collect.Lists) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) GameProfile(org.spongepowered.api.profile.GameProfile) Clause(com.skelril.nitro.Clause) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext) Clause(com.skelril.nitro.Clause) Record2(org.jooq.Record2)

Aggregations

Lists (com.google.common.collect.Lists)1 Clause (com.skelril.nitro.Clause)1 SQLHandle (com.skelril.skree.db.SQLHandle)1 PLAYERS (com.skelril.skree.db.schema.Tables.PLAYERS)1 HIGH_SCORES (com.skelril.skree.db.schema.tables.HighScores.HIGH_SCORES)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 DSLContext (org.jooq.DSLContext)1 Record1 (org.jooq.Record1)1 Record2 (org.jooq.Record2)1 Result (org.jooq.Result)1 DSL (org.jooq.impl.DSL)1 Sponge (org.spongepowered.api.Sponge)1 GameProfile (org.spongepowered.api.profile.GameProfile)1