/** * Maps this result set to a {@link ResultIterable}, using the given column mapper. * * @param mapper column mapper used to map the first column of each row * @param <T> the type to map the result set rows to * @return a {@link ResultIterable} of type {@code <T>}. */ default <T> ResultIterable<T> map(ColumnMapper<T> mapper) { return map(new SingleColumnMapper<>(mapper)); }
Optional<RowMapper<?>> getColumnMapper(Type type, int tupleIndex, ConfigRegistry config) { int colIndex = tupleIndex; return config.get(ColumnMappers.class) .findFor(type) .map(cm -> new SingleColumnMapper<>(cm, colIndex)); }
private Optional<RowMapper<?>> getColumnMapperForDefinedColumn(Type type, String col, ConfigRegistry config) { return config .get(ColumnMappers.class) .findFor(type) .map(cm -> new SingleColumnMapper<>(cm, col)); }
private static RowMapper<?> getValueMapper(Type valueType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getValueColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(valueType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map value " + valueType)); } else { return config.get(ColumnMappers.class) .findFor(valueType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map value " + valueType + " in column " + column)); } }
ColumnMapper<?> mapper = ctx.findColumnMapperFor(type) .orElse((ColumnMapper) (r, n, c) -> r.getObject(n)); mappers.add(new SingleColumnMapper<>(mapper, index + 1)); fields.add(field);
private static RowMapper<?> getKeyMapper(Type keyType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getKeyColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(keyType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map key " + keyType)); } else { return config.get(ColumnMappers.class) .findFor(keyType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map key " + keyType + " in column " + column)); } }
.orElseGet(() -> (ColumnMapper) defaultColumnMapper(property)); mappers.add(new SingleColumnMapper<>(mapper, index + 1)); propList.add(property);
.with(getQualifiers(parameter)); mappers[i] = ctx.findColumnMapperFor(type) .map(mapper -> new SingleColumnMapper<>(mapper, colIndex + 1)) .orElseThrow(() -> new IllegalArgumentException( String.format(MISSING_COLUMN_MAPPER, type, paramName, factory)));
/** * Maps this result set to a {@link ResultIterable}, using the given column mapper. * * @param mapper column mapper used to map the first column of each row * @param <T> the type to map the result set rows to * @return a {@link ResultIterable} of type {@code <T>}. */ default <T> ResultIterable<T> map(ColumnMapper<T> mapper) { return map(new SingleColumnMapper<>(mapper)); }
private static RowMapper<?> getKeyMapper(Type keyType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getKeyColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(keyType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map key " + keyType)); } else { return config.get(ColumnMappers.class) .findFor(keyType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map key " + keyType + " in column " + column)); } }
private static RowMapper<?> getValueMapper(Type valueType, ConfigRegistry config) { String column = config.get(MapEntryMappers.class).getValueColumn(); if (column == null) { return config.get(RowMappers.class) .findFor(valueType) .orElseThrow(() -> new NoSuchMapperException("No row mapper registered for map value " + valueType)); } else { return config.get(ColumnMappers.class) .findFor(valueType) .map(mapper -> new SingleColumnMapper<>(mapper, column)) .orElseThrow(() -> new NoSuchMapperException("No column mapper registered for map value " + valueType + " in column " + column)); } }
/** * @see io.apicurio.hub.core.storage.IStorage#getRecentApiDesigns(java.lang.String) */ @Override public Collection<ApiDesign> getRecentApiDesigns(String userId) throws StorageException { logger.debug("Getting a list of the user's recent APIs."); try { return this.jdbi.withHandle( handle -> { String statement = sqlStatements.selectRecentApiDesigns(); Collection<ApiDesign> designs = new ArrayList<>(); Collection<Long> recentApiIds = handle.createQuery(statement) .bind(0, userId) .map(new SingleColumnMapper<Long>(new ColumnMapper<Long>() { @Override public Long map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { return r.getLong(columnNumber); } }, "design_id")) .list(); for (Long did : recentApiIds) { designs.add(this.getApiDesign(userId, String.valueOf(did))); } return designs; }); } catch (Exception e) { throw new StorageException("Error listing API designs.", e); } }
/** * @see io.apicurio.hub.core.storage.IStorage#getRecentApiDesigns(java.lang.String) */ @Override public Collection<ApiDesign> getRecentApiDesigns(String userId) throws StorageException { logger.debug("Getting a list of the user's recent APIs."); try { return this.jdbi.withHandle( handle -> { String statement = sqlStatements.selectRecentApiDesigns(); Collection<ApiDesign> designs = new ArrayList<>(); Collection<Long> recentApiIds = handle.createQuery(statement) .bind(0, userId) .map(new SingleColumnMapper<Long>(new ColumnMapper<Long>() { @Override public Long map(ResultSet r, int columnNumber, StatementContext ctx) throws SQLException { return r.getLong(columnNumber); } }, "design_id")) .list(); for (Long did : recentApiIds) { designs.add(this.getApiDesign(userId, String.valueOf(did))); } return designs; }); } catch (Exception e) { throw new StorageException("Error listing API designs.", e); } }