org.ibatis.persist.impl.expression.CoalesceExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbatis Show documentation
Show all versions of jbatis Show documentation
The jBATIS persistence framework will help you to significantly reduce the amount of Java code that you normally need to access a relational database. iBATIS simply maps JavaBeans to SQL statements using a very simple XML descriptor.
The newest version!
package org.ibatis.persist.impl.expression;
import java.util.ArrayList;
import java.util.List;
import org.ibatis.persist.criteria.CriteriaBuilder.Coalesce;
import org.ibatis.persist.criteria.Expression;
import org.ibatis.persist.impl.CriteriaBuilderImpl;
import org.ibatis.persist.impl.Renderable;
import org.ibatis.persist.impl.RenderingContext;
/**
* Models an ANSI SQL COALESCE expression. COALESCE is a specialized CASE statement.
*/
@SuppressWarnings("unchecked")
public class CoalesceExpression extends ExpressionImpl implements Coalesce {
private final List> expressions;
private Class javaType;
public CoalesceExpression(CriteriaBuilderImpl criteriaBuilder) {
this( criteriaBuilder, null );
}
public CoalesceExpression(
CriteriaBuilderImpl criteriaBuilder,
Class javaType) {
super( criteriaBuilder, javaType );
this.javaType = javaType;
this.expressions = new ArrayList>();
}
@Override
public Class getJavaType() {
return javaType;
}
public Coalesce value(T value) {
return value( new LiteralExpression( criteriaBuilder(), value ) );
}
public Coalesce value(Expression extends T> value) {
expressions.add( value );
if ( javaType == null ) {
javaType = (Class) value.getJavaType();
}
return this;
}
public List> getExpressions() {
return expressions;
}
public void render(RenderingContext rc) {
rc.append("coalesce(");
String sep = "";
for (Expression expression : getExpressions()) {
rc.append(sep);
((Renderable) expression).render(rc);
sep = ", ";
}
rc.append(")");
}
public void renderProjection(RenderingContext rc) {
render(rc);
if (getAlias() != null) {
rc.append(" AS ").append(getAlias());
}
}
}