Re: <cgen> Ant task and makepairs attribute

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Wed Apr 27 2005 - 11:51:00 EDT

  • Next message: Joshua Pyle: "Re: how to re-order a relationship"

    On Apr 27, 2005, at 11:26 AM, Mike Kienenberger wrote:

    > 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 not following this exactly. My only desire at this point was to
    have <cgen> avoid generating the subclasses entirely, but still
    generate the _Superclass.java files.

    > 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.

    Cool. An Ant way to do that filename mapping is using the <mapper>
    type:

            http://ant.apache.org/manual/CoreTypes/mapper.html

    > 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.

    Ewww.... sorry to hear about the JSF pain. Join us in Tapestry Land -
    we're happy!

    > 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.

    I know a little 'bout Ant ;) so I'd be happy to help out to make the
    tasks fit nicely.

    > 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.

    On this front, I recommend having a look at VPP. It is incredibly well
    done wrapper around Velocity. I like how the VelocityEngine is
    configurable through it. See the "manual" page for details.

            http://vpp.sourceforge.net/

    Also note that it does Antlib nicely too.

    > 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).

    That's deeper under the covers of Cayenne than I've yet gone. But I do
    appreciate the details and its possible I'll end up doing custom
    templates I suspect.

    > 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.

    I don't have anything handy myself.

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

    All I can think of now is the ability to turn off subclass generation
    without the combining that makepairs="true" does.

    Again, I'm happy to offer advice or lend a hand with the Ant task
    efforts.

            Erik



    This archive was generated by hypermail 2.0.0 : Wed Apr 27 2005 - 11:52:26 EDT