use of org.jdbi.v3.sqlobject.locator.SqlLocator 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);
}
Aggregations