
org.hibernate.sql.Template Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate Show documentation
Show all versions of hibernate Show documentation
Relational Persistence for Java
//$Id: Template.java 9922 2006-05-10 16:58:09Z [email protected] $
package org.hibernate.sql;
import java.util.HashSet;
import java.util.StringTokenizer;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunctionRegistry;
import org.hibernate.util.StringHelper;
/**
* Parses SQL fragments specified in mapping documents
*
* @author Gavin King
*/
public final class Template {
private static final java.util.Set KEYWORDS = new HashSet();
private static final java.util.Set BEFORE_TABLE_KEYWORDS = new HashSet();
private static final java.util.Set FUNCTION_KEYWORDS = new HashSet();
static {
KEYWORDS.add("and");
KEYWORDS.add("or");
KEYWORDS.add("not");
KEYWORDS.add("like");
KEYWORDS.add("is");
KEYWORDS.add("in");
KEYWORDS.add("between");
KEYWORDS.add("null");
KEYWORDS.add("select");
KEYWORDS.add("distinct");
KEYWORDS.add("from");
KEYWORDS.add("join");
KEYWORDS.add("inner");
KEYWORDS.add("outer");
KEYWORDS.add("left");
KEYWORDS.add("right");
KEYWORDS.add("on");
KEYWORDS.add("where");
KEYWORDS.add("having");
KEYWORDS.add("group");
KEYWORDS.add("order");
KEYWORDS.add("by");
KEYWORDS.add("desc");
KEYWORDS.add("asc");
KEYWORDS.add("limit");
KEYWORDS.add("any");
KEYWORDS.add("some");
KEYWORDS.add("exists");
KEYWORDS.add("all");
BEFORE_TABLE_KEYWORDS.add("from");
BEFORE_TABLE_KEYWORDS.add("join");
FUNCTION_KEYWORDS.add("as");
FUNCTION_KEYWORDS.add("leading");
FUNCTION_KEYWORDS.add("trailing");
FUNCTION_KEYWORDS.add("from");
FUNCTION_KEYWORDS.add("case");
FUNCTION_KEYWORDS.add("when");
FUNCTION_KEYWORDS.add("then");
FUNCTION_KEYWORDS.add("else");
FUNCTION_KEYWORDS.add("end");
}
public static final String TEMPLATE = "$PlaceHolder$";
private Template() {}
public static String renderWhereStringTemplate(String sqlWhereString, Dialect dialect, SQLFunctionRegistry functionRegistry) {
return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect, functionRegistry);
}
/**
* Same functionality as {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)},
* except that a SQLFunctionRegistry is not provided (i.e., only the dialect-defined functions are
* considered). This is only intended for use by the annotations project until the
* many-to-many/map-key-from-target-table feature is pulled into core.
*
* @deprecated Only intended for annotations usage; use {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)} instead
*/
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) {
return renderWhereStringTemplate( sqlWhereString, placeholder, dialect, new SQLFunctionRegistry( dialect, java.util.Collections.EMPTY_MAP ) );
}
/**
* Takes the where condition provided in the mapping attribute and interpolates the alias.
* Handles subselects, quoted identifiers, quoted strings, expressions, SQL functions,
* named parameters.
*
* @param sqlWhereString The string into which to interpolate the placeholder value
* @param placeholder The value to be interpolated into the the sqlWhereString
* @param dialect The dialect to apply
* @param functionRegistry The registry of all sql functions
* @return The rendered sql fragment
*/
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect, SQLFunctionRegistry functionRegistry ) {
//TODO: make this a bit nicer
String symbols = new StringBuffer()
.append("=>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy