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;
}
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();
}
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);
}
Aggregations