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

The following examples show how to use org.hibernate.dialect.Dialect#openQuote() . 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
Source Project: lams   File: Column.java    License: 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 2
public String getQuotedName(Dialect d) {
	return quoted ?
		d.openQuote() + name + d.closeQuote() :
		name;
}
 
Example 3
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 4
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 5
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 6
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 7
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 8
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 9
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 10
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 11
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 12
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 13
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 14
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 15
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 16
/**
 * 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 17
public String getQuotedCatalog(Dialect dialect) {
	return catalogQuoted ?
			dialect.openQuote() + catalog + dialect.closeQuote() :
			catalog;
}
 
Example 18
public String getQuotedName(Dialect dialect) {
	return quoted ?
			dialect.openQuote() + name + dialect.closeQuote() :
			name;
}
 
Example 19
public String getQuotedSchema(Dialect dialect) {
	return schemaQuoted ?
			dialect.openQuote() + schema + dialect.closeQuote() :
			schema;
}
 
Example 20
Source Project: lams   File: StringHelper.java    License: 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() ) );
}