Package scriptella.jdbc
Class SqlReaderTokenizer
java.lang.Object
scriptella.jdbc.SqlReaderTokenizer
- All Implemented Interfaces:
Closeable,AutoCloseable,SqlTokenizer
Reader based SQL tokenizer.
This class splits sql statements using a specifed
separator string.
The ? injections in quoted literals and comments are skipped. The $ substitutions are skipped only in comments.
This class became too complex and needs to be refactored.
- Version:
- 1.0
- Author:
- Fyodor Kupolov
-
Field Summary
Fields inherited from interface scriptella.jdbc.SqlTokenizer
EMPTY_INJECTIONS_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionSqlReaderTokenizer(Reader reader) SqlReaderTokenizer(Reader reader, String separator, boolean separatorOnSingleLine, boolean keepFormat) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()int[]This method returns list of injections for the last returned statement.booleanReturns true if preserve comments and whitespaces.booleanParses the following SQL statement from the source.voidsetKeepFormat(boolean keepFormat) Keep original text format, i.e.voidsetSeparator(String separator) Sets statements separator.voidsetSeparatorOnSingleLine(boolean separatorOnSingleLine) Sets the separator mode.
-
Constructor Details
-
SqlReaderTokenizer
-
SqlReaderTokenizer
-
-
Method Details
-
nextStatement
Description copied from interface:SqlTokenizerParses the following SQL statement from the source.Use
SqlTokenizer.getInjections()to obtain recognized injections, e.g. binding variables and/or expressions.- Specified by:
nextStatementin interfaceSqlTokenizer- Returns:
- parsed SQL statement or null if EOF.
- Throws:
IOException- if I/O exception occurs
-
getInjections
public int[] getInjections()Description copied from interface:SqlTokenizerThis method returns list of injections for the last returned statement.- Specified by:
getInjectionsin interfaceSqlTokenizer- Returns:
- injections for the last returned statement.
-
getSeparator
-
setSeparator
Sets statements separator.- Parameters:
separator- statements separator. Default value is ";"
-
isSeparatorOnSingleLine
public boolean isSeparatorOnSingleLine() -
setSeparatorOnSingleLine
public void setSeparatorOnSingleLine(boolean separatorOnSingleLine) Sets the separator mode.- Parameters:
separatorOnSingleLine- true ifseparatormust be on a single line.
-
isKeepFormat
public boolean isKeepFormat()Returns true if preserve comments and whitespaces. Default value isfalse- Returns:
- false by default
-
setKeepFormat
public void setKeepFormat(boolean keepFormat) Keep original text format, i.e. preserve comments and whitespaces.- Parameters:
keepFormat- true if comments/whitespaces should be preserved.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-