All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.teiid.query.sql.lang.From Maven / Gradle / Ivy

/*
 * Copyright Red Hat, Inc. and/or its affiliates
 * and other contributors as indicated by the @author tags and
 * the COPYRIGHT.txt file distributed with this work.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.teiid.query.sql.lang;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.visitor.SQLStringVisitor;


/**
 * Represents a FROM clause in a SELECT query.  The from clause holds a set of 
 * FROM subclauses.  Each FROM subclause can be either a single group 
 * ({@link UnaryFromClause}) or a join predicate ({@link JoinPredicate}).
 */
public class From implements LanguageObject {

    private List clauses;

    /**
     * Constructs a default instance of this class.
     */
    public From() {
    	clauses = new ArrayList();
    }

    /**
     * Constructs an instance of this class from an ordered set of from clauses
     * @param parameters The ordered list of from clauses
     */
    public From( List parameters ) {
        clauses = new ArrayList( parameters );
    }

    // =========================================================================
    //                             M E T H O D S
    // =========================================================================
	
	/**
	 * Add a clause to the FROM
	 * @param clause Add a clause to the FROM
	 */
	public void addClause(FromClause clause) {
		this.clauses.add(clause);
	}
	
	/**
	 * Add clauses to the FROM 
	 * @param clauses Collection of {@link FromClause}s
	 */
	public void addClauses(Collection toAdd) {
		this.clauses.addAll(toAdd);
	}
	
	/** 
	 * Get all the clauses in FROM
	 * @return List of {@link FromClause}
	 */
	public List getClauses() {
		return this.clauses;
	}
    
	/** 
	 * Set all the clauses
	 * @param clauses List of {@link FromClause}
	 */
	public void setClauses(List clauses) {
		this.clauses = clauses;
	}
	
	
    /**
     * Adds a new group to the list (it will be wrapped in a UnaryFromClause)
     * @param group Group to add
     */
    public void addGroup( GroupSymbol group ) {
    	if( group != null ) {
			clauses.add(new UnaryFromClause(group));
        }
    }   

    /**
     * Adds a new collection of groups to the list
     * @param groups Collection of {@link GroupSymbol}
     */
    public void addGroups( Collection groups ) {
    	if(groups != null) {
    		for (GroupSymbol groupSymbol : groups) {
				clauses.add(new UnaryFromClause(groupSymbol));
			}
        }
    }

    /**
     * Returns an ordered list of the groups in all sub-clauses.
     * @return List of {@link GroupSymbol}
     */
    public List getGroups() {
        List groups = new ArrayList();
        if(clauses != null) {
            for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy