* @return Connection
* @throws org.wso2.carbon.reporting.api.ReportingException if failed to get connection for data source
*/
public Connection getJDBCConnection(String dataSourceName) throws ReportingException {
Connection connection = null;
DataSourceRepositoryManager repositoryManager;
DataSource dataSource;
DataSourceInformationRepositoryService repositoryService =
ReportingComponent.getCarbonDataSourceService();
if (repositoryService != null) {
DataSourceInformationRepository datasourceRepo =
repositoryService.getDataSourceInformationRepository();
DataSourceRepositoryHolder dataSourceHelper = DataSourceRepositoryHolder.getInstance();
dataSourceHelper.init(datasourceRepo, null);
repositoryManager = dataSourceHelper.getDataSourceRepositoryManager();
if (repositoryManager != null) {
dataSource = repositoryManager.getDataSource(dataSourceName);
if (dataSource != null) {
try {
connection = dataSource.getConnection();
} catch (SQLException e) {
throw new ReportingException("Failed to get data source connection for "