@Override public DataSource tryCreateDataSource(DataSourceProps conf) { ensureGetDriverClass(conf); UnPooledDataSource ds = new UnPooledDataSource(); ds.setDriverClassName(conf.getDriverClassName()); ds.setJdbcUrl(conf.getJdbcUrl()); ds.setUsername(conf.getUsername()); ds.setPassword(conf.getPassword()); ds.setDefaultAutoCommit(conf.getDefaultAutoCommit()); ds.setDriverProperties(conf.getExtProperties()); 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); } }
protected DataSource newDataSource(MetaDataSource meta) throws SQLException { DataSourceProps props = new DataSourceProps.Builder(toMap(meta)).build(); log.debug("DataSource url '{}', username: {}", props.getJdbcUrl(), props.getUsername()); return dataSourceManager.createDataSource(props); }
public Builder(String driverClassName,String url,String username,String password) { this.setDriverClassName(driverClassName) .setUrl(url) .setUsername(username) .setPassword(password); }
@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; } }
public static Builder createBuilder() { return new Builder(); }
public Builder setUrl(String url){ return setProperty(JDBC_URL, url); }
public Connection getConnection(String username, String password) throws SQLException { return doGetConnection(username, password); }
@Override public boolean tryValidateDataSource(DataSource ds) { try { validateDataSource(ds); return true; } catch (SQLException e) { return false; } }
public DataSourceProps build() { return new DataSourceProps(dataSourceType,_default, properties); } }
@Override public Logger getParentLogger() throws SQLFeatureNotSupportedException { return determineTargetDataSource().getParentLogger(); } }
protected void unexportDataSourceMBean(String name, DataSource ds) { if(!(ds instanceof MDataSource)) { return; } mbeanExporter.unexport(objectName(name)); }
@Override public DataSource getDataSource(String name) throws ObjectNotFoundException { DataSource ds = tryGetDataSource(name); if(null == ds){ throw new ObjectNotFoundException("DataSource '" + name + "' not found"); } return ds; }
public Builder setDriverClassName(String driverClassName){ return setProperty(DRIVER_CLASS_NAME, driverClassName); }
public Connection getConnection() throws SQLException { return doGetConnection(username, password); }
public Builder setJdbcUrl(String url) { return setProperty(JDBC_URL, url); }
public Builder setUsername(String username){ return setProperty(USERNAME, username); }
public Builder setPassword(String password) { return setProperty(PASSWORD, password); }
public Builder setExportMBean(boolean exportMBean) { setProperty(EXPORT_MBEAN, String.valueOf(exportMBean)); return this; }