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);
}
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());
}
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));
}
}
Aggregations