Search in sources :

Example 1 with Qualifiers

use of org.jdbi.v3.core.qualifier.Qualifiers in project jdbi by jdbi.

the class QualifiersBenchmark method setup.

@Setup
public void setup() throws Throwable {
    db = JdbiRule.h2();
    db.before();
    jdbi = db.getJdbi();
    jdbi.registerRowMapper(BeanMapper.factory(UnqualifiedBean.class));
    jdbi.registerRowMapper(BeanMapper.factory(QualifiedBean1.class));
    jdbi.registerRowMapper(BeanMapper.factory(QualifiedBean2.class));
    jdbi.registerRowMapper(BeanMapper.factory(QualifiedBean3.class));
    jdbi.registerRowMapper(BeanMapper.factory(QualifiedBean4.class));
    qualifiers = new Qualifiers();
    qualifiers.setRegistry(new ConfigRegistry());
}
Also used : ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) Qualifiers(org.jdbi.v3.core.qualifier.Qualifiers) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with Qualifiers

use of org.jdbi.v3.core.qualifier.Qualifiers in project jdbi by jdbi.

the class ResultReturner method forMethod.

/**
 * Inspect a Method for its return type, and choose a ResultReturner subclass
 * that handles any container that might wrap the results.
 * @param extensionType the type that owns the Method
 * @param method the method whose return type chooses the ResultReturner
 * @return an instance that takes a ResultIterable and constructs the return value
 */
static ResultReturner forMethod(Class<?> extensionType, Method method) {
    Type returnType = GenericTypes.resolveType(method.getGenericReturnType(), extensionType);
    QualifiedType<?> qualifiedReturnType = QualifiedType.of(returnType).withAnnotations(new Qualifiers().findFor(method));
    Class<?> returnClass = getErasedType(returnType);
    if (Void.TYPE.equals(returnClass)) {
        return findConsumer(method).orElseThrow(() -> new IllegalStateException(String.format("Method %s#%s is annotated as if it should return a value, but the method is void.", method.getDeclaringClass().getName(), method.getName())));
    } else if (ResultIterable.class.equals(returnClass)) {
        return new ResultIterableReturner(qualifiedReturnType);
    } else if (Stream.class.equals(returnClass)) {
        return new StreamReturner(qualifiedReturnType);
    } else if (ResultIterator.class.equals(returnClass)) {
        return new ResultIteratorReturner(qualifiedReturnType);
    } else if (Iterator.class.equals(returnClass)) {
        return new IteratorReturner(qualifiedReturnType);
    } else if (method.isAnnotationPresent(SingleValue.class)) {
        return new SingleValueReturner(qualifiedReturnType);
    } else {
        return new CollectedResultReturner(qualifiedReturnType);
    }
}
Also used : SingleValue(org.jdbi.v3.sqlobject.SingleValue) ResultIterator(org.jdbi.v3.core.result.ResultIterator) ResultIterable(org.jdbi.v3.core.result.ResultIterable) Type(java.lang.reflect.Type) GenericTypes.getErasedType(org.jdbi.v3.core.generic.GenericTypes.getErasedType) QualifiedType(org.jdbi.v3.core.qualifier.QualifiedType) Qualifiers(org.jdbi.v3.core.qualifier.Qualifiers)

Example 3 with Qualifiers

use of org.jdbi.v3.core.qualifier.Qualifiers in project jdbi by jdbi.

the class ArgumentBinderTest method before.

@BeforeEach
public void before() {
    when(ctx.getConfig(Qualifiers.class)).thenReturn(new Qualifiers());
    when(ctx.getConfig(SqlStatements.class)).thenReturn(statements);
    when(ctx.getConfig(Arguments.class)).thenReturn(new Arguments(new ConfigRegistry()));
}
Also used : ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) Arguments(org.jdbi.v3.core.argument.Arguments) Qualifiers(org.jdbi.v3.core.qualifier.Qualifiers) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Qualifiers (org.jdbi.v3.core.qualifier.Qualifiers)3 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)2 Type (java.lang.reflect.Type)1 Arguments (org.jdbi.v3.core.argument.Arguments)1 GenericTypes.getErasedType (org.jdbi.v3.core.generic.GenericTypes.getErasedType)1 QualifiedType (org.jdbi.v3.core.qualifier.QualifiedType)1 ResultIterable (org.jdbi.v3.core.result.ResultIterable)1 ResultIterator (org.jdbi.v3.core.result.ResultIterator)1 SingleValue (org.jdbi.v3.sqlobject.SingleValue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Setup (org.openjdk.jmh.annotations.Setup)1