📄 connectionpool.java
字号:
return false; } else { _inUse = true; _timeOpened = System.currentTimeMillis(); return true; } } /** * Checks if the connection currently is used by someone. **/ public boolean inUse() { return _inUse; } /** * Returns the time stamp of the last time this connection was * opened/leased. **/ public synchronized long getTimeOpened() { return _timeOpened; } /** * Returns the time stamp of the last time this connection was * closed. **/ public synchronized long getTimeClosed() { return _timeClosed; } /** * Expires this connection and closes the underlying connection to the * database. Once expired, a connection can no longer be used. **/ public void expire() throws SQLException { _conn.close(); _conn = null; } public void printStackTrace() { _throwable.printStackTrace(System.err); } /*----------------------------------+ | Wrapping methods for Connection | +----------------------------------*/ public synchronized void close() throws SQLException { // Multiple calls to close? if (_inUse) { _timeClosed = System.currentTimeMillis(); _inUse = false; if (_autoCommit == false) { // autoCommit has been set to false by this user, // restore the default "autoCommit = true" setAutoCommit(true); } } } public Statement createStatement() throws SQLException { _throwable = new Throwable(); return _conn.createStatement(); } public PreparedStatement prepareStatement(String sql) throws SQLException { _throwable = new Throwable(); return _conn.prepareStatement(sql); } public CallableStatement prepareCall(String sql) throws SQLException { return _conn.prepareCall(sql); } public String nativeSQL(String sql) throws SQLException { return _conn.nativeSQL(sql); } public void setAutoCommit(boolean autoCommit) throws SQLException { _conn.setAutoCommit(autoCommit); _autoCommit = _conn.getAutoCommit(); } public boolean getAutoCommit() throws SQLException { return _conn.getAutoCommit(); } public void commit() throws SQLException { _conn.commit(); } public void rollback() throws SQLException { _conn.rollback(); } public boolean isClosed() throws SQLException { return _conn.isClosed(); } public DatabaseMetaData getMetaData() throws SQLException { return _conn.getMetaData(); } public void setReadOnly(boolean readOnly) throws SQLException { _conn.setReadOnly(readOnly); } public boolean isReadOnly() throws SQLException { return _conn.isReadOnly(); } public void setCatalog(String catalog) throws SQLException { _conn.setCatalog(catalog); } public String getCatalog() throws SQLException { return _conn.getCatalog(); } public void setTransactionIsolation(int level) throws SQLException { _conn.setTransactionIsolation(level); } public int getTransactionIsolation() throws SQLException { return _conn.getTransactionIsolation(); } public SQLWarning getWarnings() throws SQLException { return _conn.getWarnings(); } public void clearWarnings() throws SQLException { _conn.clearWarnings(); } public Statement createStatement( int resultSetType, int resultSetConcurrency) throws SQLException { return _conn.createStatement(resultSetType, resultSetConcurrency); } public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return _conn.prepareStatement(sql, resultSetType, resultSetConcurrency); } public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return _conn.prepareCall(sql, resultSetType, resultSetConcurrency); } public Map getTypeMap() throws SQLException { return _conn.getTypeMap(); } public void setTypeMap(Map map) throws SQLException { _conn.setTypeMap(map); }/* * The following methods are new methods from java.sql.Connection that * were added in JDK1.4. These additions are incompatible with older JDK * versions. */ public void setHoldability(int holdability) throws SQLException { _conn.setHoldability(holdability); } public int getHoldability() throws SQLException { return _conn.getHoldability(); } public Savepoint setSavepoint() throws SQLException { return _conn.setSavepoint(); } public Savepoint setSavepoint(String name) throws SQLException { return _conn.setSavepoint(name); } public void rollback(Savepoint savepoint) throws SQLException { _conn.rollback(savepoint); } public void releaseSavepoint(Savepoint savepoint) throws SQLException { _conn.releaseSavepoint(savepoint); } public Statement createStatement( int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return _conn.createStatement( resultSetType, resultSetConcurrency, resultSetHoldability); } public PreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return _conn.prepareStatement( sql, resultSetType, resultSetConcurrency, resultSetHoldability); } public CallableStatement prepareCall( String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return _conn.prepareCall( sql, resultSetType, resultSetConcurrency, resultSetHoldability); } public PreparedStatement prepareStatement( String sql, int autoGenerateKeys) throws SQLException { return _conn.prepareStatement(sql, autoGenerateKeys); } public PreparedStatement prepareStatement( String sql, int[] columnIndexes) throws SQLException { return _conn.prepareStatement(sql, columnIndexes); } public PreparedStatement prepareStatement( String sql, String[] columnNames) throws SQLException { return _conn.prepareStatement(sql, columnNames); } }/*--------------------------------------------+| inner class PoolCleaner |+--------------------------------------------*/ class PoolCleaner extends Thread { protected long _cleaningInterval; protected boolean _mustStop; public PoolCleaner(long cleaningInterval) { if (cleaningInterval < 0) { throw new IllegalArgumentException("cleaningInterval must be >= 0"); } _mustStop = false; _cleaningInterval = cleaningInterval; setDaemon(true); } public void run() { while (!_mustStop) { try { sleep(_cleaningInterval); } catch (InterruptedException ignore) { } if (_mustStop) { break; } removeExpired(); } } public void halt() { _mustStop = true; synchronized (this) { this.interrupt(); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -