package com.lunhan.xxx.common.orm2; import com.lunhan.xxx.common.ConstantFactory; import com.lunhan.xxx.common.util.CalendarUtil; import com.lunhan.xxx.common.util.NumericUtil; import java.math.BigDecimal; import java.sql.Types; import java.util.Date; /** * 处ç†sql 相关工具类 */ public final class SqlUtil { private SqlUtil() { throw new IllegalStateException("Utility class"); } /** * 获å–java类型对应的sqlæ•°æ®ç±»åž‹ * @param value 傿•°å€¼ */ public static Integer getParameterType(Object value) { Integer type = Types.VARCHAR; if (value instanceof Integer) { type = Types.INTEGER; } else if (value instanceof Long) { type = Types.BIGINT; } else if (value instanceof Float) { type = Types.DECIMAL; } else if (value instanceof Double) { type = Types.DECIMAL; } else if (value instanceof Boolean) { type = Types.BOOLEAN; } else if (value instanceof CalendarUtil) { type = Types.TIME; } else if (value instanceof Date) { type = Types.TIMESTAMP; } else if (value instanceof BigDecimal) { type = Types.DECIMAL; } return type; } /** * 构建inçš„whereæ¡ä»¶ * @param inQuantity inæ¡ä»¶ä¸ªæ•° */ public static String getListInWhereSql(Integer inQuantity) { if(NumericUtil.tryParseInt(inQuantity).compareTo(0)<1) { return " 1!=1"; } StringBuilder sbSql = new StringBuilder(); sbSql.append("("); for (int i=0; i<inQuantity; i++) { if(i>0) { sbSql.append(ConstantFactory.SQL_STR_COMMA); } sbSql.append("?"); } sbSql.append(")"); return sbSql.toString(); } }