org.dbmaintain.script.parser.impl
Class DefaultScriptParser

java.lang.Object
  extended by org.dbmaintain.script.parser.impl.DefaultScriptParser
All Implemented Interfaces:
ScriptParser

public class DefaultScriptParser
extends Object
implements ScriptParser

A class for parsing statements out of sql scripts.

All statements should be separated with a semicolon (;). The last statement will be added even if it does not end with a semicolon. The semicolons will not be included in the returned statements.

This parser also takes quoted literals, double quoted text and in-line (--comment) and block (/ * comment * /) into account when parsing the statements.

Author:
Tim Ducheyne, Filip Neven, Stefan Bangels

Field Summary
protected  boolean backSlashEscapingEnabled
          Whether backslash escaping is enabled
protected  Character currentChar
          The current parsed character
protected  boolean endOfScriptReached
          True if the script has ended
protected  ParsingState initialParsingState
          The starting state
protected  Character nextChar
          The current parsed character
protected  Properties scriptParameters
          Parameters that must be replaced in the script.
protected  Reader scriptReader
          The reader for the script content stream
 
Constructor Summary
DefaultScriptParser(Reader scriptReader, ParsingState initialParsingState, boolean backSlashEscapingEnabled, Properties scriptParameters)
          Constructor for DefaultScriptParser.
 
Method Summary
protected  StatementBuilder createStatementBuilder()
          Factory method for the statement builder.
 String getNextStatement()
          Parses the next statement out of the given script stream.
protected  String getNextStatementImpl()
          Actual implementation of getNextStatement.
protected  Character readNextCharacter()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scriptReader

protected Reader scriptReader
The reader for the script content stream


backSlashEscapingEnabled

protected boolean backSlashEscapingEnabled
Whether backslash escaping is enabled


scriptParameters

protected Properties scriptParameters
Parameters that must be replaced in the script. Null if there are no such parameters


initialParsingState

protected ParsingState initialParsingState
The starting state


endOfScriptReached

protected boolean endOfScriptReached
True if the script has ended


currentChar

protected Character currentChar
The current parsed character


nextChar

protected Character nextChar
The current parsed character

Constructor Detail

DefaultScriptParser

public DefaultScriptParser(Reader scriptReader,
                           ParsingState initialParsingState,
                           boolean backSlashEscapingEnabled,
                           Properties scriptParameters)
Constructor for DefaultScriptParser.

Parameters:
scriptReader - the reader that will provide the script content, not null
initialParsingState - the inial state when starting to parse a script, not null
backSlashEscapingEnabled - true if backslash escaping is enabled
scriptParameters - parameters that must be replaced in the script. null if there are no such parameters.
Method Detail

getNextStatement

public String getNextStatement()
Parses the next statement out of the given script stream.

Specified by:
getNextStatement in interface ScriptParser
Returns:
the statements, null if no more statements

getNextStatementImpl

protected String getNextStatementImpl()
                               throws IOException
Actual implementation of getNextStatement.

Returns:
the statements, null if no more statements
Throws:
IOException - if a problem occurs reading the script from the file system

readNextCharacter

protected Character readNextCharacter()
                               throws IOException
Throws:
IOException

createStatementBuilder

protected StatementBuilder createStatementBuilder()
Factory method for the statement builder.

Returns:
The statement builder, not null


Copyright © 2011. All Rights Reserved.