de.zalando.sprocwrapper.proxy.GlobalValueTransformedParameter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zalando-sprocwrapper Show documentation
Show all versions of zalando-sprocwrapper Show documentation
Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces
including automatic object serialization and deserialization (using typemapper and
convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types
such as enums and hstore.
package de.zalando.sprocwrapper.proxy;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.sql.Connection;
import java.util.Collection;
import java.util.List;
import com.google.common.collect.Lists;
import de.zalando.sprocwrapper.globalvaluetransformer.ValueTransformerUtils;
import de.zalando.typemapper.core.ValueTransformer;
import de.zalando.typemapper.core.fieldMapper.ObjectMapper;
import de.zalando.typemapper.postgres.PgTypeHelper;
public class GlobalValueTransformedParameter extends StoredProcedureParameter {
private StoredProcedureParameter forwardingStoredProcedureParameter;
@SuppressWarnings("rawtypes")
private ValueTransformer valueTransformerForClass;
@SuppressWarnings("rawtypes")
private ObjectMapper globalObjectMapper;
public GlobalValueTransformedParameter(final ValueTransformer, ?> valueTransformerForClass, final Class> clazz,
final Type genericType, final Method m, final String typeName, final int sqlType, final int javaPosition,
final boolean sensitive, final ObjectMapper> globalObjectMapper) throws InstantiationException,
IllegalAccessException {
super(getValueTransformedClazz(clazz, valueTransformerForClass), m, typeName, getValueTransformedTypeId(clazz),
javaPosition, sensitive);
this.valueTransformerForClass = valueTransformerForClass;
this.globalObjectMapper = globalObjectMapper;
forwardingStoredProcedureParameter = StoredProcedureParameter.createParameter(getValueTransformedClazz(clazz,
valueTransformerForClass), getValueTransformedGenericClass(clazz), m,
getValueTransformedTypeName(clazz, valueTransformerForClass), getValueTransformedTypeId(clazz),
javaPosition, sensitive);
}
@Override
public Object mapParam(final Object value, final Connection connection) {
if (value == null) {
return forwardingStoredProcedureParameter.mapParam(value, connection);
}
if (forwardingStoredProcedureParameter instanceof ArrayStoredProcedureParameter) {
final List