com.easy.query.mssql.func.MsSQLDateTime2PlusSQLFunction Maven / Gradle / Ivy
package com.easy.query.mssql.func;
import com.easy.query.core.expression.parser.core.available.TableAvailable;
import com.easy.query.core.func.column.ColumnExpression;
import com.easy.query.core.func.def.AbstractExpressionSQLFunction;
import com.easy.query.core.func.def.enums.TimeUnitEnum;
import java.util.List;
/**
* create time 2023/12/21 11:58
* 文件说明
*
* @author xuejiaming
*/
public class MsSQLDateTime2PlusSQLFunction extends AbstractExpressionSQLFunction {
private final List columnExpressions;
private final TimeUnitEnum timeUnit;
public MsSQLDateTime2PlusSQLFunction(List columnExpressions, TimeUnitEnum timeUnit) {
this.columnExpressions = columnExpressions;
this.timeUnit = timeUnit;
}
@Override
public String sqlSegment(TableAvailable defaultTable) {
if (columnExpressions.size() != 2) {
throw new IllegalArgumentException("columnExpressions.size() != 2");
}
switch (timeUnit){
case MILLISECONDS: return "dateadd(second, ({1})/1000, {0})";
case SECONDS: return "dateadd(second, {1}, {0})";
case MINUTES: return "dateadd(minute, {1}, {0})";
case HOURS: return "dateadd(hour, {1}, {0})";
case DAYS: return "dateadd(day, {1}, {0})";
case MONTHS: return "dateadd(month, {1}, {0})";
case YEARS: return "dateadd(year, {1}, {0})";
}
throw new UnsupportedOperationException("not support current function MsSQLDateTime2PlusSQLFunction:"+ timeUnit);
}
@Override
public int paramMarks() {
return columnExpressions.size();
}
@Override
protected List getColumnExpressions() {
return columnExpressions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy