/** * Gets a <b>non-pooled</b> connection, unless the user and password are the same as the default * values for this connection pool. * * @return A pooled connection. * @throws SQLException Occurs when no pooled connection is available, and a new physical * connection cannot be created. */ public Connection getConnection(String user, String password) throws SQLException { // If this is for the default user/password, use a pooled connection if (user == null || (user.equals(getUser()) && ((password == null && getPassword() == null) || (password != null && password.equals(getPassword()))))) { return getConnection(); } // Otherwise, use a non-pooled connection if (!initialized) { initialize(); } return super.getConnection(user, password); }
@Override public Map<String, ?> properties(RequestContext ctx) throws Exception { Map<String, Object> result = new HashMap<>(); PGPoolingDataSource ds = this.ds; result.put("server", ds.getServerName() ); result.put("port", ds.getPortNumber()); result.put("db", ds.getDatabaseName()); result.put("user", ds.getUser()); result.put("password", ds.getPassword()); result.put("max-connections", ds.getMaxConnections()); result.put("initial-connections", ds.getInitialConnections()); List<String> schemas = configuration.exposedSchemas(); if (schemas != null && schemas.size() > 0) { result.put("schemas", schemas); } schemas = configuration.blockedSchemas(); if (schemas != null && schemas.size() > 0) { result.put("blocked-schemas", schemas); } if (configuration.defaultSchema() != null) { result.put("default-schema", configuration.defaultSchema()); } result.put("allow-create-schema", configuration.allowCreateSchema()); result.put("include-total-count", configuration.includeTotalCount()); return result; }
@Override public DataSource createDataSource(Properties properties) throws SQLException { if (properties == null) { properties = new Properties(); } if(properties.getProperty(JDBC_DATASOURCE_NAME) == null) { properties.setProperty(JDBC_DATASOURCE_NAME, DataSourceFactoryImpl.class.getSimpleName() + "_" + dataSourceCount.getAndAdd(1)); } PGPoolingDataSource dataSource = PGPoolingDataSource.getDataSource(properties.getProperty(JDBC_DATASOURCE_NAME)); if(dataSource == null) { dataSource = new PGPoolingDataSource(); // Set dataSourceName, databaseName, user, and password dataSource.setDataSourceName(properties.getProperty(JDBC_DATASOURCE_NAME)); String url = properties.getProperty(JDBC_URL); if(url != null) { dataSource.setUrl(url); } dataSource.setPortNumber(Integer.valueOf(properties.getProperty(JDBC_PORT_NUMBER, Integer.toString(dataSource.getPortNumber())))); dataSource.setServerName(properties.getProperty(JDBC_SERVER_NAME, dataSource.getServerName())); dataSource.setUser(properties.getProperty(JDBC_USER, dataSource.getUser())); dataSource.setPassword(properties.getProperty(JDBC_PASSWORD, dataSource.getPassword())); dataSource.setDatabaseName(properties.getProperty(JDBC_DATABASE_NAME, dataSource.getDatabaseName())); } return new DataSourceWrapper(dataSource); }
@Override public DataSource createDataSource(Properties properties) throws SQLException { if (properties == null) { properties = new Properties(); } if(properties.getProperty(JDBC_DATASOURCE_NAME) == null) { properties.setProperty(JDBC_DATASOURCE_NAME, DataSourceFactoryImpl.class.getSimpleName() + "_" + dataSourceCount.getAndAdd(1)); } PGPoolingDataSource dataSource = PGPoolingDataSource.getDataSource(properties.getProperty(JDBC_DATASOURCE_NAME)); if(dataSource == null) { dataSource = new PGPoolingDataSource(); // Set dataSourceName, databaseName, user, and password dataSource.setDataSourceName(properties.getProperty(JDBC_DATASOURCE_NAME)); String url = properties.getProperty(JDBC_URL); if(url != null) { dataSource.setUrl(url); } dataSource.setPortNumber(Integer.valueOf(properties.getProperty(JDBC_PORT_NUMBER, Integer.toString(dataSource.getPortNumber())))); dataSource.setServerName(properties.getProperty(JDBC_SERVER_NAME, dataSource.getServerName())); dataSource.setUser(properties.getProperty(JDBC_USER, dataSource.getUser())); dataSource.setPassword(properties.getProperty(JDBC_PASSWORD, dataSource.getPassword())); dataSource.setDatabaseName(properties.getProperty(JDBC_DATABASE_NAME, dataSource.getDatabaseName())); } return new DataSourceWrapper(dataSource); }
@Override public DataSource createDataSource(Properties properties) throws SQLException { if (properties == null) { properties = new Properties(); } PGPoolingDataSource dataSource = new PGPoolingDataSource(); // Set dataSourceName, databaseName, user, and password dataSource.setDataSourceName(properties.getProperty(JDBC_DATASOURCE_NAME)); String url = properties.getProperty(JDBC_URL); if(url != null) { dataSource.setUrl(url); } dataSource.setPortNumber(Integer.valueOf(properties.getProperty(JDBC_PORT_NUMBER, Integer.toString(dataSource.getPortNumber())))); dataSource.setServerName(properties.getProperty(JDBC_SERVER_NAME, dataSource.getServerName())); dataSource.setUser(properties.getProperty(JDBC_USER, dataSource.getUser())); dataSource.setPassword(properties.getProperty(JDBC_PASSWORD, dataSource.getPassword())); dataSource.setDatabaseName(properties.getProperty(JDBC_DATABASE_NAME, dataSource.getDatabaseName())); return new DataSourceWrapper(dataSource); }
|| !port.equals(old.getPortNumber()) || !user.equals(old.getUser()) || !pass.equals(old.getPassword()) || !maxConnections.equals(old.getMaxConnections()) || !initialConnections.equals(old.getInitialConnections());