package ws.prova.sql;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</a>
 * Copyright (C) 1998-2002 <a href="mailto:jens.dietrich@unforgettable.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.kernel.Predicate;
import org.mandarax.sql.SQLPredicate;

/**
 * Extended predicate for SQL SELECT queries
 * <p>Title: Prova</p>
 * <p>Description: Extended predicate for SQL SELECT queries</p>
 * <p>Copyright: Copyright (C) 2002-2007</p>
 * <p>Company: City University, London, United Kingdom</p>
 *
 * @author Alex Kozlenkov
 * @version 2.0 <25 March 2007>
 */
public class SQLExtendedPredicate extends SQLPredicate {
	/**
	 * Indicates whether the object (usually a term or a clause set) can be performed
	 * using the java semantics.
	 *
	 * @return false
	 */
	public boolean isExecutable() {
		return false;
	}

	/**
	 * Compare objects.
	 *
	 * @param obj Object another object
	 * @return boolean
	 */
	public boolean equals(Object obj) {
		if ((obj != null) && (obj instanceof Predicate)) {
			Predicate p = (Predicate) obj;
			boolean result = true;

			// compare name
			result = (getName() == null) ? (p.getName() == null) : getName().equals(p.getName());

			Class[] c1 = p.getStructure();
			Class[] c2 = getStructure();

			if (c1 == null) {
				result = c2 == null;
			} else {
				result = result && (c1.length == c2.length);

				for (int i = 0; i < c1.length; i++) {
					result = result && (c1[i] == c2[i]);
				}
			}

			return result;
		} else {
			return false;
		}
	}

}
