gu.sql2java.utils.ColumnTransformer 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.utils;
import static com.google.common.base.Functions.compose;
import static com.google.common.base.Preconditions.checkNotNull;
import static gu.sql2java.Sql2javaSupport.TIMESTAMP_FORMATTER_STR;
import static gu.sql2java.Sql2javaSupport.formatDate;
import static gu.sql2java.Sql2javaSupport.getDateFromString;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import com.google.common.base.Function;
import com.google.common.primitives.Primitives;
/**
* @author guyadong
* @since 3.21.0
*/
public class ColumnTransformer extends BaseTypeTransformer {
private final Function number2ByteFun = new Function(){
@Override
public Byte apply(Number input) {
return null == input ? null : input.byteValue();
}};
private final Function number2ShortFun = new Function(){
@Override
public Short apply(Number input) {
return null == input ? null : input.shortValue();
}};
private final Function number2IntegerFun = new Function(){
@Override
public Integer apply(Number input) {
return null == input ? null : input.intValue();
}};
private final Function number2LongFun = new Function(){
@Override
public Long apply(Number input) {
return null == input ? null : input.longValue();
}};
private final Function number2FloatFun = new Function(){
@Override
public Float apply(Number input) {
return null == input ? null : input.floatValue();
}};
private final Function number2DoubleFun = new Function(){
@Override
public Double apply(Number input) {
return null == input ? null : input.doubleValue();
}};
private final Function number2BooleanFun = new Function(){
@Override
public Boolean apply(Number input) {
return null == input ? null : 0 != input.intValue();
}};
private final Function string2ByteFun = new Function(){
@Override
public Byte apply(String input) {
return null== input ? null : Byte.valueOf(input);
}};
private final Function string2ShortFun = new Function(){
@Override
public Short apply(String input) {
return null== input ? null : Short.valueOf(input);
}};
private final Function string2IntegerFun = new Function(){
@Override
public Integer apply(String input) {
return null== input ? null : Integer.valueOf(input);
}};
private final Function string2LongFun = new Function(){
@Override
public Long apply(String input) {
return null== input ? null : Long.valueOf(input);
}};
private final Function string2FloatFun = new Function(){
@Override
public Float apply(String input) {
return null== input ? null : Float.valueOf(input);
}};
private final Function string2DoubleFun = new Function(){
@Override
public Double apply(String input) {
return null== input ? null : Double.valueOf(input);
}};
private final Function string2BooleanFun = new Function(){
@Override
public Boolean apply(String input) {
return null== input ? null : Boolean.valueOf(input);
}};
private final Function boolean2ByteFun = new Function(){
@Override
public Byte apply(Boolean input) {
return null== input ? null : (byte) (input?1:0);
}};
private final Function boolean2ShortFun = new Function(){
@Override
public Short apply(Boolean input) {
return null== input ? null : Short.valueOf((byte)(input?1:0));
}};
private final Function boolean2IntegerFun = new Function(){
@Override
public Integer apply(Boolean input) {
return null== input ? null : Integer.valueOf(input?1:0);
}};
private final Function boolean2LongFun = new Function(){
@Override
public Long apply(Boolean input) {
return null== input ? null : Long.valueOf(input?1:0);
}};
private final Function boolean2FloatFun = new Function(){
@Override
public Float apply(Boolean input) {
return null== input ? null : Float.valueOf(input?1:0);
}};
private final Function boolean2DoubleFun = new Function(){
@Override
public Double apply(Boolean input) {
return null== input ? null : Double.valueOf(input?1:0);
}};
private final Function long2DateFun = new Function(){
@Override
public Date apply(Long input) {
return null== input ? null : new Date(input);
}};
private final Function long2SqlDateFun = new Function(){
@Override
public java.sql.Date apply(Long input) {
return null== input ? null : new java.sql.Date(input);
}};
private final Function long2SqlTimeFun = new Function(){
@Override
public java.sql.Time apply(Long input) {
return null== input ? null : new java.sql.Time(input);
}};
private final Function long2TimestampFun = new Function(){
@Override
public Timestamp apply(Long input) {
return null== input ? null : new Timestamp(input);
}};
private final Function date2LongFun = new Function(){
@Override
public Long apply(Date input) {
return null== input ? null : input.getTime();
}};
private final Function date2StringFun = new Function(){
@Override
public String apply(Date input) {
return null== input ? null : formatDate(input,TIMESTAMP_FORMATTER_STR);
}};
private final Function string2DateFun = new Function(){
@Override
public Date apply(String input) {
return null== input ? null : getDateFromString(input);
}};
private final Function string2SqlDateFun = new Function(){
@Override
public java.sql.Date apply(String input) {
return null== input ? null : new java.sql.Date(getDateFromString(input).getTime());
}};
private final Function string2SqlTimeFun = new Function(){
@Override
public java.sql.Time apply(String input) {
return null== input ? null : new java.sql.Time(getDateFromString(input).getTime());
}};
private final Function string2TimestampFun = new Function(){
@Override
public Timestamp apply(String input) {
return null== input ? null : new Timestamp(getDateFromString(input).getTime());
}};
private final Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy