com.easy.query.mssql.func.MsSQLDateTimePropertySQLFunction Maven / Gradle / Ivy
The newest version!
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.DateTimeUnitEnum;
import com.easy.query.core.util.EasyCollectionUtil;
import java.util.List;
/**
* create time 2023/12/21 11:58
* 文件说明
*
* @author xuejiaming
*/
public class MsSQLDateTimePropertySQLFunction extends AbstractExpressionSQLFunction {
private final List columnExpressions;
private final DateTimeUnitEnum dateTimeUnitEnum;
public MsSQLDateTimePropertySQLFunction(List columnExpressions, DateTimeUnitEnum dateTimeUnitEnum) {
this.columnExpressions = columnExpressions;
this.dateTimeUnitEnum = dateTimeUnitEnum;
}
@Override
public String sqlSegment(TableAvailable defaultTable) {
if(EasyCollectionUtil.isEmpty(columnExpressions)){
throw new IllegalArgumentException("columnExpressions is empty");
}
switch (dateTimeUnitEnum){
case DayOfYear:return "datepart(dayofyear, {0})";
case DayOfWeek:return "(datepart(weekday, {0})-1)";
case Year:return "datepart(year, {0})";
case Month:return "datepart(month, {0})";
case Day:return "datepart(day, {0})";
case Hour:return "datepart(hour, {0})";
case Minute:return "datepart(minute, {0})";
case Second:return "datepart(second, {0})";
}
throw new UnsupportedOperationException("不支持当前属性获取:"+ dateTimeUnitEnum);
}
@Override
public int paramMarks() {
return columnExpressions.size();
}
@Override
protected List getColumnExpressions() {
return columnExpressions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy