org.jooq.Record类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(15.3k)|赞(0)|评价(0)|浏览(245)

本文整理了Java中org.jooq.Record类的一些代码示例,展示了Record类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Record类的具体详情如下:
包路径:org.jooq.Record
类名称:Record

Record介绍

[英]A database result record.

A record essentially combines a list of columns ( Field) with a corresponding list of values, each value being of the respective field's type.

While records can be seen as generic column / value mappings, their concrete implementations often specialise the above description in any of the following ways:

Table records

Records originating from a concrete database table (or view) are modelled by jOOQ as TableRecord or UpdatableRecord, if they contain a primary key. If you're using jOOQ's code generator, you can generate even more concrete types of table records, i.e. one table record per table.

UDT records

SQLDialect#ORACLE and SQLDialect#POSTGRES formally support user defined types (UDT), which are modelled by jOOQ as UDTRecord. In addition to being regular records (column / value mappings), they also implement the JDBC SQLData API in order to be streamed to a JDBC PreparedStatement or from a JDBC ResultSet

Records of well-defined degree

When projecting custom record types in SQL, new ad-hoc types of a certain degree are formed on the fly. Records with degree <= 22 are reflected by jOOQ through the Record1, Record2, ... Record22classes, which cover the respective row value expressions Row1, Row2, ... Row22

Note that generated TableRecords and UDTRecords also implement a Record[N] interface, if N <= 22

Record implements Comparable

jOOQ records have a natural ordering implemented in the same way as this is defined in the SQL standard. For more details, see the #compareTo(Record) method
[中]数据库结果记录。
记录实质上是将列(字段)列表与相应的值列表相结合,每个值都是相应字段的类型。
虽然记录可以被视为通用的列/值映射,但它们的具体实现通常以以下任一方式专门化上述描述:
#####表格记录
来自具体数据库表(或视图)的记录由jOOQ建模为TableRecord或UpdateRecord,如果它们包含主键。如果使用jOOQ的代码生成器,则可以生成更具体的表记录类型,即每个表一个表记录。
#####UDT记录
SQLDialogue#ORACLE和SQLDialogue#POSTGRES正式支持用户定义类型(UDT),jOOQ将其建模为UDT记录。除了作为常规记录(列/值映射),它们还实现了JDBC SQLData API,以便流式传输到JDBC PreparedStatement或JDBC ResultSet
#####定义明确的学位记录
在SQL中投影自定义记录类型时,会动态形成某种程度的新即席类型。度≤22的记录由jOOQ通过记录1、记录2。。。Record22类,其中包含相应的行值表达式Row1、Row2、。。。第22行
请注意,生成的TableRecordsUDTRecords也实现了Record[N]接口,如果N <= 22
#####记录可比性
jOOQ记录的自然顺序与SQL标准中定义的相同。有关更多详细信息,请参阅#compareTo(记录)方法

代码示例

代码示例来源:origin: palantir/atlasdb

@Override
public Multimap<Cell, Long> getAllTimestamps(final TableReference tableRef,
                       final Set<Cell> cells,
                       final long timestamp) throws InsufficientConsistencyException {
  if (cells.isEmpty()) {
    return ImmutableMultimap.of();
  }
  Multimap<Cell, Long> toReturn = ArrayListMultimap.create();
  for (List<Cell> partition : Iterables.partition(cells, batchSizeForReads)) {
    toReturn.putAll(run(ctx -> {
      Result<? extends Record> records = ctx
          .select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP)
          .from(atlasTable(tableRef).as(ATLAS_TABLE))
          .join(values(ctx, toRows(Sets.newHashSet(partition)), TEMP_TABLE_1, ROW_NAME, COL_NAME))
          .on(A_ROW_NAME.eq(T1_ROW_NAME)
              .and(A_COL_NAME.eq(T1_COL_NAME)))
          .where(A_TIMESTAMP.lessThan(timestamp))
          .fetch();
      Multimap<Cell, Long> results = ArrayListMultimap.create(records.size() / 4, 4);
      for (Record record : records) {
        results.put(
            Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)),
            record.getValue(A_TIMESTAMP));
      }
      return results;
    }));
  }
  return toReturn;
}

代码示例来源:origin: com.walmartlabs.concord.server/concord-server

@SuppressWarnings("unchecked")
private <E> E getOrNull(Record r, String fieldName) {
  Field<?> field = r.field(fieldName);
  if (field == null) {
    return null;
  }
  return (E) r.get(field);
}

代码示例来源:origin: my2iu/Jinq

private <K> void copyValueIntoRecord(T outputRecord, Record inputRecord, Field<K> field, int idx)
{
 outputRecord.setValue(field, inputRecord.getValue(idx, field.getConverter()));
}

代码示例来源:origin: shilad/wikibrain

@Override
public TIntSet getOutlinkIds(int sourceId) throws DaoException {
  DSLContext context = getJooq();
  try {
    Cursor<Record> result = context.select()
        .from(Tables.UNIVERSAL_SKELETAL_LINK)
        .where(Tables.UNIVERSAL_SKELETAL_LINK.SOURCE_ID.eq(sourceId))
        .and(Tables.UNIVERSAL_SKELETAL_LINK.ALGORITHM_ID.eq(algorithmId))
        .fetchLazy(getFetchSize());
    TIntSet ids = new TIntHashSet();
    for (Record record : result){
      ids.add(record.getValue(Tables.UNIVERSAL_SKELETAL_LINK.DEST_ID));
    }
    return ids;
  } finally {
    freeJooq(context);
  }
}

代码示例来源:origin: shilad/wikibrain

@Override
public String getBody(Language language, int rawLocalPageId) throws DaoException {
  DSLContext context = getJooq();
  try {
    return context.
      select().
      from(Tables.RAW_PAGE).
      where(Tables.RAW_PAGE.PAGE_ID.eq(rawLocalPageId)).
      and(Tables.RAW_PAGE.LANG_ID.eq(language.getId())).
      fetchOne().
      getValue(Tables.RAW_PAGE.BODY);
  } finally {
    freeJooq(context);
  }
}

代码示例来源:origin: com.walmartlabs.concord.server/concord-server

public List<IdAndStatus> getCascade(PartialProcessKey parentKey) {
  UUID parentInstanceId = parentKey.getInstanceId();
  try (DSLContext tx = DSL.using(cfg)) {
    return tx.withRecursive("children").as(
        select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.CREATED_AT, PROCESS_QUEUE.CURRENT_STATUS).from(PROCESS_QUEUE)
            .where(PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId))
            .unionAll(
                select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.CREATED_AT, PROCESS_QUEUE.CURRENT_STATUS).from(PROCESS_QUEUE)
                    .join(name("children"))
                    .on(PROCESS_QUEUE.PARENT_INSTANCE_ID.eq(
                        field(name("children", "INSTANCE_ID"), UUID.class)))))
        .select()
        .from(name("children"))
        .fetch(r -> new IdAndStatus(new ProcessKey(r.get(0, UUID.class), r.get(1, Timestamp.class)), ProcessStatus.valueOf(r.get(2, String.class))));
  }
}

代码示例来源:origin: org.jooq/jooq-meta

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
  TableConstraints tc = TABLE_CONSTRAINTS.as("tc");
  CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
  // [#2808] [#3019] Workaround for bad handling of JOIN .. USING
  Field<String> constraintName = field(name(cc.CONSTRAINT_NAME.getName()), String.class);
  for (Record record : create()
      .select(
        tc.TABLE_SCHEMA,
        tc.TABLE_NAME,
        constraintName,
        cc.CHECK_CLAUSE
       )
      .from(tc)
      .join(cc)
      .using(tc.CONSTRAINT_CATALOG, tc.CONSTRAINT_SCHEMA, tc.CONSTRAINT_NAME)
      .where(tc.TABLE_SCHEMA.in(getInputSchemata()))
      .fetch()) {
    SchemaDefinition schema = getSchema(record.get(tc.TABLE_SCHEMA));
    TableDefinition table = getTable(schema, record.get(tc.TABLE_NAME));
    if (table != null) {
      relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(
        schema,
        table,
        record.get(constraintName),
        record.get(cc.CHECK_CLAUSE)
      ));
    }
  }
}

代码示例来源:origin: mevdschee/java-crud-api

private void addFkRecords(ReflectedTable t2, HashMap<Object, Object> fkValues, Params params, DSLContext dsl,
    ArrayList<Record> records) {
  Field<Object> pk = t2.getPk();
  ArrayList<Field<?>> fields = columns.getNames(t2, false, params);
  ResultQuery<org.jooq.Record> query = dsl.select(fields).from(t2).where(pk.in(fkValues.keySet()));
  for (org.jooq.Record record : query.fetch()) {
    records.add(Record.valueOf(record.intoMap()));
  }
}

代码示例来源:origin: rancher/cattle

@Override
public Service getServiceByServiceIndexId(long serviceIndexId) {
  Record record = create()
      .select(SERVICE.fields())
      .from(SERVICE)
      .join(SERVICE_INDEX).on(SERVICE.ID.eq(SERVICE_INDEX.SERVICE_ID))
      .where(SERVICE_INDEX.ID.eq(serviceIndexId))
      .fetchAny();
  return record == null ? null : record.into(Service.class);
}

代码示例来源:origin: shilad/wikibrain

@Override
public TIntSet getRedirects(LocalPage localPage) throws DaoException {
  DSLContext context = getJooq();
  try {
    Result<Record> result = context.select().
        from(Tables.REDIRECT).
        where(Tables.REDIRECT.DEST_PAGE_ID.eq(localPage.getLocalId())).
        and(Tables.REDIRECT.LANG_ID.eq(localPage.getLanguage().getId())).
        fetch();
    TIntSet ids = new TIntHashSet();
    for (Record record : result){
      ids.add(record.getValue(Tables.REDIRECT.SRC_PAGE_ID));
    }
    return ids;
  } finally {
    freeJooq(context);
  }
}

代码示例来源:origin: mevdschee/java-crud-api

@Override
public ListDocument list(String tableName, Params params) {
  ArrayList<Record> records = new ArrayList<>();
  ReflectedTable table = reflection.getTable(tableName);
  includer.addMandatoryColumns(table, reflection, params);
  ArrayList<Field<?>> columnNames = columns.getNames(table, true, params);
  Condition condition= filters.getCombinedConditions(table, params);
  ArrayList<SortField<?>> columnOrdering = ordering.getColumnOrdering(table, params);
  int count = 0;
  ResultQuery<org.jooq.Record> query;
  if (!pagination.hasPage(params)) {
    int size = pagination.getResultSize(params);
    query = dsl.select(columnNames).from(table).where(condition).orderBy(columnOrdering);
    if (size != -1) {
      query = ((SelectLimitStep<org.jooq.Record>) query).limit(size);
    }
  } else {
    int offset = pagination.getPageOffset(params);
    int limit = pagination.getPageSize(params);
    count = (int) dsl.select(DSL.count()).from(table).where(condition).fetchOne(0);
    query = dsl.select(columnNames).from(table).where(condition).orderBy(columnOrdering).limit(offset, limit);
  }
  for (org.jooq.Record record : query.fetch()) {
    records.add(Record.valueOf(record.intoMap()));
  }
  includer.addIncludes(tableName, records, reflection, params, dsl);
  return new ListDocument(records.toArray(new Record[records.size()]), count);
}

代码示例来源:origin: k55k32/cms-admin-end

@Override
public Optional<T> getOptional(ID id) {
  Record record = getDSLContext().select().from(table).where(primaryKey.eq(id)).fetchOne();
  return Optional.ofNullable(record).map(r -> r.into(entityClass));
}

代码示例来源:origin: org.jooq/jooq-meta

.select(
  Constraints.TABLE_SCHEMA,
  Constraints.TABLE_NAME,
  Constraints.CHECK_EXPRESSION
  Columns.CHECK_CONSTRAINT
.from(COLUMNS)
.where(Columns.CHECK_CONSTRAINT.nvl("").ne(""))
.and(Columns.TABLE_SCHEMA.in(getInputSchemata())))
.fetch()) {
SchemaDefinition schema = getSchema(record.get(Constraints.TABLE_SCHEMA));
  TableDefinition table = getTable(schema, record.get(Constraints.TABLE_NAME));
      schema,
      table,
      record.get(Constraints.CONSTRAINT_NAME),
      record.get(Constraints.CHECK_EXPRESSION)
    ));

代码示例来源:origin: mevdschee/java-crud-api

@Override
public Record read(String tableName, String id, Params params) {
  ReflectedTable table = reflection.getTable(tableName);
  includer.addMandatoryColumns(table, reflection, params);
  ArrayList<Field<?>> columnNames = columns.getNames(table, true, params);
  Field<Object> pk = reflection.getTable(tableName).getPk();
  org.jooq.Record record = dsl.select(columnNames).from(table).where(pk.eq(id)).fetchOne();
  if (record == null) {
    return null;
  }
  Record r = Record.valueOf(record.intoMap());
  ArrayList<Record> records = new ArrayList<>(Arrays.asList(r));
  includer.addIncludes(tableName, records, reflection, params, dsl);
  return r;
}

代码示例来源:origin: org.jooq/jooq-meta

List<ColumnDefinition> result = new ArrayList<ColumnDefinition>();
for (Record record : create().select(
    Syscolumns.COLUMNNAME,
    Syscolumns.COLUMNNUMBER,
    Syscolumns.COLUMNDEFAULT,
    Syscolumns.AUTOINCREMENTINC)
  .from(SYSCOLUMNS)
  String typeName = record.get(Syscolumns.COLUMNDATATYPE, String.class);
  Number precision = parsePrecision(typeName);
  Number scale = parseScale(typeName);
    scale,
    !parseNotNull(typeName),
    record.get(Syscolumns.COLUMNDEFAULT)
  );
    record.get(Syscolumns.COLUMNNAME),
    record.get(Syscolumns.COLUMNNUMBER),
    type,
    null != record.get(Syscolumns.AUTOINCREMENTINC),
    null
  );

代码示例来源:origin: org.jooq/jooq-meta

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
  Field<String> fkName = field("fc.constraintname", String.class);
  Field<String> fkTable = field("ft.tablename", String.class);
  Field<String> fkSchema = field("fs.schemaname", String.class);
  Field<?> fkDescriptor = field("fg.descriptor");
  Field<String> ukName = field("pc.constraintname", String.class);
  Field<String> ukSchema = field("ps.schemaname", String.class);
  for (Record record : create().select(
      fkName,
      fkTable,
      ukName,
      ukSchema)
    .from("sys.sysconstraints   fc")
    .join("sys.sysforeignkeys   f ").on("f.constraintid = fc.constraintid")
    .join("sys.sysconglomerates fg").on("fg.conglomerateid = f.conglomerateid")
    .join("sys.systables        ft").on("ft.tableid = fg.tableid")
    .fetch()) {
    SchemaDefinition foreignKeySchema = getSchema(record.get(fkSchema));
    SchemaDefinition uniqueKeySchema = getSchema(record.get(ukSchema));
    String foreignKeyName = record.get(fkName);
    String foreignKeyTableName = record.get(fkTable);
    List<Integer> foreignKeyIndexes = decode(record.get(fkDescriptor, String.class));
    String uniqueKeyName = record.get(ukName);

代码示例来源:origin: org.jooq/jooq-meta

.select(
    ROUTINES.ROUTINE_SCHEMA,
    ROUTINES.ROUTINE_NAME,
    ROUTINES.SPECIFIC_NAME,
    nvl(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER, ROUTINES.DATA_TYPE).as("datatype"),
    ROUTINES.NUMERIC_PRECISION,
    ROUTINES.NUMERIC_SCALE,
    field(ROUTINES.ROUTINE_DEFINITION.likeRegex(".*(?i:(\\w+\\s+)+aggregate\\s+function).*")).as("aggregate"))
  .from(ROUTINES)
  .leftOuterJoin(ELEMENT_TYPES)
  .on(ROUTINES.ROUTINE_SCHEMA.equal(ELEMENT_TYPES.OBJECT_SCHEMA))
  .and(ROUTINES.ROUTINE_NAME.equal(ELEMENT_TYPES.OBJECT_NAME))
  .and(ROUTINES.DTD_IDENTIFIER.equal(ELEMENT_TYPES.COLLECTION_TYPE_IDENTIFIER))
  .where(ROUTINES.ROUTINE_SCHEMA.in(getInputSchemata()))
  .orderBy(
    ROUTINES.ROUTINE_SCHEMA,
    ROUTINES.ROUTINE_NAME)
  .fetch()) {
String datatype = record.get("datatype", String.class);
  getSchema(record.get(ROUTINES.ROUTINE_SCHEMA)),
  record.get(ROUTINES.ROUTINE_NAME),
  record.get(ROUTINES.SPECIFIC_NAME),
  datatype,
  record.get(ROUTINES.NUMERIC_PRECISION),
  record.get(ROUTINES.NUMERIC_SCALE),
  record.get("aggregate", boolean.class)));

代码示例来源:origin: org.jooq/jooq-meta

@Override
protected List<TableDefinition> getTables0() throws SQLException {
  List<TableDefinition> result = new ArrayList<TableDefinition>();
  for (Record record : create().select(
      Tables.TABLE_SCHEMA,
      Tables.TABLE_NAME,
      Tables.TABLE_COMMENT)
    .from(TABLES)
    // [#5213] Duplicate schema value to work around MySQL issue https://bugs.mysql.com/bug.php?id=86022
    .where(Tables.TABLE_SCHEMA.in(getInputSchemata()).or(
       getInputSchemata().size() == 1
      ? Tables.TABLE_SCHEMA.in(getInputSchemata())
      : falseCondition()))
    .orderBy(
      Tables.TABLE_SCHEMA,
      Tables.TABLE_NAME)
    .fetch()) {
    SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
    String name = record.get(Tables.TABLE_NAME);
    String comment = record.get(Tables.TABLE_COMMENT);
    MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment);
    result.add(table);
  }
  return result;
}

代码示例来源:origin: palantir/atlasdb

private Set<TableReference> getAllTableNames(DSLContext ctx) {
  Result<? extends Record> records = ctx
      .select(TABLE_NAME)
      .from(METADATA_TABLE)
      .fetch();
  Set<TableReference> tableRefs = Sets.newHashSetWithExpectedSize(records.size());
  for (Record record : records) {
    tableRefs.add(TableReference.createUnsafe(record.getValue(TABLE_NAME)));
  }
  return tableRefs;
}

代码示例来源:origin: org.jooq/jooq-meta

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
  for (Record record : create().select(
        ReferentialConstraints.CONSTRAINT_SCHEMA,
        ReferentialConstraints.CONSTRAINT_NAME,
        ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA,
        KeyColumnUsage.COLUMN_NAME)
      .from(REFERENTIAL_CONSTRAINTS)
      .join(KEY_COLUMN_USAGE)
      .on(ReferentialConstraints.CONSTRAINT_SCHEMA.equal(KeyColumnUsage.CONSTRAINT_SCHEMA))
      .and(ReferentialConstraints.CONSTRAINT_NAME.equal(KeyColumnUsage.CONSTRAINT_NAME))
      .fetch()) {
    SchemaDefinition foreignKeySchema = getSchema(record.get(ReferentialConstraints.CONSTRAINT_SCHEMA));
    SchemaDefinition uniqueKeySchema = getSchema(record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA));
    String foreignKey = record.get(ReferentialConstraints.CONSTRAINT_NAME);
    String foreignKeyColumn = record.get(KeyColumnUsage.COLUMN_NAME);
    String foreignKeyTableName = record.get(ReferentialConstraints.TABLE_NAME);
    String referencedKey = record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_NAME);
    String referencedTableName = record.get(ReferentialConstraints.REFERENCED_TABLE_NAME);

相关文章