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

com.jpattern.orm.query.clause.where.InSubQueryExpressionElement Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
package com.jpattern.orm.query.clause.where;

import java.util.List;

import com.jpattern.orm.query.BaseFindQuery;
import com.jpattern.orm.query.NameSolver;

/**
 * 
 * @author Francesco Cina
 *
 * 26/giu/2011
 */
public class InSubQueryExpressionElement implements ExpressionElement {

	private final BaseFindQuery query;
	private NameSolver nameSolver;
	private final String property;
	private final boolean in;

	public InSubQueryExpressionElement(final String property, final BaseFindQuery query, final boolean in) {
		this.property = property;
		this.query = query;
		this.in = in;
	}

	@Override
	public String renderSqlElement() {
		StringBuilder StringBuilder = new StringBuilder();
		renderSqlElement(StringBuilder);
		return StringBuilder.toString();
	}

	@Override
	public void renderSqlElement(final StringBuilder StringBuilder) {
		StringBuilder.append(  this.nameSolver.solvePropertyName( this.property ) );
		if (this.in) {
			StringBuilder.append( " IN ( ");
		} else {
			StringBuilder.append( " NOT IN ( ");
		}
		this.query.renderSql(StringBuilder);
		StringBuilder.append(") ");
	}

	@Override
	public void setNameSolver(final NameSolver nameSolver) {
		this.nameSolver = nameSolver;
	}

	@Override
	public final void appendElementValues(final List values) {
		this.query.appendValues(values);
	}

}