views:

85

answers:

1

I have been reporting with jasperreports and JPA, all this reports are just "catalogs" in which the only information is an entity or some times an entity with it's related entities.

Now i have to design reports with very complex information (grouping, summarization, fields not part of an entity and so on) which is not possible with my entities (Yes i know that i can modify my design but i do't think it's good for my app).

I've been thinking in different alternatives, like passing a jdbc connection even when this implies to create methods in my classes to pass this object to the view (Which generates the report).

Another one is to create another context (application) that accesses the data base in is own way (something like BI), so this application would be separated from my original application.

Hope some one can comment or give me a better way to achieve this.

By the way, my framework it's spring.

Thank you.

+1  A: 

I'd recommend using the JDBC connection option when generating a complex report, if only for the flexibility gained by writing the SQL directly. But having a JDBC connection trespassing in your view layer does not sound good, so without knowing much about Spring, I say move the actual report generation down to the service layer having it return the JasperPrint object (which is serializable) to the view layer where it can be presented.

Here is a plain-vanilla RMI example, pretty much the way I do it. I suppose this can be translated into a Spring bean of some sort.

public interface ReportService extends Remote {
  public JasperPrint fillReport(final JasperReport report, final Map reportParameters)throws RemoteException, JRException;
}

public class ReportServiceImpl implements ReportService {

  final Connection connection;

  public ReportServiceImpl(final Connection connection) {
    this.connection = connection;
  }

  public JasperPrint fillReport(final JasperReport report, final Map reportParameters) throws RemoteException, JRException {
    return JasperFillManager.fillReport(report, reportParameters, connection);
  }
}

One modification that springs to mind, no pun intended, would be to have the fillReport method take a report name or path as an argument instead of the actual JasperReport object and have the service layer load it (and cache it, since loading the report is a relatively expensive operation).

Let me know if you want me to flesh out some parts of this example, I must warn you though that I am a Desktop/Swing programmer with only a rudimentary experience in web front-ends.

darri
Thank you for your opinion it's very important, i agree that passing the Connection object to the view layer its is a very bad idea it sounds much better to generate the report in the service layer. I will be very grateful if you can provide me those examples. thank you.
OJVM
i forgot to write my e mail this is ojvm24 at gmail dot com
OJVM
Right now i'm passin the connection to the view layer, but i'll try your solution, thank you.
OJVM