private int getPositionAndPathsToConnectSubTree(final boolean relatedNodeIsParent,
                                                    int position,
                                                    final ExplorerTreeNode parent,
                                                    final ExplorerTreeNode sibling,
                                                    final List<ExplorerTreePath> pathsToClone) {
        assert pathsToClone != null && pathsToClone.size() <= 0;

        assert !relatedNodeIsParent || parent != null;

        if (relatedNodeIsParent) {
            pathsToClone.addAll(JooqUtil.contextResult(explorerDbConnProvider, context ->
                            context
                                    .selectFrom(p)
                                    .where(p.DESCENDANT.eq(parent.getId()))
                                    .fetch())
                    .map(ExplorerTreeDaoImpl::mapExplorerPathRecord));
        } else if (sibling != null) {
            pathsToClone.addAll(JooqUtil.contextResult(explorerDbConnProvider, context ->
                            context
                                    .selectFrom(p)
                                    .where(p.DESCENDANT.eq(parent.getId()))
                                    .and(p.DEPTH.gt(0))
                                    .orderBy(p.DEPTH)
                                    .fetch())
                    .map(ExplorerTreeDaoImpl::mapExplorerPathRecord));

            if (pathsToClone.size() <= 0) {
                throw new IllegalArgumentException("Sibling seems not to be a child but a root: " + sibling);
            }

            position = pathsToClone.get(0).getOrderIndex();

            assert position >= 0 : "Position of first path is not valid: " + pathsToClone;
        }

        return position;
    }
Get the root node containing a particular node, or the node itself if it is a root node.
stroom-explorer/stroom-explorer-impl-db/src/main/java/stroom/explorer/impl/db/ExplorerTreeDaoImpl.java