ObjectMagic.org

Back to home

JDO Report

JDO Report provides JDO support in JasperReports.
Here you will find the links for the download.

I strongly believe that JDO is really a superior specification about Java persistence, with a wide number of implementations available.
Nevertheless, I think that the best way to promote JDO technology, at this point in time, is to provide packages/products/solutions built on JDO.
At this time, JDO has no reporting capabilities. If you use an implmentation based on a RDBMS backend it is possible to use several reporting products, both commercial and open source.
You have the products, but also the drawbacks: the object-relational impedence mismatch is back again !

JasperReports has a nice model for building data source providers that fits well in JDO model. More, JasperReports supports query executer plug-in, so that data sources can be created by the engine itself.
Well, I am not a big fan of this model because I like to think to reports as templates for rendering of different data sources. I mean that you could use the same report layout for the output of data produced with different queries.

Architecture of the Data Source

The main capability of a JasperReports data source is the providing of fields values for the current object under rendering. JDO Report data source implementation makes use of a org.omj.core.reflect.NamedFeatureExtractor (see omj-core package) so that you can achieve a huge flexibility in the definition of fields.
In fact, actually NamedFeatureExtractor implementations are based on JEDI that allows you to easily define Java expression for object navigation. More, JEDI expressions can be configured in a XML file.

The following example is extracted from the ditribution

<extractors>

	<feature-extractor-factory name="jedi" java-class="org.omj.core.reflect.xml.JDOMJediFeatureExtractorFactory"/>
	<feature-extractor name="REGION_NAME" description="Name of region" factory="jedi" path-expr="region.getName()" arg-name="region"/>
	<feature-extractor name="CITY_NAME" description="Lastname" factory="jedi" path-expr="city.getName()" arg-name="city"/>
	<feature-extractor name="CITIES" description="Work Date" factory="jedi" path-expr="region.getCities()" arg-name="region"/>

</extractors>
  
You can see the definition of 3 fields. The names corresponds the the ones used in the report. A sample data source can be created and used in a report as follows
        JRDataSource jrds;
        JRFieldFetcher jrff = createJRFieldFetcher();
        Collection c = new ArrayList();
		//add some objects to the collection
        jrds = new JRDelegateFetchDataSource(c, jrff);
  
        Map parameters = new HashMap();
        parameters.put("ReportTitle", "The First Jasper Report Ever");
        JRDataSource jrds = createDataSource();
        JRDelegateFetchDataSource jrdfds = (JRDelegateFetchDataSource) jrds;
        
        JasperRunManager.runReportToPdfFile(fileName, parameters, jrds);
  
The field fetcher is loaded from file as follows
        JRFeatureExtractorFieldFetcher jrff = null;
        String xmlconf = "/META-INF/feature-extractor.xml";
		// This is a map of names to FeatureExtractor
        FeatureExtractorRegistry registry = new DefaultFeatureExtractorRegistry("main");
        JDOMFeatureExtractorRegistryLoader jdoml = new JDOMFeatureExtractorRegistryLoader();
        jdoml.load(xmlconf, registry);
		// This is an NamedFeatureExtractor backed on a FeatureExtractorRegistry 
        NamedFeatureExtractor fx = new DelegatingNamedFeatureExtractor(registry);
        jrff = new JRFeatureExtractorFieldFetcher(fx);
  

The JDO Query Executer

JDO implementation of JasperReports QueryExecuter interface defines "jdoql" as query language name. JDO queries are structured objects and 1.x version of the spec does not foresee the possibility of defining all the compoenents (i.e., paramenters, variables, imports etc) in a single pasrseable string, as JDO2 does.
The JDO Query Executer implemented here supports 1.x queries and due to the limitations of JasperReports query tag, what is put in the report is simply the name of a query specification present in a registry (see omj-jdocore package).
In the named package you can find an implementation of a query registry based on a XML file. Here follows an example
<jdo-queries>

	<jdo-query name="jpmquery" candidate-class="org.omj.jpm.domain.impl.WorkUnitImpl">
		<jdoql-import>org.omj.jpm.domain.spec.*</jdoql-import>
		<jdoql-param name="lastname" java-class="java.lang.String"/>
		<jdoql>((org.omj.jpm.domain.impl.WorkerImpl) worker).lastName == lastname</jdoql>
	</jdo-query>

</jdo-queries>
  
The JDO Query Executer needs 3 builtin parameters to be passed (see org.omj.report.jasper.jdo.JRJdoQueryExecuterFactory for the relevant constants for the parameters names):
  • the javax.jdo.PersistenceManager,
  • the org.omj.core.reflect.NamedFeatureExtractor used to create the data source that wraps the JDO query result
  • the org.omj.jdo.query.JdoQueryRegistry to get the query specification referenced in the report.
    Query specific parameters can be omitted in the declarative part of the report.

    For any comment on this site, drop a mail to webmaster

    For any comment, question, suggestion on the various packages contact voodoo@objectmagic.org (Yes, even for bug report)