use of org.jdbi.v3.core.config.ConfigRegistry 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.config.ConfigRegistry in project jdbi by jdbi.
the class ValueColumnImpl method configureForMethod.
@Override
public void configureForMethod(ConfigRegistry registry, Annotation annotation, Class<?> sqlObjectType, Method method) {
ValueColumn valueColumn = (ValueColumn) annotation;
String name = valueColumn.value();
registry.get(MapEntryMappers.class).setValueColumn(name.isEmpty() ? null : name);
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class SqlObjectFactory method attach.
/**
* Create a sql object of the specified type bound to this handle. Any state changes to the handle, or the sql
* object, such as transaction status, closing it, etc, will apply to both the object and the handle.
*
* @param extensionType the type of sql object to create
* @param handle the Handle instance to attach ths sql object to
* @return the new sql object bound to this handle
*/
@Override
public <E> E attach(Class<E> extensionType, HandleSupplier handle) {
Map<Method, Handler> handlers = methodHandlersFor(extensionType, handle.getConfig(Handlers.class), handle.getConfig(HandlerDecorators.class));
ConfigRegistry instanceConfig = handle.getConfig().createCopy();
for (Class<?> iface : extensionType.getInterfaces()) {
forEachConfigurer(iface, (configurer, annotation) -> configurer.configureForType(instanceConfig, annotation, extensionType));
}
forEachConfigurer(extensionType, (configurer, annotation) -> configurer.configureForType(instanceConfig, annotation, extensionType));
InvocationHandler invocationHandler = createInvocationHandler(extensionType, instanceConfig, handlers, handle);
return extensionType.cast(Proxy.newProxyInstance(extensionType.getClassLoader(), new Class[] { extensionType }, invocationHandler));
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class BuiltInArgumentFactory method build.
@Override
@SuppressWarnings("unchecked")
public Optional<Argument> build(Type expectedType, Object value, ConfigRegistry config) {
Class<?> expectedClass = getErasedType(expectedType);
if (value != null && expectedClass == Object.class) {
expectedClass = value.getClass();
}
@SuppressWarnings("rawtypes") ArgBuilder v = BUILDERS.get(expectedClass);
if (v != null) {
return Optional.of(v.build(value));
}
// Enums must be bound as VARCHAR.
if (value instanceof Enum) {
Enum<?> enumValue = (Enum<?>) value;
return Optional.of(STR_BUILDER.build(enumValue.name()));
}
if (value instanceof Optional) {
Object nestedValue = ((Optional<?>) value).orElse(null);
Type nestedType = findOptionalType(expectedType, nestedValue);
return config.get(Arguments.class).findFor(nestedType, nestedValue);
}
return value == null ? Optional.of(config.get(Arguments.class).getUntypedNullArgument()) : Optional.empty();
}
use of org.jdbi.v3.core.config.ConfigRegistry in project jdbi by jdbi.
the class SqlArrayArgumentFactory method build.
@Override
public Optional<Argument> build(Type type, Object value, ConfigRegistry config) {
Class<?> erasedType = GenericTypes.getErasedType(type);
if (!(erasedType.isArray() || Collection.class.isAssignableFrom(erasedType))) {
return Optional.empty();
}
if (value == null) {
return Optional.of(new NullArgument(Types.ARRAY));
}
Function<Type, Optional<SqlArrayType<?>>> lookup = eT -> config.get(SqlArrayTypes.class).findFor(eT);
if (erasedType.isArray()) {
Class<?> elementType = erasedType.getComponentType();
return lookup.apply(elementType).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
return GenericTypes.findGenericParameter(type, Collection.class).flatMap(lookup).map(arrayType -> new SqlArrayArgument<>(arrayType, value));
}
Aggregations