Java Code Examples for org.hibernate.dialect.Dialect#closeQuote()

The following examples show how to use org.hibernate.dialect.Dialect#closeQuote() . 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
Source File: Template.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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 2
Source File: Table.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 3
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 4
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 5
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 6
Source File: Column.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public String getQuotedName(Dialect d) {
	return quoted ?
		d.openQuote() + name + d.closeQuote() :
		name;
}
 
Example 7
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 8
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 9
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 10
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 11
Source File: Column.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public String getQuotedName(Dialect d) {
	return quoted ?
			d.openQuote() + name + d.closeQuote() :
			name;
}
 
Example 12
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 13
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 14
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 15
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 16
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 17
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 18
Source File: JoinProcessor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( !hasDynamicFilterParam( walker, sqlFragment ) )
			&& ( !( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.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 = String.join(
					",",
					ArrayHelper.fillArray(
							"?",
							type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() )
					)
			);
			final String bindFragment;
			if ( value != null && Collection.class.isInstance( value ) ) {
				bindFragment = String.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 19
Source File: StringHelper.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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() ) );
}
 
Example 20
Source File: Identifier.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * If this is a quoted identifier, then return the identifier name
 * enclosed in dialect-specific open- and end-quotes; otherwise,
 * simply return the unquoted identifier.
 *
 * @param dialect The dialect whose dialect-specific quoting should be used.
 *
 * @return if quoted, identifier name enclosed in dialect-specific open- and
 * end-quotes; otherwise, the unquoted identifier.
 */
public String render(Dialect dialect) {
	return isQuoted
			? String.valueOf( dialect.openQuote() ) + getText() + dialect.closeQuote()
			: getText();
}