001: /*
002: * $Id: MaskSelectablesForTablesVisitor.java,v 1.2 2005/12/20 18:32:27 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.engine.visitors;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045:
046: import org.axiondb.ColumnIdentifier;
047: import org.axiondb.FromNode;
048: import org.axiondb.Function;
049: import org.axiondb.Selectable;
050: import org.axiondb.TableIdentifier;
051:
052: /**
053: * Masks Selectables For given Tables, used to mask seletable while resolving condition in
054: * FromNode scope.
055: *
056: * @author Ahimanikya Satapathy
057: */
058: public class MaskSelectablesForTablesVisitor {
059:
060: public List maskAliasListForTables(FromNode from, List selected) {
061: if (selected == null) {
062: return null;
063: }
064:
065: List aliasList = new ArrayList();
066: TableIdentifier[] tables = from.toTableArray();
067: for (int i = 0, I = selected.size(); i < I; i++) {
068: Selectable sel = (Selectable) selected.get(i);
069: if (visit(sel, tables)) {
070: aliasList.add(sel);
071: }
072: }
073: return aliasList;
074: }
075:
076: public boolean visit(ColumnIdentifier col, TableIdentifier[] tables) {
077: for (int i = 0; i < tables.length; i++) {
078: if (!"*".equals(col.getName())
079: && col.getTableName().equals(
080: tables[i].getTableName())) {
081: return true;
082: }
083: }
084: return false;
085: }
086:
087: public boolean visit(Function fn, TableIdentifier[] tables) {
088: for (int i = 0, I = fn.getArgumentCount(); i < I; i++) {
089: if (!visit(fn.getArgument(i), tables)) {
090: return false;
091: }
092: }
093: return true;
094: }
095:
096: public boolean visit(Selectable sel, TableIdentifier[] tables) {
097: if (sel instanceof ColumnIdentifier) {
098: if (!visit((ColumnIdentifier) sel, tables)) {
099: return false;
100: }
101: }
102: if (sel instanceof Function) {
103: if (!visit((Function) sel, tables)) {
104: return false;
105: }
106: }
107: return true;
108: }
109: }
|