org.jdbi.v3.core.qualifier.Qualifiers类的使用及代码示例

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

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

Qualifiers介绍

[英]Utility class for type qualifiers supported by Jdbi core.
[中]用于Jdbi core支持的类型限定符的实用程序类。

代码示例

代码示例来源:origin: jdbi/jdbi

@Benchmark
public Set<Annotation> getQualifiersAnnotated() {
  return Qualifiers.getQualifiers(QualifiedBean.class);
}

代码示例来源:origin: jdbi/jdbi

@Benchmark
public Set<Annotation> getQualifiersUnannotated() {
  return Qualifiers.getQualifiers(UnqualifiedBean.class);
}

代码示例来源:origin: jdbi/jdbi

JpaMember(Class<?> clazz, Column column, Field field) {
  this.clazz = requireNonNull(clazz);
  this.columnName = nameOf(column, field.getName());
  this.qualifiedType = QualifiedType.of(field.getGenericType()).with(getQualifiers(field));
  field.setAccessible(true);
  this.accessor = field::get;
  this.mutator = field::set;
}

代码示例来源:origin: jdbi/jdbi

ConsumerResultReturner(Method method, int consumerIndex) {
  this.consumerIndex = consumerIndex;
  Type parameterType = method.getGenericParameterTypes()[consumerIndex];
  this.elementType = QualifiedType.of(
    GenericTypes.findGenericParameter(parameterType, Consumer.class)
      .orElseThrow(() -> new IllegalStateException(
        "Cannot reflect Consumer<T> element type T in method consumer parameter "
          + parameterType)))
    .with(getQualifiers(method.getParameters()[consumerIndex]));
}

代码示例来源:origin: jdbi/jdbi

JpaMember(Class<?> clazz, Column column, PropertyDescriptor property) {
  this.clazz = requireNonNull(clazz);
  this.columnName = nameOf(column, property.getName());
  Method getter = property.getReadMethod();
  Method setter = property.getWriteMethod();
  Parameter setterParam = setter.getParameters()[0];
  getter.setAccessible(true);
  setter.setAccessible(true);
  this.qualifiedType = QualifiedType.of(getter.getGenericReturnType())
    .with(getQualifiers(getter, setter, setterParam));
  this.accessor = getter::invoke;
  this.mutator = setter::invoke;
}

代码示例来源:origin: jdbi/jdbi

InferredColumnMapperFactory(ColumnMapper<?> mapper) {
  this.maps = QualifiedType.of(
    findGenericParameter(mapper.getClass(), ColumnMapper.class)
      .orElseThrow(() -> new UnsupportedOperationException("Must use a concretely typed ColumnMapper here")))
    .with(getQualifiers(mapper.getClass()));
  this.mapper = mapper;
}

代码示例来源:origin: jdbi/jdbi

/**
 * Adapts a {@link ColumnMapperFactory} into a QualifiedColumnMapperFactory. The returned
 * factory only matches qualified types with zero qualifiers.
 *
 * @param factory the factory to adapt
 */
static QualifiedColumnMapperFactory adapt(ColumnMapperFactory factory) {
  Set<Annotation> qualifiers = getQualifiers(factory.getClass());
  return (type, config) -> type.getQualifiers().equals(qualifiers)
    ? factory.build(type.getType(), config)
    : Optional.empty();
}

代码示例来源:origin: jdbi/jdbi

/**
   * Adapts an {@link ArgumentFactory} into a QualifiedArgumentFactory. The returned factory only
   * matches qualified types with zero qualifiers.
   *
   * @param factory the factory to adapt
   */
  static QualifiedArgumentFactory adapt(ArgumentFactory factory) {
    Set<Annotation> qualifiers = getQualifiers(factory.getClass());
    return (type, value, config) -> type.getQualifiers().equals(qualifiers)
      ? factory.build(type.getType(), value, config)
      : Optional.empty();
  }
}

代码示例来源:origin: jdbi/jdbi

@Override
protected Optional<TypedValue> getValue(String name, StatementContext ctx) {
  Method method = methods.get(name);
  if (method == null) {
    return Optional.empty();
  }
  QualifiedType<?> type = QualifiedType.of(method.getGenericReturnType())
              .with(getQualifiers(method));
  Object value = invokeMethod(method, ctx);
  return Optional.of(new TypedValue(type, value));
}

代码示例来源:origin: jdbi/jdbi

@Override
protected Optional<TypedValue> getValue(String name, StatementContext ctx) {
  Field field = fields.get(name);
  if (field == null) {
    return Optional.empty();
  }
  try {
    QualifiedType<?> type = QualifiedType.of(field.getGenericType())
                .with(getQualifiers(field));
    Object value = field.get(obj);
    return Optional.of(new TypedValue(type, value));
  } catch (IllegalAccessException e) {
    throw new UnableToCreateStatementException(String.format("Access exception getting field for "
        + "bean property [%s] on [%s]",
      name, obj), e, ctx);
  }
}

代码示例来源:origin: jdbi/jdbi

@Override
protected ImmutablesPojoProperty<T> createProperty(String name, Method m) {
  final Class<?> builderClass = builder.get().getClass();
  try {
    final Type propertyType = GenericTypes.resolveType(m.getGenericReturnType(), getType());
    return new ImmutablesPojoProperty<T>(
        name,
        QualifiedType.of(propertyType).with(Qualifiers.getQualifiers(m)),
        m,
        alwaysSet(),
        MethodHandles.lookup().unreflect(m),
        findBuilderSetter(builderClass, name, propertyType));
  } catch (IllegalAccessException | NoSuchMethodException e) {
    throw new IllegalArgumentException("Failed to inspect method " + m, e);
  }
}

代码示例来源:origin: jdbi/jdbi

QualifiedType<?> qualifiedReturnType = QualifiedType.of(returnType).with(getQualifiers(method));
Class<?> returnClass = getErasedType(returnType);
if (Void.TYPE.equals(returnClass)) {

代码示例来源:origin: jdbi/jdbi

.ifPresent(index -> {
  QualifiedType<?> type = QualifiedType.of(field.getGenericType())
    .with(getQualifiers(field));
  @SuppressWarnings("unchecked")
  ColumnMapper<?> mapper = ctx.findColumnMapperFor(type)

代码示例来源:origin: jdbi/jdbi

@Override
protected ImmutablesPojoProperty<T> createProperty(String name, Method m) {
  final Type propertyType = GenericTypes.resolveType(m.getGenericReturnType(), getType());
  try {
    return new ImmutablesPojoProperty<T>(
        name,
        QualifiedType.of(propertyType).with(Qualifiers.getQualifiers(m)),
        m,
        isSetMethod(name),
        MethodHandles.lookup().unreflect(m),
        MethodHandles.lookup().findVirtual(impl, setterName(name), MethodType.methodType(impl, GenericTypes.getErasedType(propertyType))));
  } catch (IllegalAccessException | NoSuchMethodException e) {
    throw new IllegalArgumentException("Failed to inspect method " + m, e);
  }
}

代码示例来源:origin: jdbi/jdbi

@Override
  public SqlStatementParameterCustomizer createForParameter(Annotation annotation,
                               Class<?> sqlObjectType,
                               Method method,
                               Parameter param,
                               int index,
                               Type type) {
    Bind b = (Bind) annotation;
    String nameFromAnnotation = b == null ? Bind.NO_VALUE : b.value();
    Optional<String> name = ParameterUtil.findParameterName(nameFromAnnotation, param);
    QualifiedType<?> qualifiedType = QualifiedType.of(type).with(getQualifiers(param));

    return (stmt, arg) -> {
      stmt.bindByType(index, arg, qualifiedType);
      name.ifPresent(n -> stmt.bindByType(n, arg, qualifiedType));
    };
  }
}

代码示例来源:origin: jdbi/jdbi

int colIndex = columnIndex.getAsInt();
final QualifiedType<?> type = QualifiedType.of(parameter.getParameterizedType())
  .with(getQualifiers(parameter));
mappers[i] = ctx.findColumnMapperFor(type)
  .map(mapper -> new SingleColumnMapper<>(mapper, colIndex + 1))

代码示例来源:origin: jdbi/jdbi

@Test
public void getQualifiers() throws Exception {
  assertThat(foo(1))
    .isEqualTo(foo(1))
    .isNotEqualTo(foo(2));
  assertThat(Qualifiers.getQualifiers(getClass().getDeclaredField("qualifiedField")))
    .containsExactly(foo(1));
  assertThat(Qualifiers.getQualifiers(getClass().getDeclaredMethod("qualifiedMethod")))
    .containsExactly(foo(2));
  assertThat(Qualifiers.getQualifiers(getClass().getDeclaredMethod("qualifiedParameter", String.class).getParameters()[0]))
    .containsExactly(foo(3));
  assertThat(Qualifiers.getQualifiers(QualifiedClass.class))
    .containsExactly(foo(4));
  assertThat(Qualifiers.getQualifiers(QualifiedClass.class.getDeclaredConstructor(String.class).getParameters()[0]))
    .containsExactly(foo(5));
  assertThat(Qualifiers.getQualifiers(getClass().getDeclaredField("twoQualifiers")))
    .containsExactlyInAnyOrder(foo(6), bar("six"));
}

代码示例来源:origin: jdbi/jdbi

public SqlUpdateHandler(Class<?> sqlObjectType, Method method) {
  super(sqlObjectType, method);
  if (method.isAnnotationPresent(UseRowReducer.class)) {
    throw new UnsupportedOperationException("Cannot declare @UseRowReducer on a @SqlUpdate method.");
  }
  boolean isGetGeneratedKeys = method.isAnnotationPresent(GetGeneratedKeys.class);
  QualifiedType<?> returnType = QualifiedType.of(
    GenericTypes.resolveType(method.getGenericReturnType(), sqlObjectType))
    .with(getQualifiers(method));
  if (isGetGeneratedKeys) {
    ResultReturner magic = ResultReturner.forMethod(sqlObjectType, method);
    String[] columnNames = method.getAnnotation(GetGeneratedKeys.class).value();
    this.returner = update -> {
      ResultBearing resultBearing = update.executeAndReturnGeneratedKeys(columnNames);
      UseRowMapper useRowMapper = method.getAnnotation(UseRowMapper.class);
      ResultIterable<?> iterable = useRowMapper == null
          ? resultBearing.mapTo(returnType)
          : resultBearing.map(rowMapperFor(useRowMapper));
      return magic.mappedResult(iterable, update.getContext());
    };
  } else if (isNumeric(method.getReturnType())) {
    this.returner = update -> update.execute();
  } else if (isBoolean(method.getReturnType())) {
    this.returner = update -> update.execute() > 0;
  } else {
    throw new UnableToCreateSqlObjectException(invalidReturnTypeMessage(method, returnType));
  }
}

代码示例来源:origin: jdbi/jdbi

/**
 * Determines which strategy is to be used for a given {@link QualifiedType}, falling back to
 * reading strategy annotations on the source class and/or using the configured default.
 *
 * @param <E> the {@link Enum} type
 * @param type qualified type to derive a strategy from
 * @return the strategy by which this enum should be handled
 */
public <E extends Enum<E>> EnumStrategy findStrategy(QualifiedType<E> type) {
  Class<?> erasedType = getErasedType(type.getType());
  return JdbiOptionals.findFirstPresent(
    () -> doFindStrategy(type),
    () -> doFindStrategy(QualifiedType.of(erasedType).with(getQualifiers(erasedType)))
  ).orElseGet(() -> registry.get(Enums.class).getDefaultStrategy());
}

相关文章

Qualifiers类方法