Skip to main content



      Home
Home » Archived » BIRT » Changing the Data Source on the fly
Changing the Data Source on the fly [message #196683] Thu, 19 October 2006 23:49 Go to next message
Eclipse UserFriend
Re-directed an usage question sent to the birt-report-designer-dev
mailing list.

--------------------------------
Date: Thu, 19 Oct 2006 07:03:24 +0530
From: "Mohit Sang"
Subject: [birt-report-designer-dev] Changing the Data Source on the
fly
To: birt-report-designer-dev@eclipse.org

Hi,
I have 2 databases with the same schema. One is used for testing and the

other one is used in production. I was wondering if BIRT has the
functionality to change the DataSource on the fly.
Is there any file that one could replace or modify so that the Database
URLs
for all the reports change as it is tedious to change all URLs to test
the
reports and change them again to release them.
Thanks
-Mohit
Re: Changing the Data Source on the fly [message #196691 is a reply to message #196683] Thu, 19 October 2006 23:50 Go to previous messageGo to next message
Eclipse UserFriend
Mohit,

You can use the property binding feature to bind the Driver URL data source
property value to that of a BIRT report parameter. In the "Edit Data
Source" dialog, select the "Property Binding" node to specify. This way,
the associated report parameter's value collected at runtime get used to
open the data source connection.

To make a single update to apply to all your report designs' data source
property, you can bind each to a shared report parameter defined in a BIRT
library.
Or, another way is to have each report design uses a shared data source
element defined in a BIRT library.

Linda
Re: Changing the Data Source on the fly [message #196928 is a reply to message #196691] Fri, 20 October 2006 19:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mohit_sang.hotmail.com

Linda,
I want to apply this to all report designs. Can you tell me how to bind a
single source from a birt library?
Re: Changing the Data Source on the fly [message #196936 is a reply to message #196928] Fri, 20 October 2006 19:45 Go to previous messageGo to next message
Eclipse UserFriend
Mohit,
That certainly is possible. The way you accomplish that is by changing
the dbURL at runtime. If you implement the following method, it will reach
into your .rptdesign file and edit the value for the dbUrl. The same
happens for username and password. It is NOT possible, though, (as far as
I know) to change the Driver at runtime this way.
In short, we're taking advantage of the BIRT API to access a special
place in the .rtpdesign file.

In this implementation, we have stored our database configuration
parameters in a table that we access at runtime. To avoid annoying you,
here are the values of the constants that are referred to within the file:

public static final String BIRT_DATA_SOURCE_SLOT_DB_URL = "odaURL";
public static final String BIRT_DATA_SOURCE_SLOT_DB_USER = "odaUser";
public static final String BIRT_DATA_SOURCE_SLOT_DB_PASS =
"odaPassword";

public static final String BIRT_DATA_SET_SLOT_QUERYTEXT =
"queryText";
public static final String LAST_WHERE_FOR_CSV_HEADERS = "WHERE";
public static final String BIRT_DATA_SET_SLOT_DB_PASS =
"odaPassword";


And, finally, the magic method that does this.

protected void populateDatabaseConnectionParameters( IReportRunnable
pDesign )
{
ConfigurationService cs = ConfigurationServiceAccessor.getService();

String dbUrl = cs.getValue( "/t360/framework/reporting",
"reporting.db.url", "" );
String dbUser = cs.getValue( "/t360/framework/reporting",
"reporting.db.userid", "" );
String dbPassword = cs.getValue( "/t360/framework/reporting",
"reporting.db.password", "" );

/** The password comes to us encrypted from the database. This will
decrypt it. */
dbPassword = CipherUtilityWeb.decrypt( dbPassword );

DesignElementHandle deh = pDesign.getDesignHandle();
SlotHandle slotHandle = deh.getSlot(
ReportDesignHandle.DATA_SOURCE_SLOT );
Iterator iter = slotHandle.iterator();

try
{
while( iter.hasNext() )
{
Object obj = iter.next();
OdaDataSourceHandle odaSrcHdl = (OdaDataSourceHandle) obj;
Iterator propIter = odaSrcHdl.getPropertyIterator();

while( propIter.hasNext() )
{
PropertyHandle propHdl = (PropertyHandle) propIter.next();

if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
IReportingConstants.BIRT_DATA_SOURCE_SLOT_DB_URL ) )
{
propHdl.setStringValue( dbUrl );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
IReportingConstants.BIRT_DATA_SOURCE_SLOT_DB_USER ) )
{
propHdl.setStringValue( dbUser );
}
else if( propHdl.getPropertyDefn().getName().equalsIgnoreCase(
IReportingConstants.BIRT_DATA_SOURCE_SLOT_DB_PASS ) )
{
propHdl.setStringValue( dbPassword );
}
}
}
}
catch( Exception e )
{
e.printStackTrace();
}
}
Re: Changing the Data Source on the fly [message #196951 is a reply to message #196928] Fri, 20 October 2006 20:52 Go to previous message
Eclipse UserFriend
Mohit,

Using the BIRT report design perspective, first create a new report library
(File->New->Library). With your .rptlibrary file open and selected, bring up
the Data Explorer view, and create a New Data Source element with your
connection properties. E.g. specify your test db URL in the oda.jdbc's Driver
URL property.

To reference this library's data source element in a report design, switch to
your .rptdesign file. Bring up the Library view, and your .rptlibrary should
be listed in the Resource Folder. Select the library's data source element,
and drag-n-drop it to the Outline view of your .rptdesign.
If you then check the XML Source content of your .rptdesign file, you will see
reference to the library's element, e.g.
<data-sources>
<oda-data-source
extensionID="org.eclipse.datatools.connectivity.oda.flatfile " name="My Library
FF Data Source" id="31"
extends="new_library.My Library FF Data Source"/>
</data-sources>

Now, changes to the connection property in the library's data source element
would be reflected in the associated report designs. You may need to first
close and re-open the rptdesign file in report designer for the UI to refresh
and get the latest value updated in the rptlibrary.

Linda

Mohit Sang wrote:

> Linda,
> I want to apply this to all report designs. Can you tell me how to bind a
> single source from a birt library?
Previous Topic:End-of-Life Support of the Older version of ODA
Next Topic:IllegalStateException after upgrade to 2.1.1
Goto Forum:
  


Current Time: Mon Jul 28 10:58:38 EDT 2025

Powered by FUDForum. Page generated in 0.06081 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top