Java Code Examples for org.hibernate.dialect.Dialect.openQuote()

The following are Jave code examples for showing how to use openQuote() of the org.hibernate.dialect.Dialect class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: Table.java   View Source Code Vote up 4 votes
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 2
Project: lams   File: Table.java   View Source Code Vote up 4 votes
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 3
Project: lams   File: Table.java   View Source Code Vote up 4 votes
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 4
Project: lams   File: Column.java   View Source Code Vote up 4 votes
public String getQuotedName(Dialect d) {
	return quoted ?
		d.openQuote() + name + d.closeQuote() :
		name;
}
 
Example 5
Project: lams   File: QueryParameters.java   View Source Code Vote up 4 votes
@SuppressWarnings( {"unchecked"})
public void processFilters(String sql, Map filters, SessionFactoryImplementor factory) {
	if ( filters.size() == 0 || !sql.contains( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
		// HELLA IMPORTANT OPTIMIZATION!!!
		processedPositionalParameterValues = getPositionalParameterValues();
		processedPositionalParameterTypes = getPositionalParameterTypes();
		processedSQL = sql;
	}
	else {
		final Dialect dialect = factory.getDialect();
		final String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote();
		final StringTokenizer tokens = new StringTokenizer( sql, symbols, true );

		StringBuilder result = new StringBuilder();
		List parameters = new ArrayList();
		List parameterTypes = new ArrayList();

		int positionalIndex = 0;
		while ( tokens.hasMoreTokens() ) {
			final String token = tokens.nextToken();
			if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
				final String filterParameterName = token.substring( 1 );
				final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
				final FilterImpl filter = (FilterImpl) filters.get( parts[0] );
				final Object value = filter.getParameter( parts[1] );
				final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
				if ( value != null && Collection.class.isAssignableFrom( value.getClass() ) ) {
					Iterator itr = ( (Collection) value ).iterator();
					while ( itr.hasNext() ) {
						final Object elementValue = itr.next();
						result.append( '?' );
						parameters.add( elementValue );
						parameterTypes.add( type );
						if ( itr.hasNext() ) {
							result.append( ", " );
						}
					}
				}
				else {
					result.append( '?' );
					parameters.add( value );
					parameterTypes.add( type );
				}
			}
			else {
				if ( "?".equals( token ) && positionalIndex < getPositionalParameterValues().length ) {
					parameters.add( getPositionalParameterValues()[positionalIndex] );
					parameterTypes.add( getPositionalParameterTypes()[positionalIndex] );
					positionalIndex++;
				}
				result.append( token );
			}
		}
		processedPositionalParameterValues = parameters.toArray();
		processedPositionalParameterTypes = ( Type[] ) parameterTypes.toArray( new Type[parameterTypes.size()] );
		processedSQL = result.toString();
	}
}
 
Example 6
Project: lams   File: JoinProcessor.java   View Source Code Vote up 4 votes
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( !hasDynamicFilterParam( sqlFragment ) )
			&& ( !( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = ParserHelper.HQL_SEPARATORS + dialect.openQuote() + dialect.closeQuote();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuilder result = new StringBuilder();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = (FilterImpl) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray(
							"?",
							type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() )
					)
			);
			final String bindFragment;
			if ( value != null && Collection.class.isInstance( value ) ) {
				bindFragment = StringHelper.join(
						",",
						ArrayHelper.fillArray( typeBindFragment, ( (Collection) value ).size() )
				);
			}
			else {
				bindFragment = typeBindFragment;
			}
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example 7
Project: lams   File: StringHelper.java   View Source Code Vote up 3 votes
/**
 * Determine if the given name is quoted.  It is considered quoted if either:
 * <ol>
 * <li>starts AND ends with backticks (`)</li>
 * <li>starts with dialect-specified {@link org.hibernate.dialect.Dialect#openQuote() open-quote}
 * 		AND ends with dialect-specified {@link org.hibernate.dialect.Dialect#closeQuote() close-quote}</li>
 * </ol>
 *
 * @param name The name to check
 * @param dialect The dialect (to determine the "real" quoting chars).
 *
 * @return True if quoted, false otherwise
 */
public static boolean isQuoted(String name, Dialect dialect) {
	return name != null && name.length() != 0 
			&& ( ( name.charAt( 0 ) == '`' && name.charAt( name.length() - 1 ) == '`' )
					|| ( name.charAt( 0 ) == '"' && name.charAt( name.length() - 1 ) == '"' )
					|| ( name.charAt( 0 ) == dialect.openQuote()
							&& name.charAt( name.length() - 1 ) == dialect.closeQuote() ) );
}