Wednesday, March 22, 2006

Open Source caching system: "memcached"

memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.

..

It uses libevent to scale to any number of open connections (using epoll on Linux, if available at runtime), uses non-blocking network I/O, refcounts internal objects (so objects can be in multiple states to multiple clients), and uses its own slab allocator and hash table so virtual memory never gets externally fragmented and allocations are guaranteed O(1).

@link

Monday, March 13, 2006

How does Jasper subreporting works?

This is a simple get-started guide on how the subreporting works in Jasper. This is by no means a detailed reference. If you are using ireports, you can drag-drop the sub-report icon from the pallette. You can double click the grey area to specify the sub-reporting parameters that will identify your already created stand-alone sub-repport.


Under the Subreport/Connection/Datasource expression tab, you can specify the connection or data source. To use the same connection as your parent report, select Use conenction expression and use the value $P{REPORT_CONNECTION}

Under subreport, you can specify different ways to invoke your subreport file. You can also pass your parameters here. Define the parameters correctly. For example, if your subreport is expecting ID as one of its parameter, the expression for this parameter will look like: $F{ID}

If you are specifying String under the expression class, do not forget the double quotes: "myChildReport.jasper". You can also embed a few lines of code under the subreport expression and supply it with URL, File, InputStream or the JasperReport objects. Variably, you can have a static factory method inside your code, that can be included here. Caution: You might loose the flexibility of previewing your report in ireports.


After you close this dialog, ireports will add the subreport xml inside the template. At runtime, your specified jasper subreport(class) will be loaded by the class loader and executed with the supplied parameters. You might face difficulties if you manage to load this sub-report in a seperate class loader.


Happy subreporting!

How to change your subreport paths at runtime?

See the "How does Jasper subreporting works?" article above in order to understand this article. If you use ireports, you can double click the sub-reports block and specify your subreport name. If you select the image expression class as "java.lang.String", you can specify your subreport name(compiled) as a java string. You can specify say mysubreport.jasper and expect the jasper file to be in the folder. You can also specify an absolute path for your sub report. While programming it is best to reduce the dependency on such hardcoded paths in the report template.

Here is the solution:
While creating the report template, always use the filename for your subreport name. At run time, replace this filename with your sub-report absolute path location which can be fetched from a property file. Code below, does exactly the same!

private void changeSubReportPath(JasperDesign jasperDesign)
{
Object[] objExpressions = jasperDesign.getExpressions().toArray();
for (int i=0; i
{
JRDesignExpression jrExpression = (JRDesignExpression)objExpressions[i];
String expressionText = jrExpression.getText();
if ((expressionText.indexOf(".class") != -1) || (expressionText.indexOf(".jasper") != -1))
{
jrExpression.setText("\"" + System.getProperty("report.child.basepath") + expressionText.substring(1));

}

}
}

Reporting frameworks for the open source Java world

Jasper Reports and BIRT are amongst the most popular open source reporting framework for the java world. Jasper had been here for quite some time, while BIRT is relatively new with less third party tool support then Jasper. However at first use BIRT looks very easy to use and nicely designed then its counter part. BIRT is restricted for the eclipse users(Developed and maintained by eclipse.org), but I am pretty sure that quite a few stand alone BIRT reporting tools might already be under development. The basic BIRT plugin is capable of addressing most of your reporting needs. If you compare BIRT vs JASPER side by side, both of them have almost the same features, though the "BI" part of BIRT reads "Business Intelligence" which means BIRT will be doing more then reporting (if not now, may be in future).

Like any other open source software, both these tools are poorly documented. I found it easy to get around with BIRT then with JASPER. Jasper api's give you great flexibility with your programming tasks. Amongst the well known jasper tools, I tried Ireports(standalone), the eclipse plugin and open report. None of them are up to the mark or as good compared to the BIRT eclipse plugin. A good source of documentation for jasper is available in form of a downloadable pdf(JRUltimateGuide.2.2.pdf), only after you some $45's! Just an fyi, most of the explanation in this pdf actually point to the examples folder of the downloadable jasper api source-docs.

BIRT architecture is much cleaner and easy to get around, compared to Jasper. You can import existing style sheets, custom HTML code, XPATH, and most important of all, no intermediate file generation(like compiled file crap!).

Quick links:
If you are working with Jasper, here are your quick links:
@Jasper Home
@ireports, standalone tool to create jrxml files
@eclipse plugin, if you are lost in the eclipse world
@open reports. This tool is more talks and less work.
@quick how to
@api docs

If you are working with BIRT:
@BIRT Home
@BIRT tutorials
@Birt world blog, very informative
@eclipse documentation
@BIRT features
@How to POJO as data source?

Happy Reporting!

Transferring data between relational db and xml

A good document that explains the use of jaxb, hyperjaxb and hibernate to acheive xml to object to relational persistance. Also check hibernate, hyperjaxb and jaxb relative websites.
@link