📄 selectcommand.java
字号:
/* * $Id: SelectCommand.java,v 1.39 2003/07/01 13:42:23 rwald Exp $ * ======================================================================= * Copyright (c) 2002-2003 Axion Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above * copyright notice, this list of conditions and the following * disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "Tigris", "Axion", nor the names of its contributors may * not be used to endorse or promote products derived from this * software without specific prior written permission. * * 4. Products derived from this software may not be called "Axion", nor * may "Tigris" or "Axion" appear in their names without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ======================================================================= */package org.axiondb.engine.commands;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import org.apache.commons.collections.comparators.ComparatorChain;import org.axiondb.AxionException;import org.axiondb.ColumnIdentifier;import org.axiondb.ComparisonOperator;import org.axiondb.Database;import org.axiondb.FromNode;import org.axiondb.Index;import org.axiondb.LeafWhereNode;import org.axiondb.Literal;import org.axiondb.OrderNode;import org.axiondb.Row;import org.axiondb.RowComparator;import org.axiondb.RowDecorator;import org.axiondb.RowIterator;import org.axiondb.Selectable;import org.axiondb.Table;import org.axiondb.TableIdentifier;import org.axiondb.WhereNode;import org.axiondb.engine.ReferencesOtherTablesWhereNodeVisitor;import org.axiondb.engine.SimpleRow;import org.axiondb.engine.rowiterators.ChangingIndexedRowIterator;import org.axiondb.engine.rowiterators.DistinctRowIterator;import org.axiondb.engine.rowiterators.FilteringRowIterator;import org.axiondb.engine.rowiterators.IndexJoinedRowIterator;import org.axiondb.engine.rowiterators.LimitingRowIterator;import org.axiondb.engine.rowiterators.ListIteratorRowIterator;import org.axiondb.engine.rowiterators.RowIteratorRowDecoratorIterator;import org.axiondb.engine.rowiterators.SimpleJoinedRowIterator;import org.axiondb.engine.rowiterators.SingleRowIterator;import org.axiondb.functions.AggregateFunction;import org.axiondb.jdbc.AxionResultSet;/** * A <tt>SELECT</tt> query. * * @version $Revision: 1.39 $ $Date: 2003/07/01 13:42:23 $ * @author Morgan Delagrange * @author Rodney Waldhoff * @author Chuck Burdick * @author Amrish Lal */public class SelectCommand extends BaseAxionCommand { //------------------------------------------------------------ Constructors public SelectCommand() { } //-------------------------------------------------------------- Properties public void setSelect(List columns) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _select = columns; } /** * Adds a {@link Selectable} to the list of items being selected. * @param column the {@link Selectable} to add * @throws IllegalStateException if I have already been resolved */ public void addSelect(Selectable column) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _select.add(column); } /** * Gets the <i>i</i><sup>th</sup> {@link Selectable} being selected. * Clients should treat the returned value as immutable. * @param i the zero-based index */ public Selectable getSelect(int i) { return (Selectable)(_select.get(i)); } /** * Sets the <i>i</i><sup>th</sup> {@link Selectable} being selected. * @param i the zero-based index * @param sel the new {@link Selectable} * @throws IllegalStateException if I have already been resolved */ public void setSelect(int i, Selectable sel) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _select.set(i,sel); } /** * Gets the number of {@link Selectable}s being selected. */ public int getSelectCount() { return _select.size(); } /** * Sets the root {@link FromNode} for the select statement. */ public void setFrom(FromNode from) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _from = from; } /** * Adds a {@link TableIdentifier} to the list * of tables being selected from. * @param table a {@link TableIdentifier} * @throws IllegalStateException if I have already been resolved */ public void addFrom(TableIdentifier table) { if(_resolved) { throw new IllegalStateException("Already resolved."); } if (_from == null) { _from = new FromNode(); _from.setType(FromNode.TYPE_SINGLE); } if (_from.getLeft() == null) { _from.setLeft(table); } else if (_from.getRight() == null) { _from.setRight(table); _from.setType(FromNode.TYPE_INNER); } else { FromNode from = new FromNode(); from.setLeft(_from); from.setRight(table); from.setType(FromNode.TYPE_INNER); _from = from; } } /** * Gets the root {@link FromNode} for the select statement. */ public FromNode getFrom() { return _from; } /** * Gets the <i>i</i><sup>th</sup> table being selected. * Clients should treat the returned value as immutable. * @param i the zero-based index */ public TableIdentifier getFrom(int i) { TableIdentifier[] tableIDs = _from.toTableArray(); return (tableIDs[i]); } /** * Gets the number of tables being from. */ public int getFromCount() { return _from.getTableCount(); } /** * Sets the {@link WhereNode where tree} for this query. * @param where a {@link WhereNode} * @throws IllegalStateException if I have already been resolved */ public void setWhere(WhereNode where) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _where = where; } /** * Returns the {@link WhereNode where tree} for this query. * Clients should treat the returned value as immutable. * @return the {@link WhereNode where tree} for this query, or <tt>null</tt>. */ public WhereNode getWhere() { return _where; } /** * Sets the order by clause for this query. * @param orderby a {@link List} of {@link OrderNode}s. * @throws IllegalStateException if I have already been resolved */ public void setOrderBy(List orderby) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _orderBy = orderby; } /** * Appends an {@link OrderNode} to the order by clause for this query * @param orderby an {@link OrderNode} to append * @throws IllegalStateException if I have already been resolved */ public void addOrderBy(OrderNode orderby) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _orderBy.add(orderby); } /** * Gets the <i>i</i><sup>th</sup> {@link OrderNode} in my order by clause. * Clients should treat the returned value as immutable. * @param i the zero-based index */ public OrderNode getOrderBy(int i) { return (OrderNode)(_orderBy.get(i)); } /** * Gets the number of {@link OrderNode}s in my query. */ public int getOrderByCount() { return (null == _orderBy ? 0 : _orderBy.size()); } /** * Determines if the {@link java.sql.ResultSet} generated * from this object will contain distinct tuples (default is false). * @param distinct true for distinct tuples */ public void setDistinct(boolean distinct) { if(_resolved) { throw new IllegalStateException("Already resolved."); } _distinct = distinct; } /** * Indicates if the {@link java.sql.ResultSet} generated from * this object will contain distinct tuples. * @return <code>true</code> for distinct tuples */ public boolean getDistinct() { return _distinct; } public void setLimit(Literal limit) { _limit = limit; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -