@Override public DataSource createDefaultDataSource(DataSourceProps conf) throws ObjectExistsException,SQLException { synchronized (this) { if(null != defaultDataSource){ throw new ObjectExistsException("Default dataSource already exists"); } DataSource ds = createDataSource(conf); this.defaultDataSource = ds; this.allDataSources.put(DEFAULT_DATASOURCE_NAME, ds); notifyDataSourceCreated(DEFAULT_DATASOURCE_NAME, ds, conf.isExportMBean()); return ds; } }
protected void unexportDataSourceMBean(String name, DataSource ds) { if(!(ds instanceof MDataSource)) { return; } mbeanExporter.unexport(objectName(name)); }
public DataSource createDataSource(DataSourceProps conf) throws UnsupportedOperationException, SQLException { DataSource ds = tryCreateDataSource(conf); if(null == ds){ throw new UnsupportedOperationException("The given datasource properties does not supported"); } return ds; }
@Override public boolean tryValidateDataSource(DataSource ds) { try { validateDataSource(ds); return true; } catch (SQLException e) { return false; } }
@Override public void registerDataSource(String name, DataSource ds) throws ObjectExistsException { synchronized (this) { if(allDataSources.containsKey(name)) { throw new ObjectExistsException("DataSource '" + name + "' already exists!"); } allDataSources.put(name, ds); notifyDataSourceCreated(name, ds, exportMBean); } }
@Override public void destroyDataSource(DataSource ds) throws UnsupportedOperationException { if(!tryDestroyDataSource(ds)){ throw new UnsupportedOperationException("The given dataSource does not supported"); } }
@Override public DataSource getDataSource(String name) throws ObjectNotFoundException { DataSource ds = tryGetDataSource(name); if(null == ds){ throw new ObjectNotFoundException("DataSource '" + name + "' not found"); } return ds; }
protected void notifyDataSourceDestroyed(String name,DataSource ds) { unexportDataSourceMBean(name, ds); for(DataSourceListener l : listeners){ l.onDataSourceDestroyed(name, ds); } }
protected void notifyDataSourceCreated(String name, DataSource ds, boolean exportMBean) { if(ds instanceof MDataSourceProxy) { ((MDataSourceProxy) ds).setName(name); } if(exportMBean) { exportDataSourceMBean(name, ds); } for(DataSourceListener l : listeners){ l.onDataSourceCreated(name, ds); } }
public DataSource tryCreateDataSource(DataSourceProps conf) throws SQLException { DataSource ds = null; String name = conf.getDataSourceType(); if(!Strings.isEmpty(name)) { DataSourceFactory dsf = dataSourceFactories.get(name); if(null == dsf) { throw new IllegalStateException("DataSource Type '" + name + "' not found"); } ds = dsf.tryCreateDataSource(conf); }else if(null != defaultDataSourceFactory){ ds = defaultDataSourceFactory.tryCreateDataSource(conf); } if(null == ds && config.isDebug()){ ds = unpooledDataSourceFactory.tryCreateDataSource(conf); } if(null != ds) { validateDataSource(ds); } if(monitoring && null != ds && ! (ds instanceof MDataSourceProxy)) { ds = new MDataSourceProxy(ds, this); } return ds; }
notifyDataSourceCreated(entry.getKey(), entry.getValue(), exportMBean);
@Override public DataSource createDataSource(String name, DataSourceProps props) throws ObjectExistsException,SQLException { synchronized (this) { if(allDataSources.containsKey(name)){ throw new ObjectExistsException("DataSource '" + name + "' already exists"); } if(props.isDefault() && null != defaultDataSource) { throw new ObjectExistsException("Default DataSource already exists!"); } DataSource ds = createDataSource(props); allDataSources.put(name,ds); if(props.isDefault()) { defaultDataSource = ds; } notifyDataSourceCreated(name, ds, props.isExportMBean()); return ds; } }
protected void exportDataSourceMBean(String name, DataSource ds) { if(!(ds instanceof MDataSource)) { return; } mbeanExporter.export(objectName(name), ((MDataSource)ds).getMBean()); }