Java Code Examples for org.hibernate.dialect.function.SQLFunctionRegistry

The following examples show how to use org.hibernate.dialect.function.SQLFunctionRegistry. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * The map of defined filters.  This is expected to be in format
 * where the filter names are the map keys, and the defined
 * conditions are the values.
 *
 * @param filters The map of defined filters.
 * @param dialect The sql dialect
 * @param functionRegistry The SQL function registry
 */
public FilterHelper(Map filters, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	int filterCount = filters.size();
	filterNames = new String[filterCount];
	filterConditions = new String[filterCount];
	Iterator iter = filters.entrySet().iterator();
	filterCount = 0;
	while ( iter.hasNext() ) {
		final Map.Entry entry = (Map.Entry) iter.next();
		filterNames[filterCount] = (String) entry.getKey();
		filterConditions[filterCount] = Template.renderWhereStringTemplate(
				(String) entry.getValue(),
				FilterImpl.MARKER,
				dialect,
				functionRegistry
			);
		filterConditions[filterCount] = StringHelper.replace( filterConditions[filterCount],
				":",
				":" + filterNames[filterCount] + "." );
		filterCount++;
	}
}
 
Example 2
Source Project: lams   Source File: Column.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return hasCustomRead()
			// see note in renderTransformerReadFragment wrt access to SessionFactory
			? Template.renderTransformerReadFragment( customRead, getQuotedName( dialect ) )
			: Template.TEMPLATE + '.' + getQuotedName( dialect );
}
 
Example 3
Source Project: lams   Source File: RowCountProjection.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected SQLFunction getFunction(CriteriaQuery criteriaQuery) {
	final SQLFunctionRegistry sqlFunctionRegistry = criteriaQuery.getFactory().getSqlFunctionRegistry();
	final SQLFunction function = sqlFunctionRegistry.findSQLFunction( "count" );
	if ( function == null ) {
		throw new HibernateException( "Unable to locate count function mapping" );
	}
	return function;
}
 
Example 4
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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
 */
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) {
	return renderWhereStringTemplate(
			sqlWhereString,
			placeholder,
			dialect,
			new SQLFunctionRegistry( dialect, java.util.Collections.<String, SQLFunction>emptyMap() )
	);
}
 
Example 5
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs order-by template rendering without {@link ColumnMapper column mapping}.  An <tt>ORDER BY</tt> template
 * has all column references "qualified" with a placeholder identified by {@link Template#TEMPLATE}
 *
 * @param orderByFragment The order-by fragment to render.
 * @param dialect The SQL dialect being used.
 * @param functionRegistry The SQL function registry
 *
 * @return The rendered <tt>ORDER BY</tt> template.
 *
 * @deprecated Use {@link #translateOrderBy} instead
 */
@Deprecated
public static String renderOrderByStringTemplate(
		String orderByFragment,
		Dialect dialect,
		SQLFunctionRegistry functionRegistry) {
	return renderOrderByStringTemplate(
			orderByFragment,
			NoOpColumnMapper.INSTANCE,
			null,
			dialect,
			functionRegistry
	);
}
 
Example 6
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static String renderOrderByStringTemplate(
		String orderByFragment,
		final ColumnMapper columnMapper,
		final SessionFactoryImplementor sessionFactory,
		final Dialect dialect,
		final SQLFunctionRegistry functionRegistry) {
	return translateOrderBy(
			orderByFragment,
			columnMapper,
			sessionFactory,
			dialect,
			functionRegistry
	).injectAliases( LEGACY_ORDER_BY_ALIAS_RESOLVER );
}
 
Example 7
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Performs order-by template rendering allowing {@link ColumnMapper column mapping}.  An <tt>ORDER BY</tt> template
 * has all column references "qualified" with a placeholder identified by {@link Template#TEMPLATE} which can later
 * be used to easily inject the SQL alias.
 *
 * @param orderByFragment The order-by fragment to render.
 * @param columnMapper The column mapping strategy to use.
 * @param sessionFactory The session factory.
 * @param dialect The SQL dialect being used.
 * @param functionRegistry The SQL function registry
 *
 * @return The rendered <tt>ORDER BY</tt> template.
 */
public static OrderByTranslation translateOrderBy(
		String orderByFragment,
		final ColumnMapper columnMapper,
		final SessionFactoryImplementor sessionFactory,
		final Dialect dialect,
		final SQLFunctionRegistry functionRegistry) {
	TranslationContext context = new TranslationContext() {
		public SessionFactoryImplementor getSessionFactory() {
			return sessionFactory;
		}

		public Dialect getDialect() {
			return dialect;
		}

		public SQLFunctionRegistry getSqlFunctionRegistry() {
			return functionRegistry;
		}

		public ColumnMapper getColumnMapper() {
			return columnMapper;
		}
	};

	return OrderByFragmentTranslator.translate( context, orderByFragment );
}
 
Example 8
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean isFunctionOrKeyword(
		String lcToken,
		String nextToken,
		Dialect dialect,
		SQLFunctionRegistry functionRegistry) {
	return "(".equals( nextToken ) ||
			KEYWORDS.contains( lcToken ) ||
			isType( lcToken, dialect ) ||
			isFunction( lcToken, nextToken, functionRegistry ) ||
			dialect.getKeywords().contains( lcToken ) ||
			FUNCTION_KEYWORDS.contains( lcToken );
}
 
Example 9
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean isFunction(String lcToken, String nextToken, SQLFunctionRegistry functionRegistry) {
	// checking for "(" is currently redundant because it is checked before getting here;
	// doing the check anyhow, in case that earlier check goes away;
	if ( "(".equals( nextToken ) ) {
		return true;
	}
	SQLFunction function = functionRegistry.findSQLFunction(lcToken);
	if ( function == null ) {
		// lcToken does not refer to a function
		return false;
	}
	// if function.hasParenthesesIfNoArguments() is true, then assume
	// lcToken is not a function (since it is not followed by '(')
	return ! function.hasParenthesesIfNoArguments();
}
 
Example 10
private static boolean isFunctionOrKeyword(String lcToken, String nextToken, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return "(".equals(nextToken) ||
		KEYWORDS.contains(lcToken) ||
		functionRegistry.hasFunction(lcToken) ||
		dialect.getKeywords().contains(lcToken) ||
		FUNCTION_KEYWORDS.contains(lcToken);
}
 
Example 11
Source Project: lams   Source File: Formula.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
	String template = Template.renderWhereStringTemplate(formula, dialect, functionRegistry);
	return StringHelper.replace( template, "{alias}", Template.TEMPLATE );
}
 
Example 12
@Override
public SQLFunctionRegistry getSqlFunctionRegistry() {
	return delegate.getSqlFunctionRegistry();
}
 
Example 13
Source Project: lams   Source File: SessionFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
public SQLFunctionRegistry getSqlFunctionRegistry() {
	return sqlFunctionRegistry;
}
 
Example 14
Source Project: lams   Source File: Template.java    License: GNU General Public License v2.0 4 votes vote down vote up
public static String renderWhereStringTemplate(String sqlWhereString, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect, functionRegistry);
}
 
Example 15
Source Project: cacheonix-core   Source File: Column.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return getQuotedName(dialect);
}
 
Example 16
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return Template.renderWhereStringTemplate(formula, dialect, functionRegistry);
}
 
Example 17
public static String renderWhereStringTemplate(String sqlWhereString, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	return renderWhereStringTemplate(sqlWhereString, TEMPLATE, dialect, functionRegistry);
}
 
Example 18
/**
 * Takes order by clause provided in the mapping attribute and interpolates the alias.
 * Handles asc, desc, SQL functions, quoted identifiers.
 */
public static String renderOrderByStringTemplate(String sqlOrderByString, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	//TODO: make this a bit nicer
	String symbols = new StringBuffer()
		.append("=><!+-*/()',|&`")
		.append(StringHelper.WHITESPACE)
		.append( dialect.openQuote() )
		.append( dialect.closeQuote() )
		.toString();
	StringTokenizer tokens = new StringTokenizer(sqlOrderByString, symbols, true);
	
	StringBuffer result = new StringBuffer();
	boolean quoted = false;
	boolean quotedIdentifier = false;
	
	boolean hasMore = tokens.hasMoreTokens();
	String nextToken = hasMore ? tokens.nextToken() : null;
	while (hasMore) {
		String token = nextToken;
		String lcToken = token.toLowerCase();
		hasMore = tokens.hasMoreTokens();
		nextToken = hasMore ? tokens.nextToken() : null;
		
		boolean isQuoteCharacter = false;
		
		if ( !quotedIdentifier && "'".equals(token) ) {
			quoted = !quoted;
			isQuoteCharacter = true;
		}
		
		if ( !quoted ) {
			
			boolean isOpenQuote;
			if ( "`".equals(token) ) {
				isOpenQuote = !quotedIdentifier;
				token = lcToken = isOpenQuote ? 
					new Character( dialect.openQuote() ).toString() :
					new Character( dialect.closeQuote() ).toString();
				quotedIdentifier = isOpenQuote;	
				isQuoteCharacter = true;
			}
			else if ( !quotedIdentifier && ( dialect.openQuote()==token.charAt(0) ) ) {
				isOpenQuote = true;
				quotedIdentifier = true;	
				isQuoteCharacter = true;
			}
			else if ( quotedIdentifier && ( dialect.closeQuote()==token.charAt(0) ) ) {
				quotedIdentifier = false;
				isQuoteCharacter = true;
				isOpenQuote = false;
			}
			else {
				isOpenQuote = false;
			}
			
			if (isOpenQuote) {
				result.append(TEMPLATE).append('.');
			}
			
		}

		boolean quotedOrWhitespace = quoted || 
			quotedIdentifier || 
			isQuoteCharacter || 
			Character.isWhitespace( token.charAt(0) );
		
		if (quotedOrWhitespace) {
			result.append(token);
		}
		else if (
			isIdentifier(token, dialect) &&
			!isFunctionOrKeyword(lcToken, nextToken, dialect, functionRegistry)
		) {
			result.append(TEMPLATE)
				.append('.')
				.append( dialect.quote(token) );
		}
		else {
			result.append(token);
		}
	}
	return result.toString();
}
 
Example 19
public SQLFunctionRegistry getSqlFunctionRegistry() {
	return sqlFunctionRegistry;
}
 
Example 20
Source Project: lemon   Source File: SessionFactoryWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public SQLFunctionRegistry getSqlFunctionRegistry() {
    return sessionFactoryImplementor.getSqlFunctionRegistry();
}
 
Example 21
Source Project: lams   Source File: TranslationContext.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Retrieves the <tt>SQL function registry/tt> for this context.
 *
 * @return The SQL function registry.
 */
public SQLFunctionRegistry getSqlFunctionRegistry();
 
Example 22
/**
 * 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 ) );
}
 
Example 23
Source Project: lams   Source File: Selectable.java    License: GNU General Public License v2.0 votes vote down vote up
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry); 
Example 24
SQLFunctionRegistry getSqlFunctionRegistry(); 
Example 25
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry); 
Example 26
public SQLFunctionRegistry getSqlFunctionRegistry();