com.easy.query.mssql.func.MsSQLDateTimePlusSQLFunction 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.column.impl.ColumnFuncValueExpressionImpl;
import com.easy.query.core.func.def.AbstractExpressionSQLFunction;
import com.easy.query.core.util.EasyCollectionUtil;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* create time 2023/12/21 11:58
* 文件说明
*
* @author xuejiaming
*/
public class MsSQLDateTimePlusSQLFunction extends AbstractExpressionSQLFunction {
private final List columnExpressions;
private final long duration;
private final TimeUnit timeUnit;
public MsSQLDateTimePlusSQLFunction(List columnExpressions, long duration, TimeUnit timeUnit) {
this.columnExpressions = columnExpressions;
this.duration = duration;
this.timeUnit = timeUnit;
}
@Override
public String sqlSegment(TableAvailable defaultTable) {
if(EasyCollectionUtil.isEmpty(columnExpressions)){
throw new IllegalArgumentException("columnExpressions is empty");
}
ColumnExpression columnExpression = columnExpressions.get(0);
columnExpressions.clear();
columnExpressions.add(columnExpression);
long millis = timeUnit.toMillis(duration);
columnExpressions.add(new ColumnFuncValueExpressionImpl(millis));
return "dateadd(second, ({1})/1000, {0})";
}
@Override
public int paramMarks() {
return columnExpressions.size();
}
@Override
protected List getColumnExpressions() {
return columnExpressions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy