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

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

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

import java.util.List;

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

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

	/**
	 * 
	 */
	
	private final BaseFindQuery query;
	private INameSolver nameSolver;
	private final String property;
	private final boolean in;

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

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

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

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

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

}