Reports developed through the Birt Report tool are often run in a unified production environment data source, but are often developed as a data source for development testing, which requires the ability to switch between two environments at any time. At present, in response to this problem, the public can retrieve the information, basically through the data source of the Beforeopen event, through the way of writing scripts to solve, this way is still more complex, in the number of reports, the number of developers, developers need to pay attention to the place is a bit more, not perfect. The processing of this article will be able to fundamentally solve the problem.
Can not make a fuss on the report, so that either need to modify the report file, or need each report to inherit a common library file, only in Birt Open API to find a way. By studying the source code of the Birt, we found the following solution, which basically solves the problem perfectly.
Ireportengine birtengine = ...; ireportrunnable runnable = Birtengine.openreportdesign (...); I Runandrendertask runandrendertask = Birtengine.createrunandrendertask (runnable); Map AppContext = Runandrendertask.getappcontext (); Connection conn = ...; Appcontext.put (Iconnectionfactory.pass_in_connection,conn);
This scenario requires that the connection be manually acquired at run time, and then there are issues such as closing the connection.
This method has been passed in Birt's 4.2 series and 4.4 series tests, and other versions of Birt have not been validated.
In fact, this appcontext is an important open extension interface of Birt, which can extend and customize many functions of Birt.
Birt Unified Public data source, dynamic switching data source solution