cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Gentry <>
Subject Re: Code Generation for Stored Procedures
Date Wed, 04 Nov 2009 21:07:12 GMT
Ah, that kind of code generation ...

I'm not aware of a standard template/etc that can generate Java code
for accessing the stored procedure for you.  Maybe someone else on the
list has done so before and can chime in.

As for writing your own, I'm not sure this is possible.  If you look at:

It seems to me that even though you pass the DataMap (which included
the stored procedures) to cgen, I think it only processes ObjEntities
(it would skip the SPs).  That being said, it might be possible to
tell cgen to only process one entity, and from that entity get the
data map, and from the data map get the procedures.

In your template, that would be something like:

#foreach( $sp in ${classGen.entity.dataMap.procedures} )

That is probably completely wrong and I haven't thought about it too
much and it would put all the SPs in one file, but perhaps it'll help
in some small way.



On Wed, Nov 4, 2009 at 3:07 PM, Daniel Toffetti <> wrote:
> Michael Gentry <mgentry <at>> writes:
>> Hi Daniel,
>> I'm assuming you've used the "Create Stored Procedure" button in
>> Cayenne Modeler?  This doesn't actually create the stored procedure
>> itself (you can't type the SP definition into the modeler).  What it
>> does is define/model a SP that you can use Cayenne to call through
>> your code.  This probably isn't documented very well, but here is what
>> we currently have for calling the SP in your code:
>> mrg
>    Thanks for the link, I've read it already. Ohh, now I understand,
> sorry if I wasn't clear enough.
>    The stored procedures are already implemented in the database and
> the modeler retrieves them, but I was expecting some kind of code
> generation of a "dao" kind of class, think of something like this:
> public class MyCustomProcSPDAO {
>    private Double outputParam;
>    public Collection<ExpectedResultClass> execute(String param1,
>                                                   Integer param2)
>        ProcedureQuery query = new ProcedureQuery("MyCustomProc");
>        query.addParam("param1", param1);
>        query.addParam("param2", param2);
>        QueryResponse result = ctxt.performGenericQuery(query);
>        // retrieve output parameters
>        outputParam = <<...>>
>        //retrieve results as a type safe collection
>        Collection<ExpectedResultClass> resultCollection = <<...>>
>        return resultCollection;
>    }
>    public Double getOutputParam() {
>        return outputParam;
>    }
> }
>    Is this possible writing custom templates ??
> Thanks and regards,
> Daniel

View raw message