use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class UseStringTemplateSqlLocatorImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
SqlLocator locator = (type, method, config) -> {
String templateName = SqlAnnotations.getAnnotationValue(method, sql -> sql).orElseGet(method::getName);
STGroup group = findStringTemplateGroup(type);
if (!group.isDefined(templateName)) {
throw new IllegalStateException("No StringTemplate group " + templateName + " for class " + sqlObjectType);
}
return templateName;
};
TemplateEngine templateEngine = (templateName, ctx) -> {
STGroup group = findStringTemplateGroup(sqlObjectType);
ST template = group.getInstanceOf(templateName);
ctx.getAttributes().forEach(template::add);
return template.render();
};
registry.get(SqlObjects.class).setSqlLocator(locator);
registry.get(SqlStatements.class).setTemplateEngine(templateEngine);
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class RegisterCollectorFactoryImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
RegisterCollectorFactory registerCollectorFactory = (RegisterCollectorFactory) annotation;
JdbiCollectors collectors = registry.get(JdbiCollectors.class);
Class<? extends CollectorFactory> type = registerCollectorFactory.value();
try {
collectors.register(type.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalStateException("Unable to instantiate container factory", e);
}
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class RegisterColumnMapperImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
RegisterColumnMapper registerColumnMapper = (RegisterColumnMapper) annotation;
ColumnMappers mappers = registry.get(ColumnMappers.class);
try {
mappers.register(registerColumnMapper.value().newInstance());
} catch (Exception e) {
throw new IllegalStateException("unable to create a specified column mapper", e);
}
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class RegisterColumnMappersImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
Configurer delegate = new RegisterColumnMapperImpl();
RegisterColumnMappers registerColumnMappers = (RegisterColumnMappers) annotation;
Stream.of(registerColumnMappers.value()).forEach(anno -> delegate.configureForType(registry, anno, sqlObjectType));
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class RegisterConstructorMapperImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
RegisterConstructorMapper registerConstructorMapper = (RegisterConstructorMapper) annotation;
RowMappers mappers = registry.get(RowMappers.class);
Class<?> type = registerConstructorMapper.value();
String prefix = registerConstructorMapper.prefix();
if (prefix.isEmpty()) {
mappers.register(ConstructorMapper.factory(type));
} else {
mappers.register(ConstructorMapper.factory(type, prefix));
}
}
Aggregations