Search in sources :

Example 1 with OrderByClauseNode

use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.

the class SqlParser method parseOrderByWord.

protected void parseOrderByWord() {
    validate();
    OrderByClauseNode node = new OrderByClauseNode(token);
    if (isInSelectStatementNode()) {
        removeNodesTo(SelectStatementNode.class);
        SelectStatementNode selectStatementNode = peek();
        selectStatementNode.setOrderByClauseNode(node);
    } else {
        appendNode(node);
    }
    push(node);
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) OrderByClauseNode(org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode)

Example 2 with OrderByClauseNode

use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.

the class H2PagingTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
    OrderByClauseNode orderBy;
    if (originalOrderBy != null) {
        orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
        for (SqlNode child : originalOrderBy.getChildren()) {
            orderBy.appendNode(child);
        }
    } else {
        orderBy = new OrderByClauseNode("");
    }
    orderBy.appendNode(new FragmentNode(" limit "));
    if (limit > 0) {
        orderBy.appendNode(new FragmentNode(String.valueOf(limit)));
    } else {
        orderBy.appendNode(new FragmentNode("-1"));
    }
    if (offset >= 0) {
        orderBy.appendNode(new FragmentNode(" offset "));
        orderBy.appendNode(new FragmentNode(String.valueOf(offset)));
    }
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(node.getSelectClauseNode());
    result.setFromClauseNode(node.getFromClauseNode());
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(orderBy);
    result.setForUpdateClauseNode(node.getForUpdateClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) OrderByClauseNode(org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 3 with OrderByClauseNode

use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.

the class MssqlPagingTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    if (!forceOffsetFetch && offset <= 0) {
        return super.appendTopNode(node);
    }
    OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
    if (originalOrderBy == null) {
        throw new JdbcException(Message.DOMA2201);
    }
    OrderByClauseNode orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
    for (SqlNode child : originalOrderBy.getChildren()) {
        orderBy.appendNode(child);
    }
    String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
    orderBy.appendNode(new FragmentNode(" offset "));
    orderBy.appendNode(new FragmentNode(offset));
    orderBy.appendNode(new FragmentNode(" rows"));
    if (this.limit > 0) {
        orderBy.appendNode(new FragmentNode(" fetch next "));
        orderBy.appendNode(new FragmentNode(String.valueOf(this.limit)));
        orderBy.appendNode(new FragmentNode(" rows only"));
    }
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(node.getSelectClauseNode());
    result.setFromClauseNode(node.getFromClauseNode());
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(orderBy);
    result.setForUpdateClauseNode(node.getForUpdateClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) JdbcException(org.seasar.doma.jdbc.JdbcException) OrderByClauseNode(org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 4 with OrderByClauseNode

use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.

the class MysqlPagingTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
    OrderByClauseNode orderBy;
    if (originalOrderBy != null) {
        orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
        for (SqlNode child : originalOrderBy.getChildren()) {
            orderBy.appendNode(child);
        }
    } else {
        orderBy = new OrderByClauseNode("");
    }
    String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
    String limit = this.limit <= 0 ? MAXIMUM_LIMIT : String.valueOf(this.limit);
    orderBy.appendNode(new FragmentNode(" limit "));
    orderBy.appendNode(new FragmentNode(offset));
    orderBy.appendNode(new FragmentNode(", "));
    orderBy.appendNode(new FragmentNode(limit));
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(node.getSelectClauseNode());
    result.setFromClauseNode(node.getFromClauseNode());
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(orderBy);
    result.setForUpdateClauseNode(node.getForUpdateClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) OrderByClauseNode(org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 5 with OrderByClauseNode

use of org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode in project doma by domaframework.

the class SqlitePagingTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    OrderByClauseNode originalOrderBy = node.getOrderByClauseNode();
    OrderByClauseNode orderBy;
    if (originalOrderBy != null) {
        orderBy = new OrderByClauseNode(originalOrderBy.getWordNode());
        for (SqlNode child : originalOrderBy.getChildren()) {
            orderBy.appendNode(child);
        }
    } else {
        orderBy = new OrderByClauseNode("");
    }
    String offset = this.offset <= 0 ? "0" : String.valueOf(this.offset);
    String limit = this.limit <= 0 ? MAXIMUM_LIMIT : String.valueOf(this.limit);
    orderBy.appendNode(new FragmentNode(" limit "));
    orderBy.appendNode(new FragmentNode(limit));
    orderBy.appendNode(new FragmentNode(" offset "));
    orderBy.appendNode(new FragmentNode(offset));
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(node.getSelectClauseNode());
    result.setFromClauseNode(node.getFromClauseNode());
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(orderBy);
    result.setForUpdateClauseNode(node.getForUpdateClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) OrderByClauseNode(org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Aggregations

OrderByClauseNode (org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode)9 SelectStatementNode (org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode)9 FragmentNode (org.seasar.doma.internal.jdbc.sql.node.FragmentNode)8 SqlNode (org.seasar.doma.jdbc.SqlNode)8 JdbcException (org.seasar.doma.jdbc.JdbcException)1