/** * Adds a new data source to the repository. * * @param dsmInfo The meta information of the data source to be added. */ public void addDataSource(DataSourceMetaInfo dsmInfo) throws DataSourceException { if (log.isDebugEnabled()) { log.debug("Adding data source: " + dsmInfo.getName()); } if (!dsmInfo.isSystem()) { this.persistDataSource(dsmInfo); } this.registerDataSource(dsmInfo); if (!dsmInfo.isSystem()) { this.notifyClusterDSChange(dsmInfo.getName()); } }
private synchronized void registerDataSource(DataSourceMetaInfo dsmInfo) throws DataSourceException { /* if a data source is already registered with the given name, unregister it first */ CarbonDataSource currentCDS = this.getDataSource(dsmInfo.getName()); if (currentCDS != null) { /* if the data source is a system data source, throw exception */ if (dsmInfo.isSystem()) { throw new DataSourceException( "System datasource " + dsmInfo.getName() + "can not be updated."); } this.unregisterDataSource(currentCDS.getDSMInfo().getName()); } if (log.isDebugEnabled()) { log.debug("Registering data source: " + dsmInfo.getName()); } Object dsObject = null; boolean isDataSourceFactoryReference = false; DataSourceStatus dsStatus; try { JNDIConfig jndiConfig = dsmInfo.getJndiConfig(); if (jndiConfig != null) { isDataSourceFactoryReference = jndiConfig.isUseDataSourceFactory(); } dsObject = this.createDataSourceObject(dsmInfo, isDataSourceFactoryReference); this.registerJNDI(dsmInfo, dsObject); dsStatus = new DataSourceStatus(DataSourceStatusModes.ACTIVE, null); } catch (Exception e) { String msg = "Error in registering data source: " + dsmInfo.getName() + " - " + e.getMessage(); log.error(msg, e); dsStatus = new DataSourceStatus(DataSourceStatusModes.ERROR, msg); } /* Creating DataSource object , if dsObject is a Reference */ if (isDataSourceFactoryReference) { dsObject = this.createDataSourceObject(dsmInfo, false); } CarbonDataSource cds = new CarbonDataSource(dsmInfo, dsStatus, dsObject); this.dataSources.put(cds.getDSMInfo().getName(), cds); }