Search in sources :

Example 1 with FragmentNode

use of org.seasar.doma.internal.jdbc.sql.node.FragmentNode 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 2 with FragmentNode

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

the class Mssql2008ForUpdateTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    StringBuilder buf = new StringBuilder(100).append("with (updlock, rowlock");
    if (forUpdateType == SelectForUpdateType.NOWAIT) {
        buf.append(", nowait");
    }
    buf.append(") ");
    FromClauseNode originalFrom = node.getFromClauseNode();
    FromClauseNode from = new FromClauseNode(originalFrom.getWordNode());
    for (SqlNode child : originalFrom.getChildren()) {
        from.appendNode(child);
    }
    from.appendNode(new FragmentNode(buf.toString()));
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(node.getSelectClauseNode());
    result.setFromClauseNode(from);
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(node.getOrderByClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : FromClauseNode(org.seasar.doma.internal.jdbc.sql.node.FromClauseNode) SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 3 with FragmentNode

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

the class Mssql2008PagingTransformer method appendTopNode.

protected SqlNode appendTopNode(SelectStatementNode node) {
    SelectClauseNode select = new SelectClauseNode(node.getSelectClauseNode().getWordNode());
    select.appendNode(new FragmentNode(" top (" + limit + ")"));
    for (SqlNode child : node.getSelectClauseNode().getChildren()) {
        select.appendNode(child);
    }
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(select);
    result.setFromClauseNode(node.getFromClauseNode());
    result.setWhereClauseNode(node.getWhereClauseNode());
    result.setGroupByClauseNode(node.getGroupByClauseNode());
    result.setHavingClauseNode(node.getHavingClauseNode());
    result.setOrderByClauseNode(node.getOrderByClauseNode());
    result.setForUpdateClauseNode(node.getForUpdateClauseNode());
    result.setOptionClauseNode(node.getOptionClauseNode());
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) SelectClauseNode(org.seasar.doma.internal.jdbc.sql.node.SelectClauseNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode) SqlNode(org.seasar.doma.jdbc.SqlNode)

Example 4 with FragmentNode

use of org.seasar.doma.internal.jdbc.sql.node.FragmentNode 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 5 with FragmentNode

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

the class MysqlCountGettingTransformer method visitSelectStatementNode.

@Override
public SqlNode visitSelectStatementNode(SelectStatementNode node, Void p) {
    if (processed) {
        return node;
    }
    processed = true;
    SelectClauseNode select = new SelectClauseNode("select");
    select.appendNode(new FragmentNode(" found_rows()"));
    SelectStatementNode result = new SelectStatementNode();
    result.setSelectClauseNode(select);
    return result;
}
Also used : SelectStatementNode(org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode) SelectClauseNode(org.seasar.doma.internal.jdbc.sql.node.SelectClauseNode) FragmentNode(org.seasar.doma.internal.jdbc.sql.node.FragmentNode)

Aggregations

FragmentNode (org.seasar.doma.internal.jdbc.sql.node.FragmentNode)16 SelectStatementNode (org.seasar.doma.internal.jdbc.sql.node.SelectStatementNode)16 SqlNode (org.seasar.doma.jdbc.SqlNode)11 OrderByClauseNode (org.seasar.doma.internal.jdbc.sql.node.OrderByClauseNode)8 SelectClauseNode (org.seasar.doma.internal.jdbc.sql.node.SelectClauseNode)5 FromClauseNode (org.seasar.doma.internal.jdbc.sql.node.FromClauseNode)3 ForUpdateClauseNode (org.seasar.doma.internal.jdbc.sql.node.ForUpdateClauseNode)2 WhereClauseNode (org.seasar.doma.internal.jdbc.sql.node.WhereClauseNode)1 JdbcException (org.seasar.doma.jdbc.JdbcException)1