Top Description Fields Constructors Methods
org.apache.derby.impl.tools.ij

public Class StatementFinder

extends Object
Class Inheritance
Imports
org.apache.derby.iapi.tools.i18n.LocalizedOutput, .LocalizedInput, java.io.IOException, .Reader

StatementGrabber looks through an input stream for the next JSQL statement. A statement is considered to be any tokens up to the next semicolon or EOF.

Semicolons inside comments, strings, and delimited identifiers are not considered to be statement terminators but to be part of those tokens.

Comments currently recognized include the SQL comment, which begins with "--" and ends at the next EOL, and nested bracketed comments.

Strings and delimited identifiers are permitted to contain newlines; the actual IJ or JSQL parsers will report errors when those cases occur.

There are no escaped characters, i.e. "\n" is considered to be two characters, '\' and 'n'.

Field Summary

Modifier and TypeField and Description
private static final char
private boolean
private boolean
private boolean
private static final char
private static final int
private static final int
private static final char
private static final int
private static final int
private static final int
private static final char
private static final char
private char
private boolean
private boolean
private LocalizedOutput
private static final char
private static final char
private static final char
private static final char
private Reader
private static final char
private int
private StringBuffer
private static final char

Constructor Summary

AccessConstructor and Description
public
StatementFinder(LocalizedInput
the input stream for reading statements from.
s
,
LocalizedOutput
LocalizedOutput stream to write line continuation prompts ("> ") to. If null, no such prompts will be written.
promptDest
)

The constructor does not assume the stream is data input or buffered, so it will wrap it appropriately.

Method Summary

Modifier and TypeMethod and Description
private boolean
public void
public String

Returns:

the next statement in the input stream.
nextStatement
()

get the next statement in the input stream.

private char

Returns:

the next character in the source stream.
peekChar
()

return the next character in the source stream, without advancing.

private boolean
private void
readBracketedComment()

Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential bracketed comment has been found.

private char

Returns:

the next character in the source stream.
readChar
()

return the next character in the source stream and append it to the statement buffer.

private void
readSingleLineComment(char
the character whose duplication signifies the start of the comment.
commentChar
)

Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential single line comment has been found.

private void
readString(char
the starting and ending character for the string being read.
stringDelimiter
)

Advance the stream to the end of the string.

public void
ReInit(LocalizedInput
the input stream for reading statements from.
s
)

Reinit is used to redirect the finder to another stream.

private boolean

Returns:

true if the character is whitespace
whiteSpace
(char
the character to consider
c
)

Determine if the given character is considered whitespace

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASTERISKback to summary
private static final char ASTERISK
atEOFback to summary
private boolean atEOF
continuedStatementback to summary
private boolean continuedStatement
doPromptback to summary
private boolean doPrompt
DOUBLEQUOTEback to summary
private static final char DOUBLEQUOTE
END_OF_INPUTback to summary
private static final int END_OF_INPUT
END_OF_STATEMENTback to summary
private static final int END_OF_STATEMENT
FORMFEEDback to summary
private static final char FORMFEED
IN_SQLCOMMENTback to summary
private static final int IN_SQLCOMMENT
IN_STATEMENTback to summary
private static final int IN_STATEMENT
IN_STRINGback to summary
private static final int IN_STRING
MINUSback to summary
private static final char MINUS
NEWLINEback to summary
private static final char NEWLINE
peekCharback to summary
private char peekChar
peekedback to summary
private boolean peeked
peekEOFback to summary
private boolean peekEOF
promptwriterback to summary
private LocalizedOutput promptwriter
RETURNback to summary
private static final char RETURN
SEMICOLONback to summary
private static final char SEMICOLON
SINGLEQUOTEback to summary
private static final char SINGLEQUOTE
SLASHback to summary
private static final char SLASH
sourceback to summary
private Reader source
SPACEback to summary
private static final char SPACE
stateback to summary
private int state
statementback to summary
private StringBuffer statement
TABback to summary
private static final char TAB

Constructor Detail

StatementFinderback to summary
public StatementFinder(LocalizedInput s, LocalizedOutput promptDest)

The constructor does not assume the stream is data input or buffered, so it will wrap it appropriately. If the StatementFinder's input stream is connected to System.in, a LocalizedOutput stream may be given to print line continuation prompts when StatementFinder reads a newline.

Parameters
s:LocalizedInput

the input stream for reading statements from.

promptDest:LocalizedOutput

LocalizedOutput stream to write line continuation prompts ("> ") to. If null, no such prompts will be written.

Method Detail

atEOFback to summary
private boolean atEOF()
closeback to summary
public void close() throws IOException
nextStatementback to summary
public String nextStatement()

get the next statement in the input stream. Returns it, dropping its closing semicolon if it has one. If there is no next statement, return a null.

Returns:String

the next statement in the input stream.

peekCharback to summary
private char peekChar()

return the next character in the source stream, without advancing.

Returns:char

the next character in the source stream.

peekEOFback to summary
private boolean peekEOF()
readBracketedCommentback to summary
private void readBracketedComment()

Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential bracketed comment has been found. If it is not a comment, do not advance the stream.

readCharback to summary
private char readChar()

return the next character in the source stream and append it to the statement buffer.

Returns:char

the next character in the source stream.

readSingleLineCommentback to summary
private void readSingleLineComment(char commentChar)

Advance the source stream to the end of a comment if it is on one, assuming the first character of a potential single line comment has been found. If it is not a comment, do not advance the stream.

The form of a single line comment is, in regexp, XX.*$, where XX is two instances of commentChar.

Parameters
commentChar:char

the character whose duplication signifies the start of the comment.

readStringback to summary
private void readString(char stringDelimiter)

Advance the stream to the end of the string. Assumes the opening delimiter of the string has been read. This handles the SQL ability to put the delimiter within the string by doubling it, by reading those as two strings sitting next to one another. I.e, 'Mary''s lamb' is read by this class as two strings, 'Mary' and 's lamb'.

The delimiter of the string is expected to be repeated at its other end. If the other flavor of delimiter occurs within the string, it is just a normal character within it.

All characters except the delimiter are permitted within the string. If EOF is hit before the closing delimiter is found, the end of the string is assumed. Parsers using this parser will detect the error in that case and return appropriate messages.

Parameters
stringDelimiter:char

the starting and ending character for the string being read.

ReInitback to summary
public void ReInit(LocalizedInput s)

Reinit is used to redirect the finder to another stream. The previous stream should not have been in a PEEK state. If an output stream was given when constructing this StatementFinder and the input is standard input, continuation prompting will be enabled.

Parameters
s:LocalizedInput

the input stream for reading statements from.

whiteSpaceback to summary
private boolean whiteSpace(char c)

Determine if the given character is considered whitespace

Parameters
c:char

the character to consider

Returns:boolean

true if the character is whitespace