gu.sql2java.BaseTypeColumnCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-base Show documentation
Show all versions of sql2java-base Show documentation
sql2java common class package
package gu.sql2java;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URL;
import java.nio.ByteBuffer;
import java.sql.Blob;
import java.sql.Clob;
import java.util.Date;
import com.google.common.base.Function;
import com.google.common.primitives.Primitives;
import gu.sql2java.exception.ResultSetCodecException;
import gu.sql2java.exception.UnsupportTypeException;
import gu.sql2java.utils.ColumnTransformer;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* 基本数据类型(Number,Boolean,Date,byte[],ByteBuffer)编解码实现
* @author guyadong
* @since 3.21.0
*
*/
public class BaseTypeColumnCodec extends BaseColumnCodec {
public static final BaseTypeColumnCodec BASE_CODEC = new BaseTypeColumnCodec();
private final ColumnTransformer transformer = new ColumnTransformer();
public BaseTypeColumnCodec() {
}
@SuppressWarnings("unchecked")
@Override
protected T doDeserialize(Object columnValue, Class targetType) throws ResultSetCodecException {
return (T) transformer(columnValue, targetType);
}
@SuppressWarnings("unchecked")
@Override
protected T doDeserialize(Object columnValue, Type targetType) throws ResultSetCodecException {
if(!(targetType instanceof Class>)) {
throw new UnsupportTypeException("UNSUPPORTED type of targetType " + targetType);
}
return (T) doDeserialize(columnValue,(Class>)targetType);
}
@SuppressWarnings("unchecked")
@Override
protected T doSerialize(Object obj, Class targetType) throws ResultSetCodecException {
return (T) transformer(obj,targetType);
}
@SuppressWarnings("unchecked")
protected Object transformer(Object input, Class> targetType) throws ResultSetCodecException {
try {
Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy