scriptella.jdbc
Class SqlReaderTokenizer

java.lang.Object
  extended by scriptella.jdbc.SqlReaderTokenizer
All Implemented Interfaces:
java.io.Closeable, SqlTokenizer

public final class SqlReaderTokenizer
extends java.lang.Object
implements 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
SqlReaderTokenizer(java.io.Reader reader)
           
SqlReaderTokenizer(java.io.Reader reader, java.lang.String separator, boolean separatorOnSingleLine, boolean keepFormat)
           
 
Method Summary
 void close()
           
 int[] getInjections()
          This method returns list of injections for the last returned statement.
 java.lang.String getSeparator()
           
 boolean isKeepFormat()
          Returns true if preserve comments and whitespaces.
 boolean isSeparatorOnSingleLine()
           
 java.lang.String nextStatement()
          Parses the following SQL statement from the source.
 void setKeepFormat(boolean keepFormat)
          Keep original text format, i.e. preserve comments and whitespaces.
 void setSeparator(java.lang.String separator)
          Sets statements separator.
 void setSeparatorOnSingleLine(boolean separatorOnSingleLine)
          Sets the separator mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlReaderTokenizer

public SqlReaderTokenizer(java.io.Reader reader)

SqlReaderTokenizer

public SqlReaderTokenizer(java.io.Reader reader,
                          java.lang.String separator,
                          boolean separatorOnSingleLine,
                          boolean keepFormat)
Method Detail

nextStatement

public java.lang.String nextStatement()
                               throws java.io.IOException
Description copied from interface: SqlTokenizer
Parses the following SQL statement from the source.

Use SqlTokenizer.getInjections() to obtain recognized injections, e.g. binding variables and/or expressions.

Specified by:
nextStatement in interface SqlTokenizer
Returns:
parsed SQL statement or null if EOF.
Throws:
java.io.IOException - if I/O exception occurs

getInjections

public int[] getInjections()
Description copied from interface: SqlTokenizer
This method returns list of injections for the last returned statement.

Specified by:
getInjections in interface SqlTokenizer
Returns:
injections for the last returned statement.

getSeparator

public java.lang.String getSeparator()

setSeparator

public void setSeparator(java.lang.String separator)
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 if separator must be on a single line.

isKeepFormat

public boolean isKeepFormat()
Returns true if preserve comments and whitespaces. Default value is false

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

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException


Copyright © Copyright 2006-2009 The Scriptella Project Team.