public AbstractDMLQuery parseSqlQuery(SQLQuery sqlQuery,ISpaceProxy space) throws SQLException {
  AbstractDMLQuery query=(AbstractDMLQuery)getQueryFromCache(getUniqueKey(sqlQuery));
  try {
    if (query == null) {
      if (_logger.isLoggable(Level.FINE)) {
        _logger.fine("Query wasn't in cache, will be parsed");
      }
      SqlParser parser=initParser(sqlQuery.getQuery());
      query=parse(parser);
      query.setTableName(sqlQuery.getTypeName());
      query.validateQuery(space);
      if (!query.isPrepared() && !query.containsSubQueries())       query.build();
      addQueryToCache(getUniqueKey(sqlQuery),query);
      if (!query.isPrepared())       return query;
    }
    query=query.clone();
    return query;
  }
 catch (  SQLException sqlEx) {
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"Error executing statement [" + sqlQuery.getQuery() + "]",sqlEx);
    }
    throw sqlEx;
  }
catch (  Throwable t) {
    if (_logger.isLoggable(Level.FINE)) {
      _logger.log(Level.FINE,"Couldn't parse given statement [" + sqlQuery.getQuery() + "]",t);
    }
    SQLException sqlEx=new SQLException("Error in statement [" + sqlQuery.getQuery() + "]; Cause: "+ t,"GSP",-201);
    sqlEx.initCause(t);
    throw sqlEx;
  }
}

public AbstractDMLQuery parseSqlQuery ( SQLQuery sqlQuery , ISpaceProxy space ) throws SQLException { AbstractDMLQuery query = ( AbstractDMLQuery ) getQueryFromCache ( getUniqueKey ( sqlQuery ) ) ; try { if ( query == null ) { if ( _logger . isLoggable ( Level . FINE ) ) { _logger . fine ( "Query wasn't in cache, will be parsed" ) ; } SqlParser parser = initParser ( sqlQuery . getQuery ( ) ) ; query = parse ( parser ) ; query . setTableName ( sqlQuery . getTypeName ( ) ) ; query . validateQuery ( space ) ; if ( ! query . isPrepared ( ) && ! query . containsSubQueries ( ) ) query . build ( ) ; addQueryToCache ( getUniqueKey ( sqlQuery ) , query ) ; if ( ! query . isPrepared ( ) ) return query ; } query = query . clone ( ) ; return query ; } catch ( SQLException sqlEx ) { if ( _logger . isLoggable ( Level . FINE ) ) { _logger . log ( Level . FINE , "Error executing statement [" + sqlQuery . getQuery ( ) + "]" , sqlEx ) ; } throw sqlEx ; } catch ( Throwable t ) { if ( _logger . isLoggable ( Level . FINE ) ) { _logger . log ( Level . FINE , "Couldn't parse given statement [" + sqlQuery . getQuery ( ) + "]" , t ) ; } SQLException sqlEx = new SQLException ( "Error in statement [" + sqlQuery . getQuery ( ) + "]; Cause: " + t , "GSP" , - 201 ) ; sqlEx . initCause ( t ) ; throw sqlEx ; } }
the main method to handle the query . first it will try to retrieve the query from the cache , if its not there , it will build a parser to parse the statement and then put it in the cache .
