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