package foundation.util;
|
|
import java.text.DateFormat;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
import foundation.server.config.DBaseType;
|
|
public class DBDate {
|
|
private Date date;
|
private boolean includeTime;
|
|
|
public DBDate() {
|
date = new Date();
|
includeTime = false;
|
}
|
|
public DBDate(Date date) {
|
this.date = date;
|
includeTime = false;
|
}
|
|
public DBDate(Date date, boolean includeTime) {
|
this.date = date;
|
this.includeTime = includeTime;
|
}
|
|
public String toSqlString(DBaseType type) {
|
if (date == null) {
|
return "null";
|
}
|
|
String result = null;
|
String formatter = this.includeTime ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd";
|
DateFormat dateFormat = new SimpleDateFormat(formatter);
|
String value = dateFormat.format(this.date);
|
|
if (type.isOracle()) {
|
result = "to_date('" + value + "','YYYY-MM-DD')";
|
}
|
else if (type.isSQLServer()) {
|
result = "'" + value + "'";
|
}
|
else if (type.isMySQL()) {
|
result = "'" + value + "'";
|
}
|
else {
|
result = "'" + value + "'";
|
}
|
|
return result;
|
}
|
|
public static String getDayAddFunciton(DBaseType dbType) {
|
if (dbType.isOracle()) {
|
return "ADD_DAYS";
|
}
|
else if (dbType.isMySQL()) {
|
return "ADDDATE";
|
}
|
else if (dbType.isSQLServer()) {
|
return "DATE_ADD";
|
}
|
|
return "ADD_DAYS";
|
}
|
|
public static String getCurrentTimeFunciton(DBaseType dbType) {
|
if (dbType.isOracle()) {
|
return "SYSDATE";
|
}
|
else if (dbType.isMySQL()) {
|
return "now()";
|
}
|
else if (dbType.isSQLServer()) {
|
return "GETDATE()";
|
}
|
|
return "SYSDATE";
|
}
|
|
public static String getCurrentDateFunciton(DBaseType dbType) {
|
if (dbType.isOracle()) {
|
return "SYSDATE";
|
}
|
else if (dbType.isMySQL()) {
|
return "now()";
|
}
|
else if (dbType.isSQLServer()) {
|
return "GETDATE()";
|
}
|
|
return "SYSDATE";
|
}
|
|
}
|