org.dbmaintain.script.parser.impl
Class StatementBuilder

java.lang.Object
  extended by org.dbmaintain.script.parser.impl.StatementBuilder

public class StatementBuilder
extends Object

Assembles SQL or stored procedure statements by processing characters one by one. It keeps track of the current parsing state and whether the current statement is complete and contains executable content.

Author:
Stefan Bangels, Tim Ducheyne, Filip Neven

Constructor Summary
StatementBuilder(ParsingState initialParsingState, Properties scriptParameters)
          Creates a new instance with the given parsing state as the initial state
 
Method Summary
 void addCharacter(Character currentChar, Character nextChar)
           
protected  void appendToCurrentLine(Character currentChar)
           
protected  void appendToStatementWithoutCommentsAndWhitespace(Character currentChar, HandleNextCharacterResult handleNextCharacterResult)
           
 String buildStatement()
           
protected  void flushCurrentLine()
           
 String getCurrentLine()
           
protected  char getLastCharacter(StringBuilder statement)
           
 StringBuilder getStatementInUppercaseWithoutCommentsOrWhitespace()
           
 boolean hasExecutableContent()
           
 boolean isComplete()
           
protected  boolean isWhitespace(Character currentChar)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatementBuilder

public StatementBuilder(ParsingState initialParsingState,
                        Properties scriptParameters)
Creates a new instance with the given parsing state as the initial state

Parameters:
initialParsingState - the initial state
scriptParameters - parameters that must be replaced in the script. Null if there are no such parameters
Method Detail

addCharacter

public void addCharacter(Character currentChar,
                         Character nextChar)

flushCurrentLine

protected void flushCurrentLine()

appendToCurrentLine

protected void appendToCurrentLine(Character currentChar)

appendToStatementWithoutCommentsAndWhitespace

protected void appendToStatementWithoutCommentsAndWhitespace(Character currentChar,
                                                             HandleNextCharacterResult handleNextCharacterResult)

getLastCharacter

protected char getLastCharacter(StringBuilder statement)

isWhitespace

protected boolean isWhitespace(Character currentChar)

getCurrentLine

public String getCurrentLine()

isComplete

public boolean isComplete()

hasExecutableContent

public boolean hasExecutableContent()
Returns:
true if the statement contains other content than comments

buildStatement

public String buildStatement()
Returns:
The resulting statement, not null

getStatementInUppercaseWithoutCommentsOrWhitespace

public StringBuilder getStatementInUppercaseWithoutCommentsOrWhitespace()
Returns:
the statement statement with comments, newlines and unnecessary whitespace left out


Copyright © 2011. All Rights Reserved.