how to set data source connection string at runtime [message #630691] |
Mon, 04 October 2010 11:14  |
Eclipse User |
|
|
|
Hello, I am new to Birt, and need some help.
1. I like to embed Birt into JSF web application. I can design a report using eclipse, but JDBC connection info is known at runtime. How to set JDBC connection info (connection string, username, password, etc) when running report engine?
2. Similarly, how to set SQL parameters at runtime?
3. Is there a way for BIRT to use query built by Hibernate Criteria API?
Thanks for help.
Dave
|
|
|
Re: how to set data source connection string at runtime [message #630710 is a reply to message #630691] |
Mon, 04 October 2010 11:49   |
Eclipse User |
|
|
|
Dave,
1 - There are a lot of different ways to do this if you are using the
API. You can pass them in as report parameters or in a session object.
You can then use the property binding feature within the dataset
editor to set them based on how you pass them in. You can also set them
in report script. For example assume you pass them is a parameter like
//this is a report parameter
task.setParameter("myrunitmeconnectionurl",yourconnectionurl);
Then in the beforeOpen script of the dataset you would set it like:
this.setExtensionProperty("odaURL",params["myruntimeconnectionurl "].value);
You can also set it in the property binding tab of the datasource
editor. Just use the expression params["myruntimeconnectionurl"].value
You can pass in the connection object as well. This will ignore all
design time settings.
task.getAppContext().put("OdaJDBCDriverPassInConnection", myconn);
//specify whether to close connection after use or not
task.getAppContext().put("OdaJDBCDriverPassInConnectionCloseAfterUse ",
true);
2 - In the dataset editor you can set up dataset parameters by using the
? in the sql editor. For example select * from orders where ordernumber = ?
This will create a dataset parameter. You can set the default value for
this parameter or create a report parameter and link the dataset to the
report parameter(data set editor parameters tab). If you link it to a
report parameter you can just use the task and set the report parameter
which will automatically pass to the dataset parameter when the report
is executed.
3 - Jboss provides a Hiberate ODA to run HQL instead of using the BIRT
SQL datasource. Is this what you want?
Jason
On 10/4/2010 11:14 AM, Dave wrote:
> Hello, I am new to Birt, and need some help.
>
> 1. I like to embed Birt into JSF web application. I can design a report
> using eclipse, but JDBC connection info is known at runtime. How to set
> JDBC connection info (connection string, username, password, etc) when
> running report engine?
>
> 2. Similarly, how to set SQL parameters at runtime?
>
> 3. Is there a way for BIRT to use query built by Hibernate Criteria API?
>
> Thanks for help.
>
> Dave
|
|
|
|
|
|
Re: how to set data source connection string at runtime [message #631290 is a reply to message #631223] |
Wed, 06 October 2010 15:50   |
Eclipse User |
|
|
|
Dave
Is your os the response.getOutputStream object?
Un-comment the html lines and comment out the pdf ones. You can also
render to a file output and look at the image source tag to see what is
happening.
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//get report name and launch the engine
//resp.setContentType("text/html");
resp.setContentType( "application/pdf" );
resp.setHeader ("Content-Disposition","inline; filename=test.pdf");
String reportName = req.getParameter("ReportName");
ServletContext sc = req.getSession().getServletContext();
this.birtReportEngine = BirtEngine.getBirtEngine(sc);
IReportRunnable design;
try
{
//Open report design
design = birtReportEngine.openReportDesign(
sc.getRealPath("/Reports")+"/"+reportName );
//create task to run and render report
IRunAndRenderTask task = birtReportEngine.createRunAndRenderTask(
design );
//task.getAppContext().put("BIRT_VIEWER_HTTPSERVLET_REQUEST ", req );
//set output options
// HTMLRenderOption options = new HTMLRenderOption();
// options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML) ;
// options.setOutputStream(resp.getOutputStream());
// options.setImageHandler(new HTMLServerImageHandler());
// options.setBaseImageURL(req.getContextPath()+"/images");
// options.setImageDirectory(sc.getRealPath("/images"));
PDFRenderOption options = new PDFRenderOption();
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);
//resp.setHeader( "Content-Disposition", "inline;
filename=\"test.pdf\"" );
options.setOutputStream(resp.getOutputStream());
task.setRenderOption(options);
//run report
task.run();
task.close();
}catch (Exception e){
e.printStackTrace();
throw new ServletException( e );
}
}
The viewer servlet code is in the org.eclipse.birt.report.viewer
project in the source tree.
Jason
On 10/6/2010 11:50 AM, Dave wrote:
> Hi Jason,
>
> Thanks!
> I created a servlet to render a report design. but I could not make the
> created chart image show on the web page. The code for image setup:
>
> HTMLRenderOption options = new HTMLRenderOption();
>
> options.setOutputStream(os);
> options.setOutputFormat("html");
>
> String imageBaseURL = "/bi/images";
> options.setBaseImageURL(imageBaseURL);
> String imageDir = <a local dir>
> options.setImageDirectory(imageDir);
> options.setEmbeddable(true);
> task.setRenderOption(options);
> ....
> ----------
> On the server side, the chart image was created successfully.
> Is there an example for rendering in HTML? I am using the latest BIRT
> 2.6.1.
>
> I like to see the Viewer servlet source code. I checked the CVS source
> code, but could not find the servlet :
>
> org.eclipse.birt.report.servlet.ViewerServlet
>
> where can I find the source code?
>
> Thanks
> Dave
|
|
|
|
|
|
|
Re: how to set data source connection string at runtime [message #643407 is a reply to message #643107] |
Mon, 06 December 2010 13:48  |
Eclipse User |
|
|
|
Is myruntimeconnectionurl a report parameter?
if it is you could do something like:
in beforeOpen of the datasource:
this.setExtensionProperty("odaURL",params["myruntimeconnectionurl "].value);
in your code
task.setParameter("myruntimeconnectionurl",""jdbc:mysql://localhost/mysql"");
Jason
On 12/4/2010 9:40 AM, Shahab wrote:
> Can any one give me an example of connection url plz?
> task.setParameter("myrunitmeconnectionurl",??????????);
|
|
|
Powered by
FUDForum. Page generated in 0.20416 seconds