Search in sources :

Example 1 with TopNode

use of org.apache.cayenne.access.sqlbuilder.sqltree.TopNode in project cayenne by apache.

the class SybaseSQLTreeProcessor method onLimitOffsetNode.

@Override
protected void onLimitOffsetNode(Node parent, LimitOffsetNode child, int index) {
    // SQLServer uses "SELECT DISTINCT TOP N" or "SELECT TOP N" instead of LIMIT
    // Offset will be calculated in-memory
    replaceChild(parent, index, new EmptyNode(), false);
    if (child.getLimit() > 0) {
        int limit = child.getLimit() + child.getOffset();
        // we have root actually as input for processor, but it's better to keep processor stateless
        // root shouldn't be far from limit's parent (likely it will be parent itself)
        Node root = getRoot(parent);
        int idx = 0;
        if (root.getChild(0).getType() == NodeType.DISTINCT) {
            idx = 1;
        }
        root.addChild(idx, new TopNode(limit));
    }
}
Also used : EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode) TopNode(org.apache.cayenne.access.sqlbuilder.sqltree.TopNode) TextNode(org.apache.cayenne.access.sqlbuilder.sqltree.TextNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) TopNode(org.apache.cayenne.access.sqlbuilder.sqltree.TopNode) EmptyNode(org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)

Aggregations

EmptyNode (org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)1 FunctionNode (org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode)1 LimitOffsetNode (org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode)1 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)1 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)1 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)1 TopNode (org.apache.cayenne.access.sqlbuilder.sqltree.TopNode)1