Search in sources :

Example 31 with ConfigRegistry

use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.

the class RegisterArgumentFactoryImpl method configureForType.

@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
    RegisterArgumentFactory raf = (RegisterArgumentFactory) annotation;
    Arguments arguments = registry.get(Arguments.class);
    try {
        arguments.register(raf.value().newInstance());
    } catch (Exception e) {
        throw new IllegalStateException("unable to instantiate specified argument factory", e);
    }
}
Also used : RegisterArgumentFactory(org.jdbi.v3.sqlobject.config.RegisterArgumentFactory) Arguments(org.jdbi.v3.core.argument.Arguments)

Example 32 with ConfigRegistry

use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.

the class RegisterBeanMapperImpl method configureForType.

@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
    RegisterBeanMapper registerBeanMapper = (RegisterBeanMapper) annotation;
    Class<?> beanClass = registerBeanMapper.value();
    String prefix = registerBeanMapper.prefix();
    RowMappers mappers = registry.get(RowMappers.class);
    if (prefix.isEmpty()) {
        mappers.register(BeanMapper.factory(beanClass));
    } else {
        mappers.register(BeanMapper.factory(beanClass, prefix));
    }
}
Also used : RowMappers(org.jdbi.v3.core.mapper.RowMappers) RegisterBeanMapper(org.jdbi.v3.sqlobject.config.RegisterBeanMapper)

Example 33 with ConfigRegistry

use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.

the class RegisterBeanMappersImpl method configureForType.

@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
    Configurer delegate = new RegisterBeanMapperImpl();
    RegisterBeanMappers registerBeanMappers = (RegisterBeanMappers) annotation;
    Stream.of(registerBeanMappers.value()).forEach(anno -> delegate.configureForType(registry, anno, sqlObjectType));
}
Also used : RegisterBeanMappers(org.jdbi.v3.sqlobject.config.RegisterBeanMappers) Configurer(org.jdbi.v3.sqlobject.config.Configurer)

Example 34 with ConfigRegistry

use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.

the class TestSqlObjectMethodBehavior method setUp.

@Before
public void setUp() throws Exception {
    HandleSupplier handleSupplier = new HandleSupplier() {

        @Override
        public ConfigRegistry getConfig() {
            return new ConfigRegistry();
        }

        @Override
        public Handle getHandle() {
            throw new UnsupportedOperationException();
        }

        @Override
        public <V> V invokeInContext(ExtensionMethod extensionMethod, ConfigRegistry config, Callable<V> task) throws Exception {
            return task.call();
        }
    };
    SqlObjectFactory factory = new SqlObjectFactory();
    dao = factory.attach(UselessDao.class, handleSupplier);
    anotherDao = factory.attach(UselessDao.class, handleSupplier);
}
Also used : ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) HandleSupplier(org.jdbi.v3.core.extension.HandleSupplier) ExtensionMethod(org.jdbi.v3.core.extension.ExtensionMethod) Callable(java.util.concurrent.Callable) Before(org.junit.Before)

Aggregations

Configurer (org.jdbi.v3.sqlobject.config.Configurer)10 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)8 RowMappers (org.jdbi.v3.core.mapper.RowMappers)5 SqlStatements (org.jdbi.v3.core.statement.SqlStatements)5 ColumnMappers (org.jdbi.v3.core.mapper.ColumnMappers)4 Type (java.lang.reflect.Type)3 Optional (java.util.Optional)3 ExtensionMethod (org.jdbi.v3.core.extension.ExtensionMethod)3 TemplateEngine (org.jdbi.v3.core.statement.TemplateEngine)3 Method (java.lang.reflect.Method)2 Types (java.sql.Types)2 Argument (org.jdbi.v3.core.argument.Argument)2 Arguments (org.jdbi.v3.core.argument.Arguments)2 JdbiCollectors (org.jdbi.v3.core.collector.JdbiCollectors)2 GenericTypes (org.jdbi.v3.core.generic.GenericTypes)2 ColumnMapperFactory (org.jdbi.v3.core.mapper.ColumnMapperFactory)2 MapEntryMappers (org.jdbi.v3.core.mapper.MapEntryMappers)2 SqlParser (org.jdbi.v3.core.statement.SqlParser)2 UseSqlParser (org.jdbi.v3.sqlobject.config.UseSqlParser)2 UseTemplateEngine (org.jdbi.v3.sqlobject.config.UseTemplateEngine)2