package com.smtservlet.mybatis; import java.util.Date; import com.smtservlet.util.SMTStatic; import com.smtservlet.util.SMTStatic.SMTCalcTime; public class SMTMybatisXmlMethod { public static String convSqlLike(String type, String value) { if(value == null) return null; if(type.equalsIgnoreCase("mssql")) { value = value .replace("[", "[[]") .replace("%", "[%]") .replace("_", "[_]") .replace("^", "[^]"); } return "%" + value + "%"; } public static String convFieldName(String type, String name) throws Exception { if(type.equalsIgnoreCase("mssql")) { return String.format("[%s]", name); } else if(type.equalsIgnoreCase("oracle")) { return String.format("\"%s\"", name); } else if(type.equalsIgnoreCase("mysql")) { return String.format("\"%s\"", name); } else throw new Exception("unsupport database for getLinkStr : " + type); } public static String getLinkStrBlock(String type, String mode) throws Exception { if(type.equalsIgnoreCase("mssql")) { if("M".equalsIgnoreCase(mode)) return "+"; else return ""; } else if(type.equalsIgnoreCase("oracle")) { if("M".equalsIgnoreCase(mode)) return "||"; else return ""; } else if(type.equalsIgnoreCase("mysql")) { if("S".equalsIgnoreCase(mode)) return "CONCAT("; if("M".equalsIgnoreCase(mode)) return ","; if("E".equalsIgnoreCase(mode)) return ")"; else return ""; } else throw new Exception("unsupport database for getLinkStr : " + type); } public static String getLinkStr(String type) throws Exception { if(type.equalsIgnoreCase("mssql")) { return "+"; } else if(type.equalsIgnoreCase("oracle")) { return "||"; } else throw new Exception("unsupport database for getLinkStr : " + type); } public static Date addDate(String type, Date date, int days) { if(date == null) return null; return SMTStatic.calculateTime(date, SMTCalcTime.ADD_DATE, days); } public static Date clearDateTime(String type, Date date) { return SMTStatic.calculateTime(date, SMTCalcTime.ZERO_TIME, 0); } }