SQLFunctionTemplatepublic class SQLFunctionTemplate extends Object implements SQLFunctionRepresents HQL functions that can have different representations in different SQL dialects.
E.g. in HQL we can define function concat(?1, ?2) to concatenate two strings
p1 and p2. Target SQL function will be dialect-specific, e.g. (?1 || ?2) for
Oracle, concat(?1, ?2) for MySql, (?1 + ?2) for MS SQL.
Each dialect will define a template as a string (exactly like above) marking function
parameters with '?' followed by parameter's index (first index is 1). |
Fields Summary |
---|
private final org.hibernate.type.Type | type | private final boolean | hasArguments | private final boolean | hasParenthesesIfNoArgs | private final String | template | private final String[] | chunks | private final int[] | paramIndexes |
Constructors Summary |
---|
public SQLFunctionTemplate(org.hibernate.type.Type type, String template)
this( type, template, true );
| public SQLFunctionTemplate(org.hibernate.type.Type type, String template, boolean hasParenthesesIfNoArgs)
this.type = type;
this.template = template;
List chunkList = new ArrayList();
List paramList = new ArrayList();
StringBuffer chunk = new StringBuffer( 10 );
StringBuffer index = new StringBuffer( 2 );
for ( int i = 0; i < template.length(); ++i ) {
char c = template.charAt( i );
if ( c == '?" ) {
chunkList.add( chunk.toString() );
chunk.delete( 0, chunk.length() );
while ( ++i < template.length() ) {
c = template.charAt( i );
if ( Character.isDigit( c ) ) {
index.append( c );
}
else {
chunk.append( c );
break;
}
}
paramList.add( new Integer( Integer.parseInt( index.toString() ) - 1 ) );
index.delete( 0, index.length() );
}
else {
chunk.append( c );
}
}
if ( chunk.length() > 0 ) {
chunkList.add( chunk.toString() );
}
chunks = ( String[] ) chunkList.toArray( new String[chunkList.size()] );
paramIndexes = new int[paramList.size()];
for ( int i = 0; i < paramIndexes.length; ++i ) {
paramIndexes[i] = ( ( Integer ) paramList.get( i ) ).intValue();
}
hasArguments = paramIndexes.length > 0;
this.hasParenthesesIfNoArgs = hasParenthesesIfNoArgs;
|
|