/** * Create connection from the data-source selected at this view * * @return * @throws SQLException */ public static Connection getConnectionFromSelectedDatasource() throws SQLException { String datasourceName = CommonIDEParameters.get(SELECTED_DATASOURCE_NAME); DataSource dataSource = null; if ((datasourceName == null) || datasourceName.equals(DEFAULT_DATASOURCE_NAME)) { logger.debug("No selected datasource found. Make use of the default one"); dataSource = DataSourceFacade.getInstance().getDataSource(CommonIDEParameters.getRequest()); if (dataSource != null) { Connection connection = dataSource.getConnection(); return connection; } logger.error("Trying to use the default datasource, but it is null"); } else { logger.debug(String.format("Selected datasource found %s", datasourceName)); dataSource = DataSourceFacade.getInstance() .getNamedDataSource(CommonIDEParameters.getRequest(), datasourceName); if (dataSource != null) { Connection connection = dataSource.getConnection(); return connection; } logger.error( String.format( "Selected datasource found %s, but the datasource itself is null", datasourceName)); } return null; }
public static String getSelectedDatasourceName() throws SQLException { return CommonIDEParameters.get(SELECTED_DATASOURCE_NAME); }