Re: <cgen> Ant task and makepairs attribute

From: Mike Kienenberger (mkienen..laska.net)
Date: Wed Apr 27 2005 - 11:26:12 EDT

  • Next message: Erik Hatcher: "how to re-order a relationship"

    Erik Hatcher <eri..hatchersolutions.com> wrote:
    > Admittedly still a Cayenne (and ORM) newbie, I'm working out how to fit
    > Cayenne into my project. I've been happily using the <cgen> task.
    > I've just modeled some inheritance, though, and now need to add the
    > setPersistenceState() trick to my main model subclasses. What I've
    > done is move these empty classes into my maintained codebase to add
    > this code, and will certainly be adding other business methods there in
    > the near future too.
    >
    > The <cgen> task only has the makepairs attribute though, which
    > generates the superclass/subclass combination or a class that both
    > combined. What I'd rather have is just the generation of the
    > superclasses. For now I'm dealing with this by doing this after
    > <cgen>:
    >
    > <delete>
    > <fileset dir="${build.dir}/gen" excludes="**/_*.java"/>
    > </delete>
    >
    > I'm curious what others using <cgen> do when the subclasses need to be
    > modified, and whether modifying <cgen> to be friendlier to this type of
    > situation is of interest or if there is a better way to do what I'm
    > doing.

    I'd probably have separate or conditional templates that allow your
    _SUPERCLASS files to generate the needed inheritance if at all possible.
    I'm going to be using vertical inheritance soon, and that's how I'm going to
    try to approach it as a first pass .

    A long time ago, I had the need to generate all sorts of files based on my
    model data.
    (velocity templates, java code, xml config files)

    I modified the ant task to look like this:

        <!-- Rebuild classes dependent on database model -->
        <target name="generateEntityReportPart2" depends="init"
    description="cmd-line: Generates ProcessENTITYReportAction.java">
                    <taskdef name="cgen"
    classname="org.objectstyle.cayenne.tools.CayenneGenerator">
                         <classpath refid="generate.classpath"/>
                    </taskdef>
                    <cgen
    map="${local.project.location}/Ebpp-struts/WEB-INF/OnlineBilling.map.xml"
                              filenamePrefix="Process"
                              filenameSuffix="ReportAction.java"
                              entity="${ENTITY_NAME}"
                              overwrite="false"
                          
    destDir="${local.project.location}/Ebpp-struts/WEB-INF/src/com/gvea/struts/ebpp/action/generated"
                          makepairs="false"
                           template
    ="${local.project.location}/Ebpp-struts/WEB-INF/src/support/VelocityEntityReportComponent/VelocityProcessEntityReportComponent.java.vm"
                          usepkgpath="false"
                    />
        </target>

    Note the entity/filenamePrefix/filenameSuffix options.

    This is being tracked in CAY-79 as a patch, which I'm long overdue to
    rewrite and commit now that I'm a cayenne committer. I REALLY do plan to
    get to this issue in the next week or two as I've recently started a new
    project and I'm near the point where I need to generate an
    entirely-different set of templates now that I'm using JSF instead of
    Struts.

    I'd love to hear as many comments as possible before I start working on it
    so the end result can be a flexible improvement, especially in terms of
    designing a "standard" ant task as my ant usage and understanding is fairly
    mediocre.

    One of the other things I'll be adding is the ability to specify a
    Velocity-tools-style toolbox.xml file to add helper classes into the
    template context.

    Another thing I plan to do is to clean up the context (adding the "classGen"
    attributes directly to the context, and eventually deprecating the use of
    "classGen" in the template).

    My first step needs to be to create some test cases for verifying that the
    template generation works as expected. If anyone has any clean velocity
    template unit testing code, I'd love to work from that.

    So if you have any envisioned use cases that aren't easily handled with the
    current cgen tool, please let me know.



    This archive was generated by hypermail 2.0.0 : Wed Apr 27 2005 - 11:24:32 EDT