You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Daniel Toffetti <dt...@yahoo.com.ar> on 2009/11/04 20:19:39 UTC

Code Generation for Stored Procedures

Hi,

    I'm trying Cayenne Modeler, I can't find a way to make the code generation
task to let me select procedures for code generation, is this even possible ?

Regards,

Daniel



Re: Code Generation for Stored Procedures

Posted by Andrus Adamchik <an...@objectstyle.org>.
3.0 features DataMap templates (i.e. generation of a class for the  
DataMap itself). Currently it places mapped SelectQueries in this  
class. Unfortunately still no support for ProcedureQueries or just  
Procedures. Something we definitely need to add in the future.

Andrus

On Nov 4, 2009, at 9:19 PM, Daniel Toffetti wrote:

> Hi,
>
>    I'm trying Cayenne Modeler, I can't find a way to make the code  
> generation
> task to let me select procedures for code generation, is this even  
> possible ?
>
> Regards,
>
> Daniel
>
>
>


Re: Code Generation for Stored Procedures

Posted by Adrian Wiesmann <aw...@somap.org>.
Hi Daniel

>     Is this possible writing custom templates ??

Probably yes. We did not exactly write custom templates for SPs, but we
did write some for BusinessObjects, DataTables, DataRows and DataRowKeys.
Which are basically templates for several patterns we implemented.

Have a look at our code generator. While this is not 100% the solution to
your problem this is hopefully some inspiration for your own solution :)

http://somap.svn.sourceforge.net/viewvc/somap/codegen/src/

The templates are within the /rsrc folder, the Generator and the targets
are within the /org directory.

Oh and for the ones wondering why we generate that many (different)
classes. We use BusinessObjects to implement use cases which affect more
than one DataTable. DataTables contain all the logic for one table,
DataRows are basically only representations of records from the database.
And DataRowKeys are strongly typed primary keys. 

With this construct it becomes possible to define a data binding language
/ engine which can be used to bind the data from a data context to a UI
during design time. This is what we do with Gozer, but that is now
completely OT :)

Cheers,
Adrian

Re: Code Generation for Stored Procedures

Posted by Michael Gentry <mg...@masslight.net>.
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:

http://cayenne.apache.org/doc/cgen.html

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} )
  ...
#end

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.

Thanks,

mrg


On Wed, Nov 4, 2009 at 3:07 PM, Daniel Toffetti <dt...@yahoo.com.ar> wrote:
> Michael Gentry <mgentry <at> masslight.net> 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:
>>
>> http://cayenne.apache.org/doc/stored-procedures.html
>>
>> 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
>
>
>

Re: Code Generation for Stored Procedures

Posted by Daniel Toffetti <dt...@yahoo.com.ar>.
Michael Gentry <mgentry <at> masslight.net> 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:
> 
> http://cayenne.apache.org/doc/stored-procedures.html
> 
> 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



Re: Code Generation for Stored Procedures

Posted by Michael Gentry <mg...@masslight.net>.
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:

http://cayenne.apache.org/doc/stored-procedures.html

mrg


On Wed, Nov 4, 2009 at 2:19 PM, Daniel Toffetti <dt...@yahoo.com.ar> wrote:
> Hi,
>
>    I'm trying Cayenne Modeler, I can't find a way to make the code generation
> task to let me select procedures for code generation, is this even possible ?
>
> Regards,
>
> Daniel