Which is the correct lifecycle of the BIRT runtime to create multiple reports [message #1240323] |
Thu, 06 February 2014 08:13 |
David Basilashvili Messages: 6 Registered: February 2014 |
Junior Member |
|
|
Hello!
I use runtime BIRT to generate multiple reports. My maven dependency:
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.3.1</version>
</dependency>
How to set up the life cycle of the ReportEngine instance?
The documentation (http://www.eclipse.org/birt/phoenix/deploy/reportEngineAPI.php#reportengine) says: Quote:Therefore, each application should create just one ReportEngine instance and use it to run multiple reports
I use documentation for creation multiple pdf reports with separate run and render tasks. But I have problems. This is my Spring singleton bean:
@Service
@Named("birtSingleton")
public class BirtSingleton implements ReportEngine, InitializingBean, DisposableBean {
@Autowired
BirtPlatform birtPlatform;
@Override
public String getInfo() {
return null;
}
IReportEngine reportEngine;
//this is spring initialize method, it calls when application is started
@Override
public void afterPropertiesSet() throws Exception {
IReportEngineFactory reportEngineFactory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
reportEngine = reportEngineFactory.createReportEngine(birtPlatform.getEngineConfig());
}
@Override
public void generateReport(ReportParameters reportParameters) throws ReportException {
System.out.println("Engine: " + reportEngine);
IReportRunnable reportRunnable;
try {
reportRunnable = reportEngine.openReportDesign(reportParameters.getReportDesignPath());
} catch (EngineException e) {
throw new ReportException("Error opening report design " + reportParameters.getReportDesignPath(), e);
}
try {
BirtDataSourceAccessStrategy dataSourceAccessStrategy = new UrlAccessStrategy();
dataSourceAccessStrategy.changeReportDesign(reportRunnable);
} catch (IOException e) {
throw new ReportException("Error changing DS properties " + reportParameters.getReportDesignPath(), e);
}
IRunTask runTask = reportEngine.createRunTask(reportRunnable);
String rptDocumentFilePath = reportParameters.getFullRptDocumentFilePath();
try {
runTask.run(rptDocumentFilePath);
} catch (EngineException e) {
throw new ReportException("Error report running " + reportParameters.getReportDesignPath(), e);
} finally {
runTask.close();
}
IReportDocument reportDocument;
try {
reportDocument = reportEngine.openReportDocument(rptDocumentFilePath);
} catch (EngineException e) {
throw new ReportException("Error report document opening " + reportParameters.getReportDesignPath(), e);
}
IRenderTask renderTask = reportEngine.createRenderTask(reportDocument);
PDFRenderOption renderOption = new PDFRenderOption();
renderOption.setOutputFileName(reportParameters.getFullReportFileName());
renderOption.setOutputFormat("pdf");
renderTask.setRenderOption(renderOption);
try {
renderTask.render();
} catch (EngineException e) {
throw new ReportException("Error rendering " + reportParameters.getReportDesignPath(), e);
} finally {
renderTask.close();
reportDocument.close();
}
//after each report generation???
reportEngine.destroy();
}
//this method calls when application terminates
@Override
public void destroy() throws Exception {
//or when application terminates???
reportEngine.destroy();
}
}
- When I call reportEngine.destroy() after each report generation:
ReportEngine instance successfully generates first pdf report, but no second generation i get nullPointerException on
reportDocument = reportEngine.openReportDocument(rptDocumentFilePath);
- When I call reportEngine.destroy() in spring termination method destroy():
ReportEngine instance successfully generates all pdf report, but when application running, I can't access pdf files. ReportEngine doesn't release them.
Where can I locate reportEngine.destroy()? Which is the correct usage of reportEngine?
Help me, please
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04205 seconds