DataSourceImpl is a class that implements the interface javax. SQL. DataSource, which maintains an object in the connection pool. Because this class is a protected class, only the methods defined in the DataSource interface are exposed to the user. All other methods are invisible to the user. First, let's take a look at the method getConnection that users can access.
/**
* @ See javax. SQL. DataSource # getConnection (String, String)
*/
Public Connection getConnection (String user, String password) throws SQLException
{
// First, find the idle object from the connection pool.
Connection conn = getFreeConnection (0 );
If (conn = null ){
// Determine whether the maximum number of connections is exceeded. If the maximum number of connections is exceeded
// Wait for a certain period of time to check whether there are idle connections; otherwise, an exception is thrown to inform the user that no available connections exist.
If (getConnectionCount ()> = connParam. getMaxConnection ())
Conn = getFreeConnection (connParam. getWaitTime ());
Else {// the number of connections does not exceed. obtain a new database connection.
ConnParam. setUser (user );
ConnParam. setPassword (password );
Connection conn2 = DriverManager. getConnection (connParam. getUrl (),
User, password );
// Connection object to be returned by the proxy