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

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

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

import java.util.List;

import com.jpattern.orm.classtool.NullOrmClassToolMap;
import com.jpattern.orm.exception.OrmException;

/**
 * 
 * @author Francesco Cina
 *
 * 08/lug/2011
 */
public abstract class ABaseOrmQuery extends AQuery implements IBaseOrmQuery {

	/**
	 * 
	 */
	
	private IExpression whereExpression = new Expression();
	private OrderBy orderBy = new OrderBy();
	private IJoin join = new Join(new NullOrmClassToolMap());

	@Override
	public final IJoin join() throws OrmException {
		return join;
	}

	@Override
	public final IExpression where() throws OrmException {
		return whereExpression;
	}

	@Override
	public final IOrderBy orderBy() throws OrmException {
		return orderBy;
	}

	protected final void setWhere(IExpression whereExpression) {
		this.whereExpression = whereExpression;
	}

	protected final void setOrderBy(OrderBy orderBy) {
		this.orderBy = orderBy;
	}

	protected final void setJoin(IJoin join) {
		this.join = join;
	}
	
	@Override
	public final String renderSql() {
		StringBuilder stringBuilder = new StringBuilder();
		renderSql(stringBuilder);
		return stringBuilder.toString();
	}
	
	@Override
	public final void renderSql(StringBuilder stringBuilder) {
		renderSelect(stringBuilder);
		renderFrom(stringBuilder);
		renderWhere(stringBuilder);
		renderOrderBy(stringBuilder);
		renderLockMode(stringBuilder);
	}

	protected abstract void renderOrderBy(StringBuilder stringBuilder);

	protected abstract void renderWhere(StringBuilder stringBuilder);

	protected abstract void renderFrom(StringBuilder stringBuilder);

	protected abstract void renderSelect(StringBuilder stringBuilder);
	
	protected abstract void renderLockMode(StringBuilder stringBuilder);

	@Override
	public final void appendValues(List values) {
		where().appendValues(values);
	}
}