Search in sources :

Example 1 with SelectItemVisitor

use of net.sf.jsqlparser.statement.select.SelectItemVisitor in project spanner-jdbc by olavloite.

the class CloudSpannerResultSetMetaData method initColumns.

private void initColumns(Select select) {
    columns = new ArrayList<>();
    aliases = new ArrayList<>();
    select.getSelectBody().accept(new SelectVisitorAdapter() {

        @Override
        public void visit(PlainSelect plainSelect) {
            for (SelectItem selectItem : plainSelect.getSelectItems()) {
                selectItem.accept(new SelectItemVisitor() {

                    private boolean foundColumn = false;

                    @Override
                    public void visit(SelectExpressionItem selectExpressionItem) {
                        selectExpressionItem.getExpression().accept(new ExpressionVisitorAdapter() {

                            @Override
                            public void visit(Column column) {
                                registerColumn(column, selectExpressionItem.getAlias());
                                foundColumn = true;
                            }
                        });
                        if (!foundColumn) {
                            registerColumn(null, selectExpressionItem.getAlias());
                        }
                    }

                    @Override
                    public void visit(AllTableColumns allTableColumns) {
                        registerAllTableColumns(allTableColumns.getTable());
                    }

                    @Override
                    public void visit(AllColumns allColumns) {
                        for (Table table : tables) {
                            registerAllTableColumns(table);
                        }
                    }
                });
            }
        }
    });
}
Also used : SelectVisitorAdapter(net.sf.jsqlparser.statement.select.SelectVisitorAdapter) Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) SelectItem(net.sf.jsqlparser.statement.select.SelectItem) AllTableColumns(net.sf.jsqlparser.statement.select.AllTableColumns) SelectExpressionItem(net.sf.jsqlparser.statement.select.SelectExpressionItem) PlainSelect(net.sf.jsqlparser.statement.select.PlainSelect) ExpressionVisitorAdapter(net.sf.jsqlparser.expression.ExpressionVisitorAdapter) SelectItemVisitor(net.sf.jsqlparser.statement.select.SelectItemVisitor) AllColumns(net.sf.jsqlparser.statement.select.AllColumns)

Aggregations

ExpressionVisitorAdapter (net.sf.jsqlparser.expression.ExpressionVisitorAdapter)1 Column (net.sf.jsqlparser.schema.Column)1 Table (net.sf.jsqlparser.schema.Table)1 AllColumns (net.sf.jsqlparser.statement.select.AllColumns)1 AllTableColumns (net.sf.jsqlparser.statement.select.AllTableColumns)1 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)1 SelectExpressionItem (net.sf.jsqlparser.statement.select.SelectExpressionItem)1 SelectItem (net.sf.jsqlparser.statement.select.SelectItem)1 SelectItemVisitor (net.sf.jsqlparser.statement.select.SelectItemVisitor)1 SelectVisitorAdapter (net.sf.jsqlparser.statement.select.SelectVisitorAdapter)1