HHH-3216 : ParameterParser + escaped function call syntax

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@15202 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-09-16 15:59:40 +00:00
parent abe9ca390b
commit ce1b3ef600
1 changed files with 39 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import org.hibernate.util.StringHelper;
* named, JPA-style, or ordinal) and providing callbacks about such * named, JPA-style, or ordinal) and providing callbacks about such
* recognitions. * recognitions.
* *
* @author <a href="mailto:steve@hibernate.org">Steve Ebersole </a> * @author Steve Ebersole
*/ */
public class ParameterParser { public class ParameterParser {
@ -22,8 +22,10 @@ public class ParameterParser {
public void other(char character); public void other(char character);
} }
/**
* Direct instantiation of ParameterParser disallowed.
*/
private ParameterParser() { private ParameterParser() {
// disallow instantiation
} }
/** /**
@ -36,12 +38,10 @@ public class ParameterParser {
* *
* @param sqlString The string to be parsed/tokenized. * @param sqlString The string to be parsed/tokenized.
* @param recognizer The thing which handles recognition events. * @param recognizer The thing which handles recognition events.
* @throws QueryException * @throws QueryException Indicates unexpected parameter conditions.
*/ */
public static void parse(String sqlString, Recognizer recognizer) throws QueryException { public static void parse(String sqlString, Recognizer recognizer) throws QueryException {
boolean hasMainOutputParameter = sqlString.indexOf( "call" ) > 0 && boolean hasMainOutputParameter = startsWithEscapeCallTemplate( sqlString );
sqlString.indexOf( "?" ) < sqlString.indexOf( "call" ) &&
sqlString.indexOf( "=" ) < sqlString.indexOf( "call" );
boolean foundMainOutputParam = false; boolean foundMainOutputParam = false;
int stringLength = sqlString.length(); int stringLength = sqlString.length();
@ -65,8 +65,9 @@ public class ParameterParser {
int chopLocation = right < 0 ? sqlString.length() : right; int chopLocation = right < 0 ? sqlString.length() : right;
String param = sqlString.substring( indx + 1, chopLocation ); String param = sqlString.substring( indx + 1, chopLocation );
if ( StringHelper.isEmpty( param ) ) { if ( StringHelper.isEmpty( param ) ) {
throw new QueryException("Space is not allowed after parameter prefix ':' '" throw new QueryException(
+ sqlString + "'"); "Space is not allowed after parameter prefix ':' [" + sqlString + "]"
);
} }
recognizer.namedParameter( param, indx ); recognizer.namedParameter( param, indx );
indx = chopLocation - 1; indx = chopLocation - 1;
@ -105,4 +106,34 @@ public class ParameterParser {
} }
} }
public static boolean startsWithEscapeCallTemplate(String sqlString) {
if ( ! ( sqlString.startsWith( "{" ) && sqlString.endsWith( "}" ) ) ) {
return false;
}
int chopLocation = sqlString.indexOf( "call" );
if ( chopLocation <= 0 ) {
return false;
}
final String checkString = sqlString.substring( 1, chopLocation + 4 );
final String fixture = "?=call";
int fixturePosition = 0;
boolean matches = true;
for ( int i = 0, max = checkString.length(); i < max; i++ ) {
final char c = Character.toLowerCase( checkString.charAt( i ) );
if ( Character.isWhitespace( c ) ) {
continue;
}
if ( c == fixture.charAt( fixturePosition ) ) {
fixturePosition++;
continue;
}
matches = false;
break;
}
return matches;
}
} }