Search in sources :

Example 1 with LimitOffsetNode

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

the class DB2SQLTreeProcessor method onLimitOffsetNode.

@Override
protected void onLimitOffsetNode(Node parent, LimitOffsetNode child, int index) {
    Node replacement = new MysqlLimitOffsetNode(child.getLimit(), child.getOffset());
    replaceChild(parent, index, replacement, false);
}
Also used : ValueNode(org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode) MysqlLimitOffsetNode(org.apache.cayenne.dba.mysql.sqltree.MysqlLimitOffsetNode) ColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) OpExpressionNode(org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode) FunctionNode(org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) DerbyValueNode(org.apache.cayenne.dba.derby.sqltree.DerbyValueNode) TrimmingColumnNode(org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode) MysqlLimitOffsetNode(org.apache.cayenne.dba.mysql.sqltree.MysqlLimitOffsetNode)

Example 2 with LimitOffsetNode

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

the class LimitOffsetStageTest method perform.

@Test
public void perform() {
    LimitOffsetStage stage = new LimitOffsetStage();
    stage.perform(context);
    Node select = context.getSelectBuilder().build();
    Node child = select.getChild(0);
    assertThat(child, instanceOf(LimitOffsetNode.class));
    LimitOffsetNode limitOffsetNode = (LimitOffsetNode) child;
    assertEquals(123, limitOffsetNode.getLimit());
    assertEquals(321, limitOffsetNode.getOffset());
}
Also used : LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) Node(org.apache.cayenne.access.sqlbuilder.sqltree.Node) LimitOffsetNode(org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode) Test(org.junit.Test)

Example 3 with LimitOffsetNode

use of org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode 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

LimitOffsetNode (org.apache.cayenne.access.sqlbuilder.sqltree.LimitOffsetNode)3 Node (org.apache.cayenne.access.sqlbuilder.sqltree.Node)3 FunctionNode (org.apache.cayenne.access.sqlbuilder.sqltree.FunctionNode)2 OpExpressionNode (org.apache.cayenne.access.sqlbuilder.sqltree.OpExpressionNode)2 ColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.ColumnNode)1 EmptyNode (org.apache.cayenne.access.sqlbuilder.sqltree.EmptyNode)1 TextNode (org.apache.cayenne.access.sqlbuilder.sqltree.TextNode)1 TopNode (org.apache.cayenne.access.sqlbuilder.sqltree.TopNode)1 TrimmingColumnNode (org.apache.cayenne.access.sqlbuilder.sqltree.TrimmingColumnNode)1 ValueNode (org.apache.cayenne.access.sqlbuilder.sqltree.ValueNode)1 DerbyValueNode (org.apache.cayenne.dba.derby.sqltree.DerbyValueNode)1 MysqlLimitOffsetNode (org.apache.cayenne.dba.mysql.sqltree.MysqlLimitOffsetNode)1 Test (org.junit.Test)1