Class SqlReaderTokenizer

java.lang.Object
scriptella.jdbc.SqlReaderTokenizer
All Implemented Interfaces:
Closeable, AutoCloseable, SqlTokenizer

public final class SqlReaderTokenizer extends 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
  • Constructor Details

    • SqlReaderTokenizer

      public SqlReaderTokenizer(Reader reader)
    • SqlReaderTokenizer

      public SqlReaderTokenizer(Reader reader, String separator, boolean separatorOnSingleLine, boolean keepFormat)
  • Method Details

    • nextStatement

      public String nextStatement() throws 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:
      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 String getSeparator()
    • setSeparator

      public void setSeparator(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 IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException