static void executeScriptFiles ( List < FileInfo > filesInfo , SQLCommandLineReader parentLineReader , DDLParserCallback callback ) throws IOException { LineReaderAdapter adapter = null ; SQLCommandLineReader reader = null ; StringBuilder statements = new StringBuilder ( ) ; if ( ! m_interactive && callback == null ) { // We have to check for the callback to avoid spewing to System.out in the "init --classes" filtering codepath. // Better logging/output handling in general would be nice to have here -- output on System.out will be consumed // by the test generators (build_eemakefield) and cause build failures. System . out . println ( ) ; StringBuilder commandString = new StringBuilder ( ) ; commandString . append ( filesInfo . get ( 0 ) . toString ( ) ) ; for ( int ii = 1 ; ii < filesInfo . size ( ) ; ii ++ ) { commandString . append ( " " + filesInfo . get ( ii ) . getFile ( ) . toString ( ) ) ; } System . out . println ( commandString . toString ( ) ) ; } for ( int ii = 0 ; ii < filesInfo . size ( ) ; ii ++ ) { FileInfo fileInfo = filesInfo . get ( ii ) ; adapter = null ; reader = null ; if ( fileInfo . getOption ( ) == FileOption . INLINEBATCH ) { // File command is a "here document" so pass in the current // input stream. reader = parentLineReader ; } else { try { reader = adapter = new LineReaderAdapter ( new FileReader ( fileInfo . getFile ( ) ) ) ; } catch ( FileNotFoundException e ) { System . err . println ( "Script file '" + fileInfo . getFile ( ) + "' could not be found." ) ; stopOrContinue ( e ) ; return ; // continue to the next line after the FILE command } // if it is a batch option, get all contents from all the files and send it as a string if ( fileInfo . getOption ( ) == FileOption . BATCH ) { String line ; // use the current reader we obtained to read from the file // and append to existing statements while ( ( line = reader . readBatchLine ( ) ) != null ) { statements . append ( line ) . append ( "\n" ) ; } // set reader to null since we finish reading from the file reader = null ; // if it is the last file, create a reader to read from the string of all files contents if ( ii == filesInfo . size ( ) - 1 ) { String allStatements = statements . toString ( ) ; byte [ ] bytes = allStatements . getBytes ( "UTF-8" ) ; ByteArrayInputStream bais = new ByteArrayInputStream ( bytes ) ; // reader LineReaderAdapter needs an input stream reader reader = adapter = new LineReaderAdapter ( new InputStreamReader ( bais ) ) ; } // NOTE - fileInfo has the last file info for batch with multiple files } } try { executeScriptFromReader ( fileInfo , reader , callback ) ; } catch ( SQLCmdEarlyExitException e ) { throw e ; } catch ( Exception x ) { stopOrContinue ( x ) ; } finally { if ( adapter != null ) { adapter . close ( ) ; } } } }
Reads a script file and executes its content . Note that the script file could be an inline batch i . e . a here document that is coming from the same input stream as the file directive .