Reputation: 436
I have a database I need to access using stored procedures. So for each stored procedure's return type, I want to create a entity.
Are there any tools pout there that can generate these entity classes for me? preferred even a tool that can generate the code to retrieve the dataset from the stored procedure.
I am all for DRY principle, so if I can generate this, it would be great!
I am not interested in ORM, JPA, Hibernate or what-so-ever because I cannot access the tables anyways.
The DB we use is PostgreSQL.
Upvotes: 4
Views: 2169
Reputation: 622
Consider using Spring's JdbcTemplate
, StoredProcedure
and related classes to save yourself work in coding your stored procedure calls. Spring has good support for the low-level JDBC stuff and accessing your database in an object-oriented way.
You could use Velocity to generate classes to provide a Java interface to your stored procedures. If you have more than a few stored procedures it could be worth the effort to write the Velocity templates.
As part of the generation you can automate the mapping between Java types, JDBC types and native database types, which often have subtle differences between each other, for example java.util.Date
versus java.sql.Date
versus the database's own date type, or big differences, e.g. LOBs and cursors.
If your stored procedure results need to be mapped to complex objects, i.e. entity or domain classes, you'll probably have to write these yourself, but you could possibly generate the database interface and automate mapping the results to your classes.
Upvotes: 2