from ConnectionProvider
544821
public Connection getConnection (String ident, boolean readOnly)
        throws PersistenceException
    {
        return getMapping(ident, readOnly).getConnection(ident);
    }
755132
public void checkConnection() throws ConnectionException {
        IAPIConnector connector = populateHeaders(new V1APIConnector(getApplicationURL()
                + MEMBER_CONNECT_PARAM, username, password, ApiClientInternals.getProxyProvider(proxySettings)));

        try {
            connector.getData().close();
        } catch (Exception ex) {
            throw new ConnectionException("Application not found at the URL: "
                    + getApplicationURL(), ex);
        }
    }
1269700
public Collector<T> getResults(Connection conn, DataObject object, Collector<T> collector) throws Exception {
        return executeSelect(conn, object, new ResultSetMapper<Collector<T>>(collector));
    }
703920
public ConnectionFactory<?> getConnectionFactory(String providerId) {
		ConnectionFactory<?> connectionFactory = connectionFactories.get(providerId);
		if (connectionFactory == null) {
			throw new IllegalArgumentException("No connection factory for service provider '" + providerId + "' is registered");
		}
		return connectionFactory;
	}
1210173
protected void queueConnectForSelector(ConnectInfo connectInfo) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "queueConnectForSelector");
        }

        try {
            moveIntoPosition(connectCount, connect, connectInfo, CS_CONNECTOR);
        } catch (IOException x) {
            FFDCFilter.processException(x, getClass().getName(), "140", this);
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Caught IOException...throwing RuntimeException");
            }
            throw new RuntimeException(x);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "queueConnectForSelector");
        }
    }
1179476
private void returnConnection(final ConnectionHolder connectionHolder) {

        ClientStatistics stats = connectionHolder.clientConnection.getStatistics();
        this.requestCount.incrementAndGet();
        if(stats != null) {
            //we update the stats when the connection is closed
            this.read.addAndGet(stats.getRead());
            this.written.addAndGet(stats.getWritten());
            stats.reset();
        }

        HostThreadData hostData = getData();
        if (closed) {
            //the host has been closed
            IoUtils.safeClose(connectionHolder.clientConnection);
            ConnectionHolder con = hostData.availableConnections.poll();
            while (con != null) {
                IoUtils.safeClose(con.clientConnection);
                con = hostData.availableConnections.poll();
            }
            redistributeQueued(hostData);
            return;
        }

        //only do something if the connection is open. If it is closed then
        //the close setter will handle creating a new connection and decrementing
        //the connection count
        final ClientConnection connection = connectionHolder.clientConnection;
        if (connection.isOpen() && !connection.isUpgraded()) {
            CallbackHolder callback = hostData.awaitingConnections.poll();
            while (callback != null && callback.isCancelled()) {
                callback = hostData.awaitingConnections.poll();
            }
            if (callback != null) {
                if (callback.getTimeoutKey() != null) {
                    callback.getTimeoutKey().remove();
                }
                // Anything waiting for a connection is not expecting exclusivity.
                connectionReady(connectionHolder, callback.getCallback(), callback.getExchange(), false);
            } else {
                final int cachedConnectionCount = hostData.availableConnections.size();
                if (cachedConnectionCount >= maxCachedConnections) {
                    // Close the longest idle connection instead of the current one
                    final ConnectionHolder holder = hostData.availableConnections.poll();
                    if (holder != null) {
                        IoUtils.safeClose(holder.clientConnection);
                    }
                }
                hostData.availableConnections.add(connectionHolder);
                // If the soft max and ttl are configured
                if (timeToLive > 0) {
                    //we only start the timeout process once we have hit the core pool size
                    //otherwise connections could start timing out immediately once the core pool size is hit
                    //and if we never hit the core pool size then it does not make sense to start timers which are never
                    //used (as timers are expensive)
                    final long currentTime = System.currentTimeMillis();
                    connectionHolder.timeout = currentTime + timeToLive;
                    if(hostData.availableConnections.size() > coreCachedConnections) {
                        if (hostData.nextTimeout <= 0) {
                            hostData.timeoutKey = WorkerUtils.executeAfter(connection.getIoThread(), hostData.timeoutTask, timeToLive, TimeUnit.MILLISECONDS);
                            hostData.nextTimeout = connectionHolder.timeout;
                        }
                    }
                }
            }
        } else if (connection.isOpen() && connection.isUpgraded()) {
            //we treat upgraded connections as closed
            //as we do not want the connection pool filled with upgraded connections
            //if the connection is actually closed the close setter will handle it
            connection.getCloseSetter().set(null);
            handleClosedConnection(hostData, connectionHolder);
        }
    }
649688
@Override
    protected void init() throws Exception {
        final boolean trace = TraceComponent.isAnyTracingEnabled();

        try {
            PropertyService vProps = new PropertyService();
            NavigableMap<String, Object> wProps = parseConfiguration(properties, vProps);

            // Clone properties so that we can later detect modifications from the current values
            vProps = (PropertyService) vProps.clone();

            String jndiName = (String) wProps.remove(JNDI_NAME);
            String type = (String) wProps.remove(DSConfig.TYPE);

            // Trace some of the most important config settings
            if (trace && tc.isDebugEnabled())
                Tr.debug(this, tc, DATASOURCE, id, jndiName, type);

            // Get the connection manager service for this data source. If none is configured, then use defaults.
            conMgrSvc = (ConnectionManagerService) priv.locateService(componentContext,CONNECTION_MANAGER);

            boolean createdDefaultConnectionManager = false;
            
            if (conMgrSvc == null) {
                if (wProps.containsKey(DSConfig.CONNECTION_MANAGER_REF)) {
                    SQLNonTransientException failure = connectorSvc.ignoreWarnOrFail(tc, null, SQLNonTransientException.class, "MISSING_RESOURCE_J2CA8030",
                                                                                    DSConfig.CONNECTION_MANAGER_REF, "", DATASOURCE, jndiName == null ? id : jndiName);
                    if (failure != null)
                        throw failure;
                }
                conMgrSvc = ConnectionManagerService.createDefaultService(id);
                createdDefaultConnectionManager = true;

            }
            conMgrSvc.addObserver(this);

            // Obtain the data source from the JDBC driver
            // TODO: Switch to org.osgi.service.jdbc.DataSourceFactory for compatibility with OSGI JDBC drivers
            jdbcDriverSvc = (JDBCDriverService) priv.locateService(componentContext,JDBC_DRIVER);

            if (jdbcDriverSvc == null) {
                Tr.error(tc, "DSRA4003.driver.null", jndiName == null ? id : jndiName);

                throw new SQLNonTransientException(ConnectorService.getMessage("MISSING_RESOURCE_J2CA8030", DSConfig.JDBC_DRIVER_REF,
                                                                               "", DATASOURCE, jndiName == null ? id : jndiName));
            }
            jdbcDriverSvc.addObserver(this);

            Object vendorImpl;
            Class<?> ifc;

            if(type == null){
                boolean atLeastJDBC43 = jdbcRuntime.getVersion().compareTo(JDBCRuntimeVersion.VERSION_4_3) >= 0;
                vendorImpl = atLeastJDBC43 || id != null && id.contains("dataSource[DefaultDataSource]")
                                ? jdbcDriverSvc.createAnyPreferXADataSource(vProps, id)
                                : jdbcDriverSvc.createAnyPreferLegacyOrder(vProps, id);
                ifc = vendorImpl instanceof XADataSource ? XADataSource.class
                    : vendorImpl instanceof ConnectionPoolDataSource ? ConnectionPoolDataSource.class
                    : vendorImpl instanceof DataSource ? DataSource.class
                    : Driver.class;
            } else if (ConnectionPoolDataSource.class.getName().equals(type)) {
                ifc = ConnectionPoolDataSource.class;
                vendorImpl = jdbcDriverSvc.createConnectionPoolDataSource(vProps, id);
            } else if (XADataSource.class.getName().equals(type)) {
                ifc = XADataSource.class;
                vendorImpl = jdbcDriverSvc.createXADataSource(vProps, id);
            } else if (DataSource.class.getName().equals(type)) {
                ifc = DataSource.class;
                vendorImpl = jdbcDriverSvc.createDataSource(vProps, id);
            } else if (Driver.class.getName().equals(type)) {
                ifc = Driver.class;
                String url = vProps.getProperty("URL", vProps.getProperty("url"));
                if (url != null && !"".equals(url)) {
                    vendorImpl = jdbcDriverSvc.getDriver(url, vProps, id);
                } else 
                    throw new SQLNonTransientException(AdapterUtil.getNLSMessage("DSRA4014.URL.for.Driver.missing", jndiName == null ? id : jndiName));
            } else
                throw new SQLNonTransientException(ConnectorService.getMessage("MISSING_RESOURCE_J2CA8030", DSConfig.TYPE, type, DATASOURCE, jndiName == null ? id : jndiName));

            // Convert isolationLevel constant name to integer
            vendorImplClassName = vendorImpl.getClass().getName();
            parseIsolationLevel(wProps, vendorImplClassName);
            
            Object objIsolationLevel = wProps.get(DataSourceDef.isolationLevel.name());
            int wIsolationLevel = objIsolationLevel == null ? -1 : (int) objIsolationLevel;
            
            if(wIsolationLevel == Connection.TRANSACTION_NONE) {
                Object objTransactional = wProps.get(DataSourceDef.transactional.name());
                boolean wTransactional = objTransactional == null ? true : (boolean) objTransactional;
                
                if (wTransactional) {
                    throw new SQLException(AdapterUtil.getNLSMessage("DSRA4009.tran.none.transactional.unsupported", id));
                }
            }

            // Derby Embedded needs a reference count so that we can shutdown databases when no longer used.
            isDerbyEmbedded = vendorImplClassName.startsWith("org.apache.derby.jdbc.Embedded");
            if (isDerbyEmbedded) {
                String dbName = (String) vProps.get(DataSourceDef.databaseName.name());
                if (dbName != null) {
                    // Maintaining compatibility here. Variables are no longer normalized by default, but the ResourceFactoryBuilder is still
                    // using VariableRegistry.resolveString() to resolve variables in data source definitions. 
                    dbName = PathUtils.normalize(dbName);
                    embDerbyRefCount.add(dbName);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        Tr.debug(this, tc, "ref count for database shutdown", dbName, embDerbyRefCount);
                }
            }

            isUCP = vendorImplClassName.startsWith("oracle.ucp");
            if (isUCP) {
                if (!createdDefaultConnectionManager && !sentUCPConnMgrPropsIgnoredInfoMessage) {
                    Set<String> connMgrPropsAllowed = Collections.singleton("enableSharingForDirectLookups");
                    Tr.info(tc, "DSRA4013.ignored.connection.manager.config.used", connMgrPropsAllowed);
                    sentUCPConnMgrPropsIgnoredInfoMessage = true;
                }
                updateConfigForUCP(wProps);
            }

            dsConfigRef.set(new DSConfig(id, jndiName, wProps, vProps, connectorSvc));

            WSManagedConnectionFactoryImpl mcfImpl = new WSManagedConnectionFactoryImpl(dsConfigRef, ifc, vendorImpl, jdbcRuntime);

            if (jdbcDriverSvc.loadFromApp()) {
                // data source class loaded from thread context class loader
                mcf = null;
                mcfPerClassLoader = new ConcurrentHashMap<String, WSManagedConnectionFactoryImpl>();
                ClassLoader tccl = priv.getContextClassLoader();
                String identifier = connectorSvc.getClassLoaderIdentifierService().getClassLoaderIdentifier(tccl);
                mcfPerClassLoader.put(identifier, mcfImpl);
            } else {
                // data source class loaded from shared library
                mcf = mcfImpl;
                mcfPerClassLoader = null;
            }

            isInitialized.set(true);
        } catch (Exception x) {
            FFDCFilter.processException(x, getClass().getName(), "587", this);
            // undo any partial initialization
            if (conMgrSvc != null)
                conMgrSvc.deleteObserver(this);
            if (jdbcDriverSvc != null)
                jdbcDriverSvc.deleteObserver(this);
            throw x;
        } catch (Error x) {
            FFDCFilter.processException(x, getClass().getName(), "591", this);
            // undo any partial initialization
            if (conMgrSvc != null)
                conMgrSvc.deleteObserver(this);
            if (jdbcDriverSvc != null)
                jdbcDriverSvc.deleteObserver(this);
            throw x;
        }
    }
905675
ConnectionWrapper obtainConnection() {
		synchronized (allConnections) {
			//fails if connection pool not started
			if (!availableConnections.isEmpty()) {
				//retrieve and remove first connection from list
				//  since released connections are added to the back, connections will rotate
				ConnectionWrapper connWrap = (ConnectionWrapper) availableConnections.remove(0);
				usedConnections.add(connWrap);
				if (usedConnections.size() > maxNrOfConcurrentConnectionsCounted) {
					maxNrOfConcurrentConnectionsCounted = usedConnections.size();
				}
				return connWrap;
			} else {
				//create one if max not reached
				//this also restores lost connections
				if ((allConnections.size() < initialNrofConnections) || (allConnections.size() < maxNrofConnections)) {
					try {
						ConnectionWrapper connWrap = createConnectionWrapper(dbUrl, dbUsername, dbUserpassword);

						allConnections.add(connWrap);
						usedConnections.add(connWrap);

						System.out.println(new LogEntry("Creating new Connection, now " + allConnections.size() + " in use"));

						return connWrap;
					} catch (SQLException sqle) {
						//happens if db unreachable
						//connection will be lost for the time being
						nrofErrors++;
						System.out.println(new LogEntry("Cannot create new connection to " + dbUrl + " unreachable or useless connection settings", sqle));
						throw new ResourceException("Cannot create new connection to " + dbUrl + " unreachable or useless connection settings", sqle);
					}
				} else {
					System.out.println(new LogEntry("maximum nr of connections (" + maxNrofConnections + ") reached while Application demands another"));
				}
				return null;
			}
		}
	}
996451
public static Connection getconnnection() {
		Connection con = null;
		try {
			con = DriverManager.getConnection(url, userName, password);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
1201544
@Override
    public Session connectToServer(Class<? extends Endpoint> endpointClass, ClientEndpointConfig endpointConfig, URI path) throws DeploymentException, IOException {

        Object theObject = null;

        if (endpointClass == null || path == null) {
            throw new IllegalArgumentException();
        }

        if (!(Endpoint.class.isAssignableFrom(endpointClass))) {
            DeploymentException e = new DeploymentException("Class " + endpointClass.getName() + " does not extend Endpoint");
            String msg = Tr.formatMessage(tc, "client.invalid.endpointclass", endpointClass.toString(), e.getMessage());
            Tr.error(tc, "client.invalid.endpointclass", endpointClass.toString(), e.getMessage());
            throw new DeploymentException(msg, e);
        }

        ClientConnector x = new ClientConnector();

        try {
            theObject = getEndpointInstance(endpointClass);
        } catch (DeploymentException e) {
            String msg = Tr.formatMessage(tc, "client.connection.error", endpointClass.toString(), e.getMessage());
            Tr.error(tc, "client.connection.error", endpointClass.toString(), e.getMessage());
            throw new DeploymentException(msg, e);
        }

        return x.connectClass(theObject, path, endpointConfig, this);
    }
76726
@Override
    public Session connectToServer(Class<?> clazz, URI path) throws DeploymentException, IOException {

        if (clazz == null || path == null) {
            throw new IllegalArgumentException();
        }
        Object theObject = null;
        ClientConnector x = new ClientConnector();

        try {
            theObject = getEndpointInstance(clazz);
        } catch (DeploymentException e) {
            String msg = Tr.formatMessage(tc, "client.connection.error", clazz.toString(), e.getMessage());
            Tr.error(tc, "client.connection.error", clazz.toString(), e.getMessage());
            throw new DeploymentException(msg, e);
        }

        return x.connectAnnotatedClass(theObject, path, this);
    }
179318
@Override
  public Connection getConnection() throws SQLException {
    return getConnection(
      new Callable<Connection>() {
        @Override
        public Connection call() throws SQLException {
          return MonitoringDataSource.this.original.getConnection();
        }
      },
      ".getConnection");
  }
1255766
@Override
	public void setConnectionTimeoutMS(int connectionTimeoutMS) {
    	connectionManager.getParams().setConnectionTimeout(connectionTimeoutMS);
    	http.getParams().setConnectionManagerTimeout(connectionTimeoutMS);
	}
817151
function HttpClient(connectionConfig)
{
  // save the connection config
  this._connectionConfig = connectionConfig;

  // check that we have a valid request module
  var requestModule = this.getRequestModule();
  Errors.assertInternal(
      Util.isObject(requestModule) || Util.isFunction(requestModule));
}
907854
public List<T> getResults(Connection conn, DataObject object) throws Exception {
        return executeSelect(conn, object, new ResultSetMapper<ArrayListCollector<T>>(new ArrayListCollector<T>()));
    }
548137
@Override
    public String getProviderEndpoints() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getProviderEndpoints");
        String providerEndpoints = jcaConnectionFactory.getProviderEndpoints();
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "getProviderEndpoints", providerEndpoints);
        return providerEndpoints;
    }
479674
public static void connectionObserver(AbstractBootstrap<?, ?> b,
			ConnectionObserver connectionObserver) {
		Objects.requireNonNull(b, "bootstrap");
		Objects.requireNonNull(connectionObserver, "connectionObserver");
		b.option(OBSERVER_OPTION, connectionObserver);
	}