Author: steve.ebersole(a)jboss.com
Date: 2008-09-16 11:59:40 -0400 (Tue, 16 Sep 2008)
New Revision: 15202
Modified:
core/branches/Branch_3_2/src/org/hibernate/engine/query/ParameterParser.java
Log:
HHH-3216 : ParameterParser + escaped function call syntax
Modified: core/branches/Branch_3_2/src/org/hibernate/engine/query/ParameterParser.java
===================================================================
---
core/branches/Branch_3_2/src/org/hibernate/engine/query/ParameterParser.java 2008-09-16
15:58:53 UTC (rev 15201)
+++
core/branches/Branch_3_2/src/org/hibernate/engine/query/ParameterParser.java 2008-09-16
15:59:40 UTC (rev 15202)
@@ -10,7 +10,7 @@
* named, JPA-style, or ordinal) and providing callbacks about such
* recognitions.
*
- * @author <a href="mailto:steve@hibernate.org">Steve Ebersole
</a>
+ * @author Steve Ebersole
*/
public class ParameterParser {
@@ -22,8 +22,10 @@
public void other(char character);
}
+ /**
+ * Direct instantiation of ParameterParser disallowed.
+ */
private ParameterParser() {
- // disallow instantiation
}
/**
@@ -36,12 +38,10 @@
*
* @param sqlString The string to be parsed/tokenized.
* @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
{
- boolean hasMainOutputParameter = sqlString.indexOf( "call" ) > 0
&&
- sqlString.indexOf( "?" ) <
sqlString.indexOf( "call" ) &&
- sqlString.indexOf( "=" ) <
sqlString.indexOf( "call" );
+ boolean hasMainOutputParameter = startsWithEscapeCallTemplate( sqlString );
boolean foundMainOutputParam = false;
int stringLength = sqlString.length();
@@ -65,8 +65,9 @@
int chopLocation = right < 0 ? sqlString.length() : right;
String param = sqlString.substring( indx + 1, chopLocation );
if ( StringHelper.isEmpty( param ) ) {
- throw new QueryException("Space is not allowed after parameter prefix
':' '"
- + sqlString + "'");
+ throw new QueryException(
+ "Space is not allowed after parameter prefix ':' [" + sqlString
+ "]"
+ );
}
recognizer.namedParameter( param, indx );
indx = chopLocation - 1;
@@ -105,4 +106,34 @@
}
}
+ 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;
+ }
+
}