castor
  1. castor
  2. CASTOR-1774

Replace PrintStream and StringBuffer by a Writer implementation

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.2
    • Component/s: JDO DDL generator
    • Labels:
      None
    • Number of attachments :
      3
    1. DDLWriter.java
      12 kB
      Le Duc Bao
    2. patch.txt
      148 kB
      Le Duc Bao
    3. patch-C1774-20070607.txt
      170 kB
      Ralf Joachim

      Activity

      Le Duc Bao made changes -
      Field Original Value New Value
      Assignee Le Duc Bao [ leducbao ]
      Hide
      Le Duc Bao added a comment -

      Hello Ralf,

      Does it really need to replace StringBuffer? What is the advantage of a Writer implementation (like StringWriter) in compare with StringBuffer?

      I will replace PrintStream by Writer.

      Show
      Le Duc Bao added a comment - Hello Ralf, Does it really need to replace StringBuffer? What is the advantage of a Writer implementation (like StringWriter) in compare with StringBuffer? I will replace PrintStream by Writer.
      Hide
      Ralf Joachim added a comment -

      We have various properties to configure output that are independed 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 a 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.

      Hope this explains the idea behind this issue a bit better then the summary alone.

      Show
      Ralf Joachim added a comment - We have various properties to configure output that are independed 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 a 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. Hope this explains the idea behind this issue a bit better then the summary alone.
      Hide
      Le Duc Bao added a comment -

      I created the DDLWriter which encapsulates almost common task for writer. It will replace the PrintStream and StringBuffer.

      Show
      Le Duc Bao added a comment - I created the DDLWriter which encapsulates almost common task for writer. It will replace the PrintStream and StringBuffer.
      Le Duc Bao made changes -
      Attachment DDLWriter.java [ 26994 ]
      Hide
      Ralf Joachim added a comment -

      Thanks for your work. When looking at the writer code you provided I recognized the following:

      • you are using java 5 features but we like ddlgen to be compliant with java 1.4
      • could you please take a bit more care on formating of javadoc and code
      • isn't it possible for you to prepare patch files as that would be required for changes to available classes
      • why are the methods for objects called writeObject() instead of write(). The compiler should be able to choose the right one
      • the writer does not handle char formating: SENSITIVE, UPPER and LOWER
      • after thinking again about when to output indent characters I came to the conclusion that it would be better to output them at the first write to a new line and not directly after writing the newline as that may cause wrong indention in following situation.

      w.writeln("line1");
      w.indent();
      w.writeln("line2");
      w.unindent();
      w.writeln("line3");

      In that case line 3 will be indented even if it should not be indented.

      Show
      Ralf Joachim added a comment - Thanks for your work. When looking at the writer code you provided I recognized the following: you are using java 5 features but we like ddlgen to be compliant with java 1.4 could you please take a bit more care on formating of javadoc and code isn't it possible for you to prepare patch files as that would be required for changes to available classes why are the methods for objects called writeObject() instead of write(). The compiler should be able to choose the right one the writer does not handle char formating: SENSITIVE, UPPER and LOWER after thinking again about when to output indent characters I came to the conclusion that it would be better to output them at the first write to a new line and not directly after writing the newline as that may cause wrong indention in following situation. w.writeln("line1"); w.indent(); w.writeln("line2"); w.unindent(); w.writeln("line3"); In that case line 3 will be indented even if it should not be indented.
      Hide
      Le Duc Bao added a comment -

      Hi Ralf,
      I changed all signature createxxx() to createxxx(DDLWriter) and also fix the tester. By the way, I cannot run the test suite. Can you help me?

      Show
      Le Duc Bao added a comment - Hi Ralf, I changed all signature createxxx() to createxxx(DDLWriter) and also fix the tester. By the way, I cannot run the test suite. Can you help me?
      Le Duc Bao made changes -
      Attachment patch.txt [ 27334 ]
      Hide
      Werner Guttmann added a comment -

      Which test suite ? XML or JDO ?

      Show
      Werner Guttmann added a comment - Which test suite ? XML or JDO ?
      Hide
      Le Duc Bao added a comment -

      The DDLGen test suite.

      Show
      Le Duc Bao added a comment - The DDLGen test suite.
      Hide
      Ralf Joachim added a comment -

      I'll review your patch and run DDLGEN test suite

      Show
      Ralf Joachim added a comment - I'll review your patch and run DDLGEN test suite
      Hide
      Ralf Joachim added a comment -

      Final patch

      Show
      Ralf Joachim added a comment - Final patch
      Ralf Joachim made changes -
      Attachment patch-C1774-20070607.txt [ 27833 ]
      Ralf Joachim made changes -
      Resolution Fixed [ 1 ]
      Fix Version/s 1.1.2 [ 13440 ]
      Status Open [ 1 ] Resolved [ 5 ]
      Ralf Joachim made changes -
      Status Resolved [ 5 ] Closed [ 6 ]

        People

        • Assignee:
          Le Duc Bao
          Reporter:
          Ralf Joachim
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: