@Override @Nullable public PutBatch getNextBatch(Result<? extends Record> existingRecords) { Map<Cell, byte[]> existing = Maps.newHashMapWithExpectedSize(existingRecords.size()); for (Record record : existingRecords) { existing.put( Cell.create(record.getValue(JdbcConstants.A_ROW_NAME), record.getValue(JdbcConstants.A_COL_NAME)), record.getValue(JdbcConstants.A_VALUE)); } Map<Cell, byte[]> nextBatch = Maps.newHashMap(); for (Entry<Cell, byte[]> entry : data.entrySet()) { Cell cell = entry.getKey(); byte[] newValue = entry.getValue(); byte[] oldValue = existing.get(cell); if (oldValue == null) { nextBatch.put(cell, newValue); } else if (!Arrays.equals(oldValue, newValue)) { return null; } } return new SingleTimestampPutBatch(nextBatch, timestamp); }
@Override public final <T> List<T> fetchInto(Class<? extends T> type) { return fetch().into(type); }
/** * Use a previously obtained result as a new {@link Table} that can be used * in SQL statements through {@link #values(RowN...)}. * * @see #values(RowN...) */ @Support public static <R extends Record> Table<R> table(Result<R> result) { int size = result.size(); RowN[] rows = new RowN[size]; for (int i = 0; i < size; i++) rows[i] = (RowN) result.get(i).valuesRow(); Field<?>[] fields = result.fields(); String[] columns = new String[fields.length]; for (int i = 0; i < fields.length; i++) columns[i] = fields[i].getName(); // TODO [#2986] Coerce the record type upon the resulting table. return (Table<R>) values(rows).as("v", columns); }
public List<Pizza> findOrderByIdAsc() { List<Result<Record>> values = dslContext.selectDistinct() .from(PIZZA) .innerJoin(BASE).on(BASE.ID.eq(PIZZA.BASE_ID)) .innerJoin(PIZZA_TOPPINGS).on(PIZZA_TOPPINGS.PIZZA_ID.eq(PIZZA.ID)) .innerJoin(TOPPING).on(TOPPING.ID.eq(PIZZA_TOPPINGS.TOPPINGS_ID)) .orderBy(PIZZA.ID.asc()) .fetch() .intoGroups(PIZZA.fields()) .values() .stream() .collect(Collectors.toList()); if (values.isEmpty()) { return Collections.emptyList(); } return values.stream() .map(r -> { Pizza pizza = r.into(PIZZA.ID, PIZZA.NAME, PIZZA.PRICE).get(0).into(Pizza.class); pizza.setBase(r.into(BASE.ID, BASE.NAME).get(0).into(Base.class)); pizza.setToppings(r.sortAsc(TOPPING.ID).into(Topping.class)); return pizza; }) .collect(Collectors.toList()); }
@Override public final <E> List<E> fetch(RecordMapper<? super R, E> mapper) { return fetch().map(mapper); }
@Override public final <U> U[] fetchArray(int fieldIndex, Converter<?, ? extends U> converter) { return fetch().intoArray(fieldIndex, converter); }
@Override public void resultEnd(ExecuteContext ctx) { if (ctx.result() != null) { if (log.isTraceEnabled()) logMultiline("Fetched result", ctx.result().format(TXTFormat.DEFAULT.maxRows(500).maxColWidth(500)), Level.FINE); else if (log.isDebugEnabled()) logMultiline("Fetched result", ctx.result().format(TXTFormat.DEFAULT.maxRows(5).maxColWidth(50)), Level.FINE); if (log.isDebugEnabled()) log.debug("Fetched row(s)", ctx.result().size()); } }
@Override public final Map<?, Result<R>> fetchGroups(int keyFieldIndex) { return fetch().intoGroups(keyFieldIndex); }
private <T> T getValue(int columnIndex, Class<T> type) throws SQLException { checkInRange(); checkField(columnIndex); T value = result.get(index - 1).getValue(columnIndex - 1, type); wasNull = (value == null); return value; }
@Override protected Map<String, Integer> create() { Connection connection = openConnection(); try (DSLContext context = openContext(connection)) { ResultQuery<Record2<Integer, String>> query = context .select(symbolIdField, symbolValueField) .from(symbolTable); try { Map<String, Integer> symbolIds = new ConcurrentHashMap<>(); query.fetch().forEach(r -> symbolIds.put(r.value2(), r.value1())); return symbolIds; } catch (DataAccessException error) { throw convertJooqError(error, query); } } finally { closeConnection(connection); } } };
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; }
@Override public final <Z extends Record> Result<Z> fetchInto(Table<Z> table) { return fetch().into(table); }
/** * Use a previously obtained result as a new {@link Table} that can be used * in SQL statements through {@link #values(RowN...)}. * * @see #values(RowN...) */ @Support @Transition( name = "TABLE", args = "Result" ) public static <R extends Record> Table<R> table(Result<R> result) { int size = result.size(); RowN[] rows = new RowN[size]; for (int i = 0; i < size; i++) rows[i] = (RowN) result.get(i).valuesRow(); Field<?>[] fields = result.fields(); String[] columns = new String[fields.length]; for (int i = 0; i < fields.length; i++) columns[i] = fields[i].getName(); // TODO [#2986] Coerce the record type upon the resulting table. return (Table<R>) values(rows).as("v", columns); }
@Override public final <E> List<E> fetch(RecordMapper<? super R, E> mapper) { return fetch().map(mapper); }
@Override public final Object[] fetchArray(int fieldIndex) { return fetch().intoArray(fieldIndex); }
@Override public final Map<?, List<?>> fetchGroups(Name keyFieldName, Name valueFieldName) { return fetch().intoGroups(keyFieldName, valueFieldName); }
private <T> T getValue(String columnLabel, Class<T> type) throws SQLException { checkInRange(); checkField(columnLabel); T value = result.get(index - 1).getValue(columnLabel, type); wasNull = (value == null); return value; }