Menu

what is good practice?

Balaji
2008-06-14
2013-04-25
  • Balaji

    Balaji - 2008-06-14

    While editing the generated code, what kind of process will help in smooth usage?

    For example, if I want to edit the <table>manager.java, editing directly would cause difficultly when I want to regenerate the code.
    Is extending this class a better approach?

    Pls share your thoughts and experience.

    Thanks
    Balaji

     
    • Alain Fagot Béarez

      There are many possible approaches to this depending on what you want to edit in the generated code (and why you want it)

      1- you want to replace some lines of the generated methods:

      make your changes to the manager.java.vm template and contribute your change so that it gets integrated with the next release;
      this is the way sql2java got to the actual state of available templates;

      2- you want to run some additional code around the existing methods:

      extend the generated code in a new class

      3- you want to add new methods or new lines to kept over regeneration

      add your own code between comment lines of the form "^// .*[+-]$"
      // any identifying comment +
      private void myMethod(){
      }
      // any identifying comment -

      modify the manager.java.vm template to insert the following line where you want your own code to be kept
      ${userCode.getBlock("any identifying comment")}

      it seems to be a very old sql2java functionality that has not been much documented

      4- you want to generate your own code (own classes and own methods)

      prepare your own templates in your own folder;
      don't forget to contribute it to let others maintain and improve your original work

      Now if what you want is some specific alteration in some specific class, the point 2- may be your solution.  Otherwise, the point 1- is a good way to keep your changes replicated in the future, when adding new tables to your application (this too may happen, that's how I got involved with sql2java in the first place;-).

      Any other point of view from a practical experience?

      Alain

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.