int as;
int leftParen;
int rightParen;
int paramCnt;
String objType;
ParamInfo info;
StringBuffer sb;
Integer paramNo;
if ( !oql.startsWith("CALL ") ) {
throw new QueryException( "Stored procedure call must start with CALL" );
}
// Fix for bug #995
// as = oql.indexOf( " AS " );
as = oql.lastIndexOf( " AS " );
if ( as < 0 ) {
throw new QueryException( "Stored procedure call must end with \"AS <class-name>\"" );
}
leftParen = oql.indexOf( "(" );
rightParen = oql.indexOf( ")" );
sql = new StringBuffer();
paramCnt = 0;
_paramInfo = new Hashtable();
if ( oql.startsWith("CALL SQL") ) {
int startOff = oql.toUpperCase().indexOf("WHERE "); // parameters begin here!
if (!(startOff < 0)) {
startOff += 6;
sql.append(oql.substring(5, startOff));
for ( int i = startOff; i < as; ++i ) {
if ( oql.charAt( i ) == '$' ) {
// get parameter number if given
sb = new StringBuffer();
boolean didParam = false;
for ( int j = i + 1; j < as; j++ ) {
char c = oql.charAt( j );
if (!Character.isDigit(c)) {
didParam = true;
sql.append("?"); // replace characters with "?"
break;
}
sb.append( c );
}
if (!didParam) sql.append('?'); // we reached the end of the string!
if ( sb.length() > 0 ) {
paramNo = Integer.valueOf( sb.toString() );
} else {
paramNo = new Integer( paramCnt + 1 );
}
info = (ParamInfo) _paramInfo.get( paramNo );
if ( info == null ) {
info = new ParamInfo( "", "java.lang.Object", null);
}
info.mapToSQLParam( paramCnt + 1 );
_paramInfo.put( paramNo , info );
paramCnt++;
i += sb.length();
} else {
sql.append(oql.charAt(i));
}
}
} else {
sql.append(oql.substring(5, as));
}
}
else if ((leftParen < 0 && rightParen < 0) ) {
sql.append( oql.substring( 5, as ) );
} else {
if ( ( leftParen < 0 && rightParen >= 0 )
|| ( leftParen > rightParen ) ) {
throw new QueryException( "Syntax error: parenthesis" );
}
sql.append( oql.substring( 5, leftParen ) );
sql.append( '(' );
for ( int i = leftParen + 1; i < rightParen; i++ ) {
if ( oql.charAt( i ) == '$' ) {
// get parameter number if given
sb = new StringBuffer();
for ( int j = i + 1; j < rightParen; j++ ) {
char c;
c = oql.charAt( j );
if ( c < '0' || c > '9' ) {
break;
}
sb.append( c );
}
if ( sb.length() > 0 ) {
paramNo = Integer.valueOf( sb.toString() );
} else {
paramNo = new Integer( paramCnt + 1 );
}
info = (ParamInfo) _paramInfo.get( paramNo );
if ( info == null ) {
info = new ParamInfo( "", "java.lang.Object", null);
}
info.mapToSQLParam( paramCnt + 1 );
_paramInfo.put( paramNo , info );
paramCnt++;
}
}
for ( int i = 0; i < paramCnt; i++ ) {