Пример #1
0
  /**
   * @param selectItems
   * @return <code>null</code> if <code>selectItems</code> is null or contains only an {@link
   *     net.sf.jsqlparser.statement.select.AllColumns}
   */
  private static String[] getColumns(ISession session, List selectItems) throws IOException {
    if (selectItems == null || selectItems.size() == 0) {
      return null;
    }

    SelectItem item;
    List colNames = new ArrayList(selectItems.size());
    for (Iterator it = selectItems.iterator(); it.hasNext(); ) {
      item = (SelectItem) it.next();
      if (item instanceof AllColumns) {
        continue;
      } else if (item instanceof AllTableColumns) {
        AllTableColumns allTableCols = (AllTableColumns) item;
        Table table = allTableCols.getTable();
        List tableColNames = getTableColumns(session, table);
        colNames.addAll(tableColNames);
      } else if (item instanceof SelectExpressionItem) {
        String stringItem = item.toString();
        colNames.add(stringItem);
      } else {
        throw new RuntimeException("unknown select item type: " + item);
      }
    }

    String[] columns = (String[]) colNames.toArray(new String[colNames.size()]);
    return columns;
  }
Пример #2
0
  @Override
  public void visit(PlainSelect plainSelect) {
    log.debug("visit(PlainSelect) " + plainSelect);
    enterPlainSelect(plainSelect);

    this.visitingPart = VisitingPart.SELECT_ITEM;
    List<SelectItem> selectItems = plainSelect.getSelectItems();
    if (selectItems != null) for (SelectItem s : selectItems) s.accept(this.expressionNavigator);

    log.debug("visit(PlainSelect) done");
    leavePlainSelect();
  }
Пример #3
0
 @Override
 public void visit(PlainSelect plainSelect) {
   firstRun = true;
   counter = 0;
   aliases.clear();
   for (SelectItem item : plainSelect.getSelectItems()) {
     item.accept(this);
   }
   firstRun = false;
   for (SelectItem item : plainSelect.getSelectItems()) {
     item.accept(this);
   }
 }
 @SuppressWarnings("unchecked")
 @Override
 public void visit(PlainSelect select) {
   if (!CollectionUtils.isEmpty(select.getGroupByColumnReferences())
       || !CollectionUtils.isEmpty(select.getJoins())) {
     isSimple = false;
   } else {
     select.getFromItem().accept(this);
     for (SelectItem item : (List<SelectItem>) select.getSelectItems()) {
       item.accept(this);
     }
   }
 }
Пример #5
0
 @Override
 public void visit(WithItem withItem) throws Exception {
   // TODO: Redo this later. What's withItem list.
   // Add with name here.
   if (withItem.getName() != null) {
     this.withTableNameList.add(withItem.getName());
   }
   withItem.getSelectBody().accept(this);
   if (withItem.getWithItemList() != null) {
     for (SelectItem selectItem : withItem.getWithItemList()) {
       selectItem.accept(this);
     }
   }
 }
Пример #6
0
  /** @brief The following functions override functions of the interfaces. */
  public void visit(PlainSelect plainSelect) throws Exception {
    if (plainSelect.getFromItem() != null) {
      if (plainSelect.getFromItem().getAlias() != null) {
        this.aliasTableNameList.add(plainSelect.getFromItem().getAlias().getName());
      }
      plainSelect.getFromItem().accept(this);
    }

    if (plainSelect.getJoins() != null) {
      for (Iterator joinsIt = plainSelect.getJoins().iterator(); joinsIt.hasNext(); ) {
        Join join = (Join) joinsIt.next();
        if (join.getRightItem().getAlias() != null) {
          this.aliasTableNameList.add(join.getRightItem().getAlias().getName());
        }
        if (join.getOnExpression() != null) {
          join.getOnExpression().accept(this);
        }
        join.getRightItem().accept(this);
      }
    }

    // Select selectItem From fromItem, joinItem Where whereClause.
    if (plainSelect.getSelectItems() != null) {
      for (SelectItem selectItem : plainSelect.getSelectItems()) {
        selectItem.accept(this);
      }
    }

    if (plainSelect.getWhere() != null) {
      plainSelect.getWhere().accept(this);
    }

    if (plainSelect.getGroupByColumnReferences() != null) {
      for (Iterator groupByIt = plainSelect.getGroupByColumnReferences().iterator();
          groupByIt.hasNext(); ) {
        Expression groupBy = (Expression) groupByIt.next();
        groupBy.accept(this);
      }
    }

    if (plainSelect.getClusterByElements() != null) {
      for (Iterator clusterByit = plainSelect.getClusterByElements().iterator();
          clusterByit.hasNext(); ) {
        ClusterByElement clusterByElement = (ClusterByElement) clusterByit.next();
        visit(clusterByElement);
      }
    }

    if (plainSelect.getDistributeByElements() != null) {
      for (Iterator distributeByIt = plainSelect.getDistributeByElements().iterator();
          distributeByIt.hasNext(); ) {
        DistributeByElement distributeByElement = (DistributeByElement) distributeByIt.next();
        visit(distributeByElement);
      }
    }

    if (plainSelect.getOrderByElements() != null) {
      for (Iterator orderByIt = plainSelect.getOrderByElements().iterator();
          orderByIt.hasNext(); ) {
        OrderByElement orderByElement = (OrderByElement) orderByIt.next();
        orderByElement.accept(this);
      }
    }

    if (plainSelect.getSortByElements() != null) {
      for (Iterator sortByIt = plainSelect.getSortByElements().iterator(); sortByIt.hasNext(); ) {
        SortByElement sortByElement = (SortByElement) sortByIt.next();
        visit(sortByElement);
      }
    }

    if (plainSelect.getHaving() != null) {
      plainSelect.getHaving().accept(this);
    }
  }