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

com.jpattern.orm.query.AQuery Maven / Gradle / Ivy

There is a newer version: 3.5.1
Show newest version
package com.jpattern.orm.query;

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

/**
 * 
 * @author Francesco Cina'
 *
 * Dec 20, 2011
 */
public abstract class AQuery implements BaseFindQuery {

	@Override
	public final int hashCode() {
		final int prime = 31;
		int result = 1;
		List values =  new ArrayList();
		appendValues(values);
		String sql = renderSql();
		result = prime * result + ((values == null) ? 0 : values.hashCode());
		result = prime * result + getMaxRows();
		result = prime * result + ((sql == null) ? 0 : sql.hashCode());
		return result;
	}

	@Override
	public final boolean equals(Object obj) {
		List list =  new ArrayList();
		appendValues(list);
		String sql = renderSql();
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof AQuery)) {
			return false;
		}
		AQuery other = (AQuery) obj;
		if (getMaxRows() != other.getMaxRows()) {
			return false;
		}
		if (!sql.equals(other.renderSql())) {
			return false;
		}
		List otherlist =  new ArrayList();
		other.appendValues(otherlist);
		if (!list.equals(otherlist)) {
			return false;
		}
		return true;
	}
	
}