dbpoolimpl.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,116 行 · 第 1/2 页

JAVA
1,116
字号
      return -1;    else      return _maxPoolTime;  }  /**   * Set the time in milliseconds a connection will remain in the pool before   * being closed.   */  public void setMaxPoolTime(Period maxPoolTime)  {    long period = maxPoolTime.getPeriod();    if (period < 0)      _maxPoolTime = Long.MAX_VALUE / 2;    else if (period == 0)      _maxPoolTime = 1000L;    else      _maxPoolTime = period;  }  /**   * Get the time in milliseconds a connection can remain active.   */  public long getMaxActiveTime()  {    if (_maxActiveTime > Long.MAX_VALUE / 2)      return -1;    else      return _maxActiveTime;  }  /**   * Set the time in milliseconds a connection can remain active.   */  public void setMaxActiveTime(Period maxActiveTime)  {    long period = maxActiveTime.getPeriod();    if (period < 0)      _maxActiveTime = Long.MAX_VALUE / 2;    else if (period == 0)      _maxActiveTime = 1000L;    else      _maxActiveTime = period;  }  /**   * Get the table to 'ping' to see if the connection is still live.   */  public String getPingTable()  {    return _pingTable;  }  /**   * Set the table to 'ping' to see if the connection is still live.   *   * @param pingTable name of the SQL table to ping.   */  public void setPingTable(String pingTable)  {    _pingTable = pingTable;    if (pingTable != null)      _pingQuery = "select 1 from " + pingTable + " where 1=0";    else      _pingQuery = null;    if (_isPing == null)      _isPing = true;  }  /**   * Returns the ping query.   */  public String getPingQuery()  {    return _pingQuery;  }  /**   * Sets the ping query.   */  public void setPingQuery(String pingQuery)  {    _pingQuery = pingQuery;    if (_isPing == null)      _isPing = true;  }  /**   * If true, the pool will ping when attempting to reuse a connection.   */  public boolean getPingOnReuse()  {    return isPing();  }  /**   * Set the table to 'ping' to see if the connection is still live.   */  public void setPingOnReuse(boolean pingOnReuse)  {    _isPing = pingOnReuse;  }  /**   * If true, the pool will ping in the idle pool.   */  public boolean getPingOnIdle()  {    return _isPing;  }  /**   * Set the table to 'ping' to see if the connection is still live.   */  public void setPingOnIdle(boolean pingOnIdle)  {    _isPing = pingOnIdle;  }  /**   * Set true if pinging is enabled.   */  public void setPing(boolean ping)  {    _isPing = ping;  }  /**   * Returns true if pinging is enabled.   */  public boolean isPing()  {    if (_isPing != null)      return _isPing;    else      return false;  }  /**   * Sets the time to ping for ping-on-idle   */  public void setPingInterval(Period interval)  {    _pingInterval = interval.getPeriod();    if (_pingInterval < 0)      _pingInterval = Long.MAX_VALUE / 2;    else if (_pingInterval < 1000)      _pingInterval = 1000;    if (_isPing == null)      _isPing = true;  }  /**   * Gets how often the ping for ping-on-idle   */  public long getPingInterval() {    return _pingInterval;  }  /**   * Set the transaction manager for this pool.   */  public void setTransactionManager(TransactionManager tm)  {    _tm = tm;  }  /**   * Returns the transaction manager.   */  /*  public TransactionManager getTransactionManager()  {    return _tm;  }  */  /**   * Returns true if this is transactional.   */  public boolean isXA()  {    return _isTransactional;  }  /**   * Returns true if this is transactional.   */  public void setXA(boolean isTransactional)  {    _isTransactional = isTransactional;  }  /**   * Returns true if transactions should force isSameRM to be false.   */  public boolean isXAForbidSameRM()  {    return _isXAForbidSameRM;  }  /**   * Returns true if transactions should force isSameRM to be false.   */  public void setXAForbidSameRM(boolean isXAForbidSameRM)  {    _isXAForbidSameRM = isXAForbidSameRM;  }  /**   * Set the output for spying.   */  public void setSpy(boolean isSpy)  {    _isSpy = isSpy;  }  /**   * Return true for a spy.   */  public boolean isSpy()  {    return _isSpy;  }  /**   * Returns the next spy id.   */  public SpyDataSource getSpyDataSource()  {    return _spyDataSource;  }  /**   * Returns the next spy id.   */  public String newSpyId()  {    return _spyDataSource.createConnectionId();  }  /**   * Returns true if the pool supports transactions.   */  public boolean isTransactional()  {    return _isTransactional;  }  /**   * Returns true if there is a valid XAResource associated   * with the database.   */  public boolean isXATransaction()  {    if (_connectionConfig.isReadOnly())      return false;    else if (_driverList.size() > 0) {      DriverConfig driver = _driverList.get(0);      return driver.isXATransaction();    }    else      return false;  }  /**   * Returns true if there is a valid local transactino associated   * with the database.   */  public boolean isLocalTransaction()  {    if (_connectionConfig.isReadOnly())      return false;    else if (_driverList.size() > 0) {      DriverConfig driver = _driverList.get(0);      return driver.isLocalTransaction();    }    else      return false;  }  int createPoolId()  {    return _idCount++;  }  /**   * Sets the timeout for a database login.   */  public void setLoginTimeout(int seconds) throws SQLException  {  }  /**   * Gets the timeout for a database login.   */  public int getLoginTimeout() throws SQLException  {    return 0;  }  /**   * Sets the debugging log for the connection.   */  public void setLogWriter(PrintWriter out) throws SQLException  {  }  /**   * Sets the debugging log for the connection.   */  public PrintWriter getLogWriter() throws SQLException  {    return null;  }  /**   * Initialize the pool.   */  public void init()    throws Exception  {    Environment.addEnvironmentListener(this);    // _alarm = new Alarm("db-pool", this, 60000);    /*    if (_pingInterval > 0 &&        _pingInterval < _maxIdleTime &&        _pingInterval < 60000L)      _alarm.queue(_pingInterval);    else if (_maxIdleTime > 60000)      _alarm.queue(60000);    else      _alarm.queue(_maxIdleTime);    */    try {      if (_tm == null) {        Object obj = new InitialContext().lookup("java:comp/TransactionManager");        if (obj instanceof TransactionManager)          _tm = (TransactionManager) obj;      }    } catch (Exception e) {      log.log(Level.FINE, e.toString(), e);    }    /*    if (isXA() && _tm == null)      throw new ConfigException(L.l("Can't find TransactionManager in java:comp/TransactionManager for transaction-enabled DBPool."));    */    for (int i = 0; i < _driverList.size(); i++) {      DriverConfig driver = _driverList.get(i);      if (driver.getUser() == null)	driver.setUser(_user);      if (driver.getPassword() == null)	driver.setPassword(_password);      driver.initDriver();      driver.initDataSource(_isTransactional, _isSpy);      if (_mcf == null)	_mcf = driver.getManagedConnectionFactory();      /*      if (driver.getXADataSource() == null)	_isTransactional = false;      */    }    DriverConfig []drivers = new DriverConfig[_driverList.size()];    _driverList.toArray(drivers);    for (int i = 0; i < _backupDriverList.size(); i++) {      DriverConfig driver = _backupDriverList.get(i);      if (driver.getUser() == null)	driver.setUser(_user);      if (driver.getPassword() == null)	driver.setPassword(_password);      driver.initDriver();      driver.initDataSource(_isTransactional, _isSpy);      /*      if (driver.getXADataSource() == null)	_isTransactional = false;      */    }    DriverConfig []backupDrivers = new DriverConfig[_backupDriverList.size()];    _backupDriverList.toArray(backupDrivers);    if (_mcf == null)      _mcf = new ManagedFactoryImpl(this, drivers, backupDrivers);    if (_name != null) {      String name = _name;      if (! name.startsWith("java:"))        name = "java:comp/env/" + name;      if (drivers[0].getURL() != null)        log.config("database " + name + " starting (URL:" + drivers[0].getURL() + ")");      else        log.config("database " + name + " starting");      // XXX: actually should be proxy      // Jndi.bindDeep(name, this);    }    _spyDataSource = new SpyDataSource(_name);  }  /**   * Returns the managed connection factory.   */  ManagedConnectionFactory getManagedConnectionFactory()  {    return _mcf;  }  /**   * Initialize the pool's data source   *   * <ul>   * <li>If data-source is set, look it up in JNDI.   * <li>Else if the driver is a pooled or xa data source, use it.   * <li>Else create wrappers.   * </ul>   */  synchronized void initDataSource()    throws SQLException  {    if (_isStarted)      return;    _isStarted = true;    for (int i = 0; i < _driverList.size(); i++) {      DriverConfig driver = _driverList.get(i);      driver.initDataSource(_isTransactional, _isSpy);    }    try {      if (_isTransactional && _tm == null) {        Object obj = new InitialContext().lookup("java:comp/TransactionManager");        if (obj instanceof TransactionManager)          _tm = (TransactionManager) obj;      }    } catch (NamingException e) {      throw new SQLExceptionWrapper(e);    }  }  /**   * Closes the idle connections in the pool.   */  public void closeIdleConnections()  {      }  /**   * At the alarm, close all connections which have been sitting in   * the pool for too long.   *   * @param alarm the alarm event.   */  public void handleAlarm(Alarm alarm)  {    if (_isClosed)      return;  }  /**   * Callback when the environment configures.   */  public void environmentConfigure(EnvironmentClassLoader loader)  {  }  /**   * Callback when the environment binds.   */  public void environmentBind(EnvironmentClassLoader loader)  {  }    /**   * Callback when the environment starts.   */  public void environmentStart(EnvironmentClassLoader loader)  {  }  /**   * Callback when the class loader dies.   */  public void environmentStop(EnvironmentClassLoader loader)  {    forceClose();  }  /**   * Returns true if the pool is closed.   */  public boolean isClosed()  {    return _isClosed;  }  /**   * Close the pool, closing the connections.   */  public void close()  {    if (_forbidClose)      throw new IllegalStateException("illegal to call close() for this DBPool");    forceClose();  }  /**   * Close all the connections in the pool.   */  public void forceClose()  {    if (_isClosed)      return;    _isClosed = true;    if (log.isLoggable(Level.FINE))      log.fine("closing pool " + getName());  }  /**   * Returns a string description of the pool.   */  public String toString()  {    return "DBPoolImpl[" + _name + "]";  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?