All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.hibernate.query.criteria.internal.expression.function.LocateFunction Maven / Gradle / Ivy
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.query.criteria.internal.expression.function;
import java.io.Serializable;
import javax.persistence.criteria.Expression;
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.ParameterRegistry;
import org.hibernate.query.criteria.internal.Renderable;
import org.hibernate.query.criteria.internal.compile.RenderingContext;
import org.hibernate.query.criteria.internal.expression.LiteralExpression;
/**
* Models the ANSI SQL LOCATE function.
*
* @author Steve Ebersole
*/
public class LocateFunction
extends BasicFunctionExpression
implements Serializable {
public static final String NAME = "locate";
private final Expression pattern;
private final Expression string;
private final Expression start;
public LocateFunction(
CriteriaBuilderImpl criteriaBuilder,
Expression pattern,
Expression string,
Expression start) {
super( criteriaBuilder, Integer.class, NAME );
this.pattern = pattern;
this.string = string;
this.start = start;
}
public LocateFunction(
CriteriaBuilderImpl criteriaBuilder,
Expression pattern,
Expression string) {
this( criteriaBuilder, pattern, string, null );
}
public LocateFunction(CriteriaBuilderImpl criteriaBuilder, String pattern, Expression string) {
this(
criteriaBuilder,
new LiteralExpression( criteriaBuilder, pattern ),
string,
null
);
}
public LocateFunction(CriteriaBuilderImpl criteriaBuilder, String pattern, Expression string, int start) {
this(
criteriaBuilder,
new LiteralExpression( criteriaBuilder, pattern ),
string,
new LiteralExpression( criteriaBuilder, start )
);
}
public Expression getPattern() {
return pattern;
}
public Expression getStart() {
return start;
}
public Expression getString() {
return string;
}
@Override
public void registerParameters(ParameterRegistry registry) {
Helper.possibleParameter( getPattern(), registry );
Helper.possibleParameter( getStart(), registry );
Helper.possibleParameter( getString(), registry );
}
@Override
public String render(RenderingContext renderingContext) {
renderingContext.getFunctionStack().push( this );
try {
final StringBuilder buffer = new StringBuilder();
buffer.append( "locate(" )
.append( ( (Renderable) getPattern() ).render( renderingContext ) )
.append( ',' )
.append( ( (Renderable) getString() ).render( renderingContext ) );
if ( getStart() != null ) {
buffer.append( ',' )
.append( ( (Renderable) getStart() ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();
}
finally {
renderingContext.getFunctionStack().pop();
}
}
}