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

db.sql.api.impl.cmd.struct.query.OrderBy Maven / Gradle / Ivy

There is a newer version: 1.7.6-RC2
Show newest version
package db.sql.api.impl.cmd.struct.query;

import db.sql.api.Cmd;
import db.sql.api.SqlBuilderContext;
import db.sql.api.cmd.basic.IOrderByDirection;
import db.sql.api.cmd.struct.query.IOrderBy;
import db.sql.api.impl.tookit.SqlConst;
import db.sql.api.tookit.CmdUtils;

import java.util.ArrayList;
import java.util.List;

public class OrderBy implements IOrderBy {

    private final List orderByValues = new ArrayList<>(2);

    @Override
    public OrderBy orderBy(IOrderByDirection orderByDirection, Cmd column) {
        orderByValues.add(new OrderByValue(orderByDirection, column));
        return this;
    }

    public List getOrderByField() {
        return orderByValues;
    }

    @Override
    public StringBuilder sql(Cmd module, Cmd parent, SqlBuilderContext context, StringBuilder sqlBuilder) {
        if (this.orderByValues.isEmpty()) {
            return sqlBuilder;
        }
        sqlBuilder.append(SqlConst.ORDER_BY);
        CmdUtils.join(this, this, context, sqlBuilder, this.orderByValues, SqlConst.DELIMITER);
        return sqlBuilder;
    }

    @Override
    public boolean contain(Cmd cmd) {
        return CmdUtils.contain(cmd, this.orderByValues);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy