With i-net Clear Reports it is possible to use Java Beans as data source for a report. The idea is to avoid executions of SQL queries if the data is already available in an application. For many enterprise applications Java Bean objects represent the business data. Now these objects can be used as data source for report generation. It is also possible to design such reports with i-net Designer. The main field of application will be application servers and Servlet environments which uses just Java Beans. Java Beans can be used as data source for reports. This feature is addressed to developers of applications using i-net Clear Reports and needs some own developing.
The base class for this feature is com.inet.report.database.beans.BeanDataSourceManager. This class is providing the Java Beans of the application which is requested by i-net Clear Reports. The figure shows two use cases how a bean data source will be used.
If reports are executed in the application server then the class DatabaseBean will work as the driver for the bean data source. This means that the configured BeanDataSourceManager will be called to return the data for the Java Beans.
If reports are executed outside of the application server the data needs to be requested from the application server. For this purpose there is a Servlet inside the i-net Clear Reports context which communicates between the BeanDataSourceManager and the external application.
The BeanDataSourceManager will be used by i-net Clear Reports to query the JavaBeans for a report. Therefore an implementation of BeanDataSourceManager must be present inside the application server. The implementation class (must be public, and must have a public constructor with no parameters) will be called by i-net Clear Reports. The following methods need to be implemented:
public String[] getAllBeanClassNames(String user, String password) throws TransferServletException;
This method is called by i-net Clear Reports to determine which Java Beans are available as data source for a report. An implementation should return the package-qualified names of the Java Bean classes which can be used by a report. A user/session management can be implemented by providing different names for different users. If the authentication fails (e.g. invalid user/password) a TransferServletException should be thrown.
public List getBeanData(String beanClassname, String user, String password) throws TransferServletException;
This method is called by i-net Clear Reports at report execution if the Java Bean is used as “table”. An implementation should return the data containing instances of the provided Java Bean name. By identifying the user/session different data can be returned for different users/sessions. If the authentication fails (e.g. invalid user/password) a TransferServletException should be thrown.
public List getBeanData(String beanClassname, String param, String user, String password)throws TransferServletException;
This method is called by i-net Clear Reports at report execution if the Java Bean is used as “stored procedure”. An implementation should return the data containing instances of the provided Java Bean name. By identifying the user/session different data can be returned for different users/sessions. If the authentication fails (e.g. invalid user/password) a TransferServletException should be thrown. The difference to the method above is that the method argument param can be used to filter the data in any way. The argument param is handled like a stored procedure parameter and can be specified as a prompt for the report.
public void destroy();
This method is called by the Servlet environment or application server if the application is shut down. So an implementation could do any clean-up required here.
The implementation class of BeanDataSourceManager and the Java Bean classes have to be on classpath when i-net Clear Reports is executed. Usually the jar archives containing the classes should be in the WEB-INF/lib sub directory of the Servlet context.
Using the API of i-net Clear Reports a DataSourceConfiguration for a bean data source can be created like this. If you want to use the bean data source in your application only, this means not using it in i-net Designer or any other application outside the application server, then only the class name of the BeanDataSourceManager implementation class is needed. If you implemented a user/session management in this implementation you also need the user name and password. The code to create a DataSourceConfiguration would then look like this:
DataSourceConfiguration dsc = DataSourceConfigurationManager.createDataSourceConfiguration( "SampleBeanDataSource",DataSourceConfigurationManager.USER_PREFERENCES); dsc.setDatabaseClassname("com.inet.report.DatabaseBean"); dsc.setUser("user"); dsc.setPassword("password"); dsc.addProperty("beanDataSourceManager", "samples.beans.BeanDataSourceManagerImpl");
If you want to use the bean data source in i-net Designer or any other application outside the application server you need to specify the Servlet path too. This is the path to the TransferServlet used for communication with the application server. The format is the following:
http://<server>:<port>/<reporting context>/TransferServlet
For a typical installation of i-net Clear Reports into the Servlet context “reporting” in a local Tomcat the additional call would look like this:
dsc.addProperty("servletPath","http://localhost:8080/reporting/TransferServlet");
i-net software strives to provide accurate product documentation. Please give us your feedback using the form below.
NOTE: This form is for documentation feedback only. For technical assistance, please send an email to clearreports@inetsoftware.de.