org.ibatis.persist.impl.predicate.LikePredicate 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.predicate;
import org.ibatis.persist.criteria.Expression;
import org.ibatis.persist.impl.CriteriaBuilderImpl;
import org.ibatis.persist.impl.Renderable;
import org.ibatis.persist.impl.RenderingContext;
import org.ibatis.persist.impl.expression.LiteralExpression;
/**
* Models a SQL LIKE expression.
*/
public class LikePredicate extends AbstractSimplePredicate {
private final Expression matchExpression;
private final Expression pattern;
private final Expression escapeCharacter;
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
Expression pattern) {
this( criteriaBuilder, matchExpression, pattern, null );
}
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
String pattern) {
this( criteriaBuilder, matchExpression, new LiteralExpression( criteriaBuilder, pattern) );
}
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
Expression pattern,
Expression escapeCharacter) {
super( criteriaBuilder );
this.matchExpression = matchExpression;
this.pattern = pattern;
this.escapeCharacter = escapeCharacter;
}
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
Expression pattern,
char escapeCharacter) {
this(
criteriaBuilder,
matchExpression,
pattern,
new LiteralExpression( criteriaBuilder, escapeCharacter )
);
}
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
String pattern,
char escapeCharacter) {
this(
criteriaBuilder,
matchExpression,
new LiteralExpression( criteriaBuilder, pattern ),
new LiteralExpression( criteriaBuilder, escapeCharacter )
);
}
public LikePredicate(
CriteriaBuilderImpl criteriaBuilder,
Expression matchExpression,
String pattern,
Expression escapeCharacter) {
this(
criteriaBuilder,
matchExpression,
new LiteralExpression( criteriaBuilder, pattern ),
escapeCharacter
);
}
public Expression getEscapeCharacter() {
return escapeCharacter;
}
public Expression getMatchExpression() {
return matchExpression;
}
public Expression getPattern() {
return pattern;
}
@Override
public void render(boolean isNegated, RenderingContext rc) {
final String operator = isNegated ? " not like " : " like ";
((Renderable) getMatchExpression()).render(rc);
rc.append(operator);
((Renderable) getPattern()).render(rc);
if (escapeCharacter != null) {
rc.append(" escape ");
((Renderable) getEscapeCharacter()).render(rc);
}
}
}