Re: Some ideas extending Cayenne

From: Mike Kienenberger (mkienen..mail.com)
Date: Tue Aug 14 2007 - 10:29:29 EDT

  • Next message: Andrus Adamchik: "Re: NPE in DataDomainQueryAction.java"

    On 8/14/07, Adrian Wiesmann <awiesman..omap.org> wrote:
    > Talking about generating classes from a DataMap. What would be the best
    > way to generate personalised classes from a DataMap? I want to create at
    > least two classes per DataObject. Would writing my own set of Velocity
    > template transformations make sense? Or did I miss some hook in Cayenne
    > which I could use? Afaik the cgen Ant task is not that flexible?

    The cgen Ant task is very flexible. I have generated entire web
    applications directly from the database model using cgen ant task and
    templates. I think the modeler now supports most of the cgen ant
    task options and you can also use the modeler if you want.

    Here's a couple of examples:

            <target name="entity stub" depends="failure check"
    description="internal:generate entity stub">
            <mkdir dir="${dataMapModelPackageDir}/entity/stub/generated"/>
                <cgen map="${template.datamap}"
                        additionalMaps="${additional.template.datamaps}"
                version="1.2"
                makepairs="false"
                overwrite="true"
                        mode="entity"
                        outputPattern="_*StubImpl.java"
                destDir="${dataMapModelPackageDir}/entity/stub/generated"
                        superpkg="${dataMapModelPackage}.entity.cayenne.generated"
                        template="${template.superclass.stub}"
                usepkgpath="false">
                </cgen>
            <mkdir dir="${dataMapModelPackageDir}/entity/stub"/>
                <cgen map="${template.datamap}"
                        additionalMaps="${additional.template.datamaps}"
                version="1.2"
                makepairs="false"
                overwrite="false"
                        mode="entity"
                        outputPattern="*StubImpl.java"
                destDir="${dataMapModelPackageDir}/entity/stub"
                        superpkg="${dataMapModelPackage}.entity.cayenne.generated"
                        template="${template.subclass.stub}"
                usepkgpath="false">
                </cgen>
        </target>

                <vppconfig id="vppconfig.datamap" >
                    <context>
                        <property key="dataMapName" value="${dataMapClassPrefix}" />
                        <property key="dataMapPkg" value="${dataMapPkg}" />
                                    <tool key="metaDataTool" classname="com.xyz.velocity.tool.MetaDataTool" />
                    </context>
                    <engine>
                      <property key="file.resource.loader.path" add="yes"
    value="${java.templates}" />
                    </engine>
                </vppconfig>

        <target name="datastore interface" depends="failure check"
    description="internal:generate datastore">
            <mkdir dir="${framework-cayenne.java.src.generated}/datastore"/>
                <cgen map="${template.datamap}"
                        additionalMaps="${additional.template.datamaps}"
                version="1.2"
                makepairs="false"
                overwrite="true"
                        mode="datamap"
                        includeEntities="${template.entity}"
                    template="${java.templates}/_DataMapDataStore.java.vm"
                destDir="${framework-cayenne.java.src.generated}/datastore"
                    outputPattern="_${dataMapClassPrefix}DataStore.java"
                usepkgpath="false">
                <config refid="vppconfig.datamap" />
                </cgen>
            <mkdir dir="${dataMapModelPackageDir}/business"/>
                <cgen map="${template.datamap}"
                        additionalMaps="${additional.template.datamaps}"
                version="1.2"
                makepairs="false"
                overwrite="false"
                        mode="datamap"
                        includeEntities="${template.entity}"
                    template="${java.templates}/DataMapDataStore.java.vm"
                destDir="${dataMapModelPackageDir}/business"
                    outputPattern="${dataMapClassPrefix}DataStore.java"
                usepkgpath="false">
                <config refid="vppconfig.datamap" />
                </cgen>
        </target>



    This archive was generated by hypermail 2.0.0 : Tue Aug 14 2007 - 10:29:59 EDT