ComplexTerm1.java :  » Rule-Engine » Mandarax » org » mandarax » jdbc » server » sql » Java Open Source

Java Open Source » Rule Engine » Mandarax 
Mandarax » org » mandarax » jdbc » server » sql » ComplexTerm1.java
package org.mandarax.jdbc.server.sql;

/*
 * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import org.mandarax.jdbc.server.parser.ParseException;
 
/**
 * Class for complex column terms using functions with one parameter
 * (in particular, aggregation functions).
 * @see Functions
 * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
 * @version 3.3.2 <29 December 2004>
 * @since 3.0
 */
public class ComplexTerm1 extends ColumnTerm implements ColumnTermContext , Functions {
  private Function function = null;
  private ColumnTerm colTerm = null; 
  /**
   * Add a condition to this context.
   * @param colTerm a column term
   */
  public void add(ColumnTerm colTerm) throws ParseException {
    if (this.function.isAggregationFunction() && !(colTerm instanceof ColumnTerm)) throw new ParseException("Column term expected as argument by aggregation function " + function);
    this.colTerm = colTerm;
    colTerm.setOwner(this);
  }
  /**
   * Set the function.
   * @param function a function
   */
  public void setFunction(Function function) {
    this.function = function;
  }
  /**
   * Gather the host variables.
   * @param variables the list used to collect the variables
   */
   public void prepare(java.util.List variables) {
     if (colTerm!=null) colTerm.prepare(variables);
   }
  /**
   * Compares objects. 
   * @param obj another object.
   * @return a boolean
   */
  public boolean sameAs(Object obj) {
    if (obj instanceof ComplexTerm1) {
      ComplexTerm1 ct1 = (ComplexTerm1)obj;
      return function==ct1.function && colTerm.sameAs(ct1.colTerm);
    }
    return false;
  }
  /**
   * Get the associated variable name.
   * @return a variable name
   */
  public String asVariableName() {
    StringBuffer buf = new StringBuffer() ;
    function.print(buf,new ColumnTerm[]{colTerm});
    return buf.toString();
  }
  /**
   * Get the function.
   * @return the function
   */
  Function getFunction() {
    return function;
  }

  /**
   * Get the column term.
   * @return ColumnTerm
   */
  ColumnTerm getColTerm() {
    return colTerm;
  }
  /**
   * Print the object on a buffer in order to display the parsed SQL.
   * @param out a string bufer to print on
   */
  public void print(StringBuffer out) {
    function.print(out,new ColumnTerm[]{colTerm});
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.