Package org.exolab.castor.jdo

Examples of org.exolab.castor.jdo.QueryException


        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++ ) {
                sql.append( '?' );
                if ( i < paramCnt - 1 )
                    sql.append( ',' );
            }
            sql.append( ')' );
        }
        _spCall = sql.toString();
        _projectionType = ParseTreeWalker.PARENT_OBJECT;
        _bindTypes = new Class[ paramCnt ];
        for ( int i = 0; i < paramCnt; i++ )
            _bindTypes[ i ] = Object.class;

        objType = oql.substring( as + 4 ).trim();
        if ( objType.length() == 0 ) {
            throw new QueryException( "Missing object name" );
        }
        try {
            if ( _dbImpl.getClassLoader() == null )
                _objClass = Class.forName( objType );
            else
                _objClass = _dbImpl.getClassLoader().loadClass( objType );
        } catch ( ClassNotFoundException except ) {
            throw new QueryException( "Could not find class " + objType );
        }
        _dbEngine = _dbImpl.getLockEngine();
        if ( _dbEngine == null || _dbEngine.getPersistence( _objClass ) == null )
            throw new QueryException( "Could not find an engine supporting class " + objType );
    }
View Full Code Here


                        if ( _bindValues != null ) {
                            for ( int i = 0 ; i < _bindValues.length ; ++i )
                                _query.setParameter( i, _bindValues[ i ] );
                        }
                    } catch ( QueryException except ) {
                        throw new QueryException( except.getMessage() );
                    }
                    results = _dbImpl.getTransaction().query( _dbEngine, _query, accessMode, scrollable );
                    _fieldNum = 0;

                    if ( _projectionType == ParseTreeWalker.PARENT_OBJECT )
View Full Code Here

        Parser parser = new Parser(lexer);
        ParseTreeNode parseTree = parser.getParseTree();

        _dbEngine = _dbImpl.getLockEngine();
        if ( _dbEngine == null )
            throw new QueryException( "Could not get a persistence engine" );

        ParseTreeWalker walker = new ParseTreeWalker(_dbEngine, parseTree, _dbImpl.getClassLoader());

        _objClass = walker.getObjClass();
        _clsDesc = walker.getClassDescriptor();
View Full Code Here

        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++ ) {
                sql.append( '?' );
                if ( i < paramCnt - 1 )
                    sql.append( ',' );
            }
            sql.append( ')' );
        }
        _spCall = sql.toString();
        _projectionType = ParseTreeWalker.PARENT_OBJECT;
        _bindTypes = new Class[ paramCnt ];
        for ( int i = 0; i < paramCnt; i++ )
            _bindTypes[ i ] = Object.class;

        objType = oql.substring( as + 4 ).trim();
        if ( objType.length() == 0 ) {
            throw new QueryException( "Missing object name" );
        }
        try {
            if ( _dbImpl.getClassLoader() == null )
                _objClass = Class.forName( objType );
            else
                _objClass = _dbImpl.getClassLoader().loadClass( objType );
        } catch ( ClassNotFoundException except ) {
            throw new QueryException( "Could not find class " + objType );
        }
        _dbEngine = _dbImpl.getLockEngine();
        if ( _dbEngine == null || _dbEngine.getPersistence( _objClass ) == null )
            throw new QueryException( "Could not find an engine supporting class " + objType );
    }
View Full Code Here

                        if ( _bindValues != null ) {
                            for ( int i = 0 ; i < _bindValues.length ; ++i )
                                _query.setParameter( i, _bindValues[ i ] );
                        }
                    } catch ( QueryException except ) {
                        throw new QueryException( except.getMessage() );
                    }
                    results = _dbImpl.getTransaction().query( _dbEngine, _query, accessMode, scrollable );
                    _fieldNum = 0;

                    if ( _projectionType == ParseTreeWalker.PARENT_OBJECT )
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.QueryException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.