Class DDLWriter

java.lang.Object
java.io.Writer
org.castor.ddlgen.DDLWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public final class DDLWriter extends Writer
Replace PrintStream and StringBuffer by a Writer implementation We have various properties to configure output that are in-depended of the schema object:
  • org.castor.ddlgen.CharFormat=SENSITIVE, UPPER and LOWER
  • org.castor.ddlgen.Newline=\n
  • org.castor.ddlgen.Indention=\t These properties are accessed at various places all around ddlgen at the moment.The idea is that these properties are set only once at the new Writer and do not need to be accessed elsewhere. This has the following advantages:
  • improved performance as the properties don't need to be accessed for every object to output
  • functionallity to format genertaed ddl is concentrated in one class: the new Writer
  • all the toDDL(), toDropDDL(), toCreateDDL() methods get much shorter I thought of the following interface for the new Writer (not complete):
  • write(String) outputs String as is
  • writeln(String) calls write(String) followed by newline()
  • newline() output newline and indention of next line
  • indent() increases indention
  • unindent() decreases indention More write() and writeln() methods for other data types may be added on demand. A further improvement could be to offer write(String, Object[]) methods that internally use MessageFormat. This would enable us to use a pattern based approach for DDL generation. These patterns may sometimes be much easier to read and maintain. In addition to the introduction of the new Writer it will be required to pass an instance of the Writer to every method where DDL gets generated. Therefore the parameterless toCreate() method have to be changed to toCreateDDL(DDLWriter). This also applies to other such methods.
  • Since:
    1.1.2
    Version:
    $Revision: 5951 $ $Date: 2006-04-25 16:09:10 -0600 (Tue, 25 Apr 2006) $
    Author:
    Le Duc Bao
    • Field Summary

      Fields inherited from class java.io.Writer

      lock
    • Constructor Summary

      Constructors
      Constructor
      Description
      Construct new DDLWriter with given output stream and configuration file.
      Construct new DDLWriter with given writer and configuration file.
    • Method Summary

      Modifier and Type
      Method
      Description
      void
      Check if any error occured at previous operations of the writer.
      void
      Close the writer.
      void
      Flush the writer.
      void
      Increase indention by 1.
      void
      print(char[] chars)
      Print an array of characters.
      void
      print(double number)
      Print a double-precision floating-point number.
      void
      print(int number)
      Print an integer number.
      void
      print(long number)
      Print a long number.
      void
      print(Object object)
      Print an object.
      void
      print(String string)
      Print a string.
      void
      print(String pattern, Object[] arguments)
      A convenience method to print a formatted string build by filling placeholders of the specified pattern with given arguments.
      void
      Terminate the current line by writing the line separator string.
      void
      println(char[] chars)
      Print an array of characters and terminate the line.
      void
      println(double number)
      Print a double-precision floating-point number and terminate the line.
      void
      println(int number)
      Print an integer number and terminate the line.
      void
      println(long number)
      Print a long number and terminate the line.
      void
      println(Object object)
      Print an object and terminate the line.
      void
      println(String string)
      Print a string and terminate the line.
      void
      println(String pattern, Object[] arguments)
      A convenience method to print a formatted string build by filling placeholders of the specified pattern with given arguments.
      void
      Decrease indention by 1.
      void
      write(char[] buf)
      void
      write(char[] buf, int off, int len)
      void
      write(int c)
      void
      void
      write(String s, int off, int len)

      Methods inherited from class java.io.Writer

      append, append, append, nullWriter

      Methods inherited from class java.lang.Object

      clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Details

      • DDLWriter

        public DDLWriter(OutputStream output, Configuration conf)
        Construct new DDLWriter with given output stream and configuration file.
        Parameters:
        output - Output stream to write output characters to.
        conf - Configuration.
      • DDLWriter

        public DDLWriter(Writer writer, Configuration conf)
        Construct new DDLWriter with given writer and configuration file.
        Parameters:
        writer - Writer to write output characters to.
        conf - Configuration.
    • Method Details

      • flush

        public void flush()
        Flush the writer.
        Specified by:
        flush in interface Flushable
        Specified by:
        flush in class Writer
      • close

        public void close()
        Close the writer.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in class Writer
      • checkError

        public void checkError() throws IOException
        Check if any error occured at previous operations of the writer. If an IOException was caught at any previous operation of the writer it will be thrown now.
        Throws:
        IOException - IOException caught at any previous operation of the writer.
      • indent

        public void indent()
        Increase indention by 1.
      • unindent

        public void unindent()
        Decrease indention by 1.
      • write

        public void write(char[] buf, int off, int len)
        Specified by:
        write in class Writer
      • write

        public void write(char[] buf)
        Overrides:
        write in class Writer
      • write

        public void write(int c)
        Overrides:
        write in class Writer
      • write

        public void write(String s, int off, int len)
        Overrides:
        write in class Writer
      • write

        public void write(String s)
        Overrides:
        write in class Writer
      • print

        public void print(char[] chars)
        Print an array of characters.
        Parameters:
        chars - Array of chars to be printed.
      • print

        public void print(double number)
        Print a double-precision floating-point number.
        Parameters:
        number - Double to be printed.
      • print

        public void print(int number)
        Print an integer number.
        Parameters:
        number - Integer to be printed.
      • print

        public void print(long number)
        Print a long number.
        Parameters:
        number - Long to be printed.
      • print

        public void print(Object object)
        Print an object.
        Parameters:
        object - Object to be printed.
      • print

        public void print(String string)
        Print a string.
        Parameters:
        string - String to be printed.
      • print

        public void print(String pattern, Object[] arguments)
        A convenience method to print a formatted string build by filling placeholders of the specified pattern with given arguments.
        Parameters:
        pattern - Pattern with placeholders.
        arguments - Arguments to replace placeholders in pattern.
      • println

        public void println()
        Terminate the current line by writing the line separator string.
      • println

        public void println(char[] chars)
        Print an array of characters and terminate the line.
        Parameters:
        chars - Array of chars to be printed.
      • println

        public void println(double number)
        Print a double-precision floating-point number and terminate the line.
        Parameters:
        number - Double to be printed.
      • println

        public void println(int number)
        Print an integer number and terminate the line.
        Parameters:
        number - Integer to be printed.
      • println

        public void println(long number)
        Print a long number and terminate the line.
        Parameters:
        number - Long to be printed.
      • println

        public void println(Object object)
        Print an object and terminate the line.
        Parameters:
        object - Object to be printed.
      • println

        public void println(String string)
        Print a string and terminate the line.
        Parameters:
        string - String to be printed.
      • println

        public void println(String pattern, Object[] arguments)
        A convenience method to print a formatted string build by filling placeholders of the specified pattern with given arguments. Line will be terminated after the formatted string.
        Parameters:
        pattern - Pattern with placeholders.
        arguments - Arguments to replace placeholders in pattern.