All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.easy.query.mssql.func.MsSQLDateTimeDurationSQLFunction Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show 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.DateTimeDurationEnum;

import java.util.List;

/**
 * create time 2023/12/21 11:58
 * 文件说明
 *
 * @author xuejiaming
 */
public class MsSQLDateTimeDurationSQLFunction extends AbstractExpressionSQLFunction {
    private final List columnExpressions;
    private final DateTimeDurationEnum durationEnum;

    public MsSQLDateTimeDurationSQLFunction(List columnExpressions, DateTimeDurationEnum durationEnum) {

        this.columnExpressions = columnExpressions;
        this.durationEnum = durationEnum;
    }

    @Override
    public String sqlSegment(TableAvailable defaultTable) {
        if(columnExpressions.size()!=2){
            throw new IllegalArgumentException("date time duration sql arguments != 2");
        }
        switch (durationEnum){
            case Days:return "datediff(day, {1}, {0})";
            case Hours:return "datediff(hour, {1}, {0})";
            case Minutes:return "datediff(minute, {1}, {0})";
            case Seconds:return "datediff(second, {1}, {0})";
        }
        throw new UnsupportedOperationException("不支持当前属性获取:"+ durationEnum);
    }

    @Override
    public int paramMarks() {
        return columnExpressions.size();
    }

    @Override
    protected List getColumnExpressions() {
        return columnExpressions;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy