private boolean shouldStopVisiting(TableNode tableNode) {

    if (inRecursiveRelation(tableNode)) {
      if (recursivelyVisited(tableNode)) return true;

    } else {
      if (ctx.tableAlreadyVisited(tableNode.getTable())) return true;
    }

    return false;
  }
  /*
   * Implements the relational tree traversal
   */
  public void visit(TableNode tableNode, boolean baseTable) {

    ctx.createTableContext(tableNode);

    if (baseTable) ctx.setBaseTable(tableNode.getTable());

    if (baseTable) onVisitBaseTable(tableNode);
    else {
      onVisitRelatedTable(tableNode);
    }

    if (inRecursiveRelation(tableNode)) {
      ctx.setVisitedRecursion(tableNode.getTable());
      if (ctx.isInLazyQuery()) ctx.setVisitedTable(tableNode.getTable(), tableNode);
    }

    // Add
    if (shouldStopVisiting(tableNode)) return;
    ctx.setVisitedTable(tableNode.getTable(), tableNode);

    for (RelationNode relationNode : tableNode.getChildren()) {
      if (eligibleForVisitation(relationNode, tableNode)) {
        //				relationNode.setRelContextManager(ctx); //pass the context to the node
        Fetching relationFecthing = getFetchingForRelationNode(relationNode);
        if (fetching == null
            || fetching.equals(relationFecthing)
            || allowedForVisitation(relationNode)) {
          if (traversedLazyRelation(
              relationFecthing,
              relationNode)) // stop if we reached the tableNode by traversing a relation with lazy
            // fetching
            continue;
          for (TableNode childTableNode : relationNode.getChildren()) {
            visit(childTableNode, false);
          }
          onVisitedTableRelation(relationNode);
        }
      }
    }
  }
 private boolean recursivelyVisited(TableNode tableNode) {
   return ctx.recursionAlreadyVisited(tableNode.getTable());
 }