Is there a code generator?

Calvin Loh
2002-05-03
2002-10-07
  • Calvin Loh

    Calvin Loh - 2002-05-03

    Has anyone written a code generator
    for JGrinder?

    I forsee having to write a lot of code
    to support many tables (10 - 20)  :(

    TIA.

     
    • David Hoag

      David Hoag - 2002-05-03

      Actually, there are 3!

      1) This link describes how to use the first one - the content is a bit stale, but you'll get the idea. http://sourceforge.net/docman/display_doc.php?docid=4291&group_id=1531

      2) There is a cvs module called Cartographer. This has never been polished, and would require some work on your part, but what it does is generate persistent objects from reading JDBC meta information.

      3) There is a new template generator that is based upon JSP. It uses the JSP engine from tomcat 4.0.1. Again, not a lot of polish or documentation, but it shouldn't be too hard to figure out.

       
    • Ashik Uzzaman

      Ashik Uzzaman - 2002-10-07

      I was trying your code generator and slightly adjusted a few lines. But it returns after line #A

      import java.util.Vector;import com.objectwave.exception.*;import java.io.FileNotFoundException;import com.objectwave.persist.examples.DomainObject;import com.objectwave.persist.broker.FileBroker;import com.objectwave.persist.SQLQuery;import com.objectwave.persist.BrokerFactory;public class Employee extends DomainObject {    public static java.lang.reflect.Field _salary;    public static java.lang.reflect.Field _name;    static String tableName;    static Vector classDescriptor;    protected String name;    protected int salary;    public Employee() throws FileNotFoundException, ConfigurationException   
      {        initialize();    }    /**     *  Use an instance method to access a static variable. This method MUST     *  be duplicated in each and every subclass. This allows our generic logic     *  in this super class to modify static state in a subclass.     *     * @param  table The new TableName value     */
          protected void setTableName(final String table)    {        tableName = table;    }   
      /**     *  Use an instance method to access a static variable. This method MUST     *  be duplicated in each and every subclass. This allows our generic logic     *  in this super class to modify static state in a subclass.     *     * @param  v The new ClassDescriptor value     */   
      protected void setClassDescriptor(final Vector v)    {        classDescriptor = v;    }   
      /**     *  Use an instance method to access a static variable. This method MUST     *  be duplicated in each and every subclass. This allows our generic logic     *  in this super class to modify static state in a subclass.     *     * @return  The TableName value     */
          protected String getTableName()    {        return tableName;    }    /**     *  Use an instance method to access a static variable. This method MUST     *  be duplicated in each and every subclass. This allows our generic logic     *  in this super class to modify static state in a subclass.     *     * @return  The ClassDescriptor value     */
          protected Vector getClassDescriptor()    {        return classDescriptor;    }   
      /**     * This static block will be regenerated if persistence is regenerated.     * Errors while running a static method can result in odd exceptions, so we     * print the stack trace to help out.     */    static {        try{            _name = Employee.class.getDeclaredField("name");            _name.setAccessible(true);            _salary = Employee.class.getDeclaredField("salary");            _salary.setAccessible(true);        }        catch (NoSuchFieldException ex) { ex.printStackTrace(); }    }
          /**    * @author ashik    */    public String getName()    {        return (String)editor.get(_name, name);    }    /**    * @author ashik    */    public void setName(String aValue)    {        editor.set(_name, aValue, name);    }
          /**    * @author ashik    */    public int getSalary()    {        return (int)editor.get(_salary, salary);    }
          /**    * @author ashik    */    public void setSalary(int aValue)    {        editor.set(_salary, aValue, salary);    }
          /**     * Must be called from ALL constructors!     * Needed to define table name and the description of this class.     */    public void initialize() throws FileNotFoundException, ConfigurationException    {
              try{            setObjectEditor( initializeObjectEditor("employee.xml", this) );// line #A
                  System.out.println("========= Object Editor set =======");        }       
      catch(FileNotFoundException fnfe) {            System.out.println("========= FileNotFoundException ======");        }        catch(ConfigurationException ce){            System.out.println("======= ConfigurationException ========");        }        catch(Exception e) {            System.out.println("====== General Exception ======");            e.printStackTrace();        }    }
          /** To run this code only -- ashik */    public static void main(String [] args)    {    try {    FileBroker fb = new FileBroker();    BrokerFactory.setDefaultBroker( fb );    SQLQuery.setDefaultBroker( fb );    Employee employee = employee = new Employee();    employee.setName("Dave");    employee.save();    SQLQuery query = new SQLQuery( employee );    Employee foundEmployee = (Employee)query.findUnique();    System.out.println( foundEmployee.getName() );    }    catch( Throwable t ) { }    System.out.println("======== Finish ========");
          }}

      I provided the xml file in current directory and in classpath. Despite its returning without result after the line ------

      setObjectEditor( initializeObjectEditor("employee.xml", this) );

      Any light here?

       
    • David Hoag

      David Hoag - 2002-10-07

      An alternate approach may be to try the new bcel support in JGrinder. This doesn't require any modifications to your persistent objects. Check out the com.objectwave.persist.bcel.examples for examples on how to use it.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks