... until the collector arrives ...

This "blog" is really just a scratchpad of mine. There is not much of general interest here. Most of the content is scribbled down "live" as I discover things I want to remember. I rarely go back to correct mistakes in older entries. You have been warned :)

2007-09-24

BIRT Report Data Sources

Here is a code snippet that will replace the design-time connection parameters in all of the ODA/JDBC data sources that use a particular driver:

private void fixupDesignTimeJdbcDataSources(ReportDesignHandle reportDesignHandle) {
    String jdbcDriver = "my.driver.Class";
    String jdbcUrl = "jdbc:mynewurl";
    String jdbcUser = "myuserid";
    String jdbcPassword = "mypassword";
    for (Iterator<?> d = reportDesignHandle.getDataSources().iterator(); d.hasNext();) {
        Object dataSource = d.next();
        if (dataSource instanceof OdaDataSourceHandle) {
            OdaDataSourceHandle odaDataSource = (OdaDataSourceHandle) dataSource;
            if (ODA_JDBC_EXTENSION_ID.equals(odaDataSource.getExtensionID())
                    && jdbcDriver.equals(odaDataSource.getProperty(ODA_DRIVER_CLASS))
                    && null != odaDataSource.getProperty(ODA_URL)) {
                try {
                    odaDataSource.setProperty(ODA_URL, jdbcUrl);
                    odaDataSource.setProperty(ODA_USER, jdbcUser);
                    odaDataSource.setProperty(ODA_PASSWORD, jdbcPassword);
                } catch (SemanticException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    }
}

private static final String ODA_JDBC_EXTENSION_ID = "org.eclipse.birt.report.data.oda.jdbc"; //$NON-NLS-1$
private static final String ODA_DRIVER_CLASS = "odaDriverClass"; //$NON-NLS-1$
private static final String ODA_URL = "odaURL"; //$NON-NLS-1$
private static final String ODA_USER = "odaUser"; //$NON-NLS-1$
private static final String ODA_PASSWORD = "odaPassword"; //$NON-NLS-1$

Blog Archive