Search in sources :

Example 1 with Record2

use of org.jooq.Record2 in project jOOQ by jOOQ.

the class PostgresDatabase method getEnums0.

@Override
protected List<EnumDefinition> getEnums0() throws SQLException {
    List<EnumDefinition> result = new ArrayList<EnumDefinition>();
    // [#2736] This table is unavailable in Amazon Redshift
    if (exists(PG_ENUM)) {
        // [#2707] Fetch all enum type names first, in order to be able to
        // perform enumlabel::[typname] casts in the subsequent query for
        // cross-version compatible enum literal ordering
        Result<Record2<String, String>> types = create().select(PG_NAMESPACE.NSPNAME, PG_TYPE.TYPNAME).from(PG_TYPE).join(PG_NAMESPACE).on(PG_TYPE.TYPNAMESPACE.eq(oid(PG_NAMESPACE))).where(PG_NAMESPACE.NSPNAME.in(getInputSchemata())).and(oid(PG_TYPE).in(select(PG_ENUM.ENUMTYPID).from(PG_ENUM))).orderBy(PG_NAMESPACE.NSPNAME, PG_TYPE.TYPNAME).fetch();
        for (Record2<String, String> type : types) {
            String nspname = type.get(PG_NAMESPACE.NSPNAME);
            String typname = type.get(PG_TYPE.TYPNAME);
            DefaultEnumDefinition definition = null;
            for (String label : enumLabels(nspname, typname)) {
                SchemaDefinition schema = getSchema(nspname);
                String typeName = String.valueOf(typname);
                if (definition == null || !definition.getName().equals(typeName)) {
                    definition = new DefaultEnumDefinition(schema, typeName, null);
                    result.add(definition);
                }
                definition.addLiteral(label);
            }
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) DefaultEnumDefinition(org.jooq.util.DefaultEnumDefinition) EnumDefinition(org.jooq.util.EnumDefinition) DefaultEnumDefinition(org.jooq.util.DefaultEnumDefinition) Record2(org.jooq.Record2)

Example 2 with Record2

use of org.jooq.Record2 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)

Example 3 with Record2

use of org.jooq.Record2 in project jOOQ by jOOQ.

the class MockArray method getResultSet0.

@SuppressWarnings("unchecked")
private ResultSet getResultSet0(T[] a) {
    DSLContext create = DSL.using(dialect);
    Field<Long> index = field(name("INDEX"), Long.class);
    Field<T> value = (Field<T>) field(name("VALUE"), type.getComponentType());
    Result<Record2<Long, T>> result = create.newResult(index, value);
    for (int i = 0; i < a.length; i++) {
        Record2<Long, T> record = create.newRecord(index, value);
        record.setValue(index, i + 1L);
        record.setValue(value, a[i]);
        result.add(record);
    }
    return new MockResultSet(result);
}
Also used : Field(org.jooq.Field) DSLContext(org.jooq.DSLContext) Record2(org.jooq.Record2)

Aggregations

Record2 (org.jooq.Record2)3 DSLContext (org.jooq.DSLContext)2 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 ArrayList (java.util.ArrayList)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 Field (org.jooq.Field)1 Record1 (org.jooq.Record1)1 Result (org.jooq.Result)1 DSL (org.jooq.impl.DSL)1 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)1