use of org.jdbi.v3.core.statement.TemplateEngine 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.statement.TemplateEngine in project jdbi by jdbi.
the class UseTemplateEngineImpl method configureForType.
@Override
public void configureForType(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType) {
UseTemplateEngine anno = (UseTemplateEngine) annotation;
try {
final TemplateEngine templateEngine = instantiate(anno.value(), sqlObjectType, null);
registry.get(SqlStatements.class).setTemplateEngine(templateEngine);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
use of org.jdbi.v3.core.statement.TemplateEngine in project jdbi by jdbi.
the class UseTemplateEngineImpl method configureForMethod.
@Override
public void configureForMethod(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType, Method method) {
UseTemplateEngine anno = (UseTemplateEngine) annotation;
try {
final TemplateEngine templateEngine = instantiate(anno.value(), sqlObjectType, method);
registry.get(SqlStatements.class).setTemplateEngine(templateEngine);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
Aggregations