⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionpoolimpl.java

📁 OA典型例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	    try {
		Thread.sleep(500);
	    } catch (InterruptedException _ex) {}
	}

	//close all opened connections
	for (int i = 0; i < currConnCount; i++) {
	    try {
		if (pool[i] != null) {
		    pool[i].close();
		}
	    } catch (SQLException e) {}
	}

	for (int i = 0; i < maxConns; i++) {
	    connStatus[i] = CN_STATUS_CLOSED;
	}
	log.println(new java.util.Date() + " : Connection pool destroy successful");
	log.println("------------------ END -----------------");
	log.close();
    }


    /**
     *@param  connection
     */
    public void freeConnection(Connection connection) {
	int index = -1;
	index = indexOfConnection(connection);
	if (index == -1) {
	    return;
	}
	synchronized (connStatus) {
	    debug("free connection of " + index);
	    connStatus[index] = CN_STATUS_FREE;
	}
    }


    /**
     *@return    int
     */
    public int getSize() {
	return maxConns;
    }


    /**
     *@return    int
     */
    public int getUsedCount() {
	int count = 0;
	for (int i = 0; i < currConnCount; i++) {
	    if (connStatus[i] == CN_STATUS_USED) {
		count++;
	    }
	}
	return count;
    }


    //get free connection count status != CN_STATUS_INVALID
    /**
     *  Gets the availableCount attribute of the MWConnectionPoolImpl object
     *
     *@return    The availableCount value
     */
    public int getAvailableCount() {
	int count = 0;
	for (int i = 0; i < currConnCount; i++) {
	    if ((connStatus[i] == CN_STATUS_USED) || (connStatus[i] == CN_STATUS_FREE)) {
		count++;
	    }
	}
	return count;
    }


    /**
     *@param  connection
     *@return             int
     */
    public int indexOfConnection(Connection connection) {
	int index = -1;
	for (int i = 0; i < currConnCount; i++) {
	    if ((pool[i] != null) && (connection.equals(pool[i]))) {
		index = i;
		break;
	    }
	}
	return index;
    }


    /**
     *  implements java.sql.Connection to override close method ,to free
     *  Connection of ConnectionPool
     *
     *@author     Administrator
     *@created    2002年1月23日
     */
    public class ConnectionWrapper implements java.sql.Connection {
	private Connection connection;
	private ConnectionPool connectionPool;


	/**
	 *@param  conn
	 *@param  connPool
	 */
	public ConnectionWrapper(Connection conn, ConnectionPool connPool) {
	    connection = conn;
	    connectionPool = connPool;
	}

        public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws java.sql.SQLException {
	    return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
        }

        public CallableStatement prepareCall(String sql, int resultSetType,int resultSetConcurrency,int resultSetHoldability) throws java.sql.SQLException {
            return connection.prepareCall(sql, resultSetType, resultSetConcurrency,resultSetHoldability);
        }

	/**
	 *  Description of the Method
	 *
	 *@param  obj  Description of the Parameter
	 *@return      Description of the Return Value
	 */
	public boolean equals(Object obj) {
	    return connection.equals(obj);
	}


	/**
	 *@exception  SQLException  Description of the Exception
	 */
	public void close() throws SQLException {
	    try {
		//just try to rollback transaction to avoid database locked
		connection.rollback();
	    } catch (SQLException ex) {}
	    connection.setAutoCommit(true);
	    connectionPool.freeConnection(connection);
	    connection = null;
	    connectionPool = null;
	}


	//these methods just return Connection object's methods
	/**
	 *  Description of the Method
	 *
	 *@exception  SQLException  Description of the Exception
	 */
	public void clearWarnings() throws SQLException {
	    connection.clearWarnings();
	}


	/**
	 *  Description of the Method
	 *
	 *@exception  SQLException  Description of the Exception
	 */
	public void commit() throws SQLException {
	    connection.commit();
	}


	/**
	 *  Description of the Method
	 *
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public Statement createStatement() throws SQLException {
	    return connection.createStatement();
	}


	/**
	 *  Description of the Method
	 *
	 *@param  i                 Description of the Parameter
	 *@param  j                 Description of the Parameter
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public Statement createStatement(int i, int j) throws SQLException {
	    return connection.createStatement(i, j);
	}

        public Statement createStatement(int i, int j,int k) throws SQLException {
            return connection.createStatement(i, j,k);
        }

	/**
	 *  Gets the autoCommit attribute of the ConnectionWrapper object
	 *
	 *@return                   The autoCommit value
	 *@exception  SQLException  Description of the Exception
	 */
	public boolean getAutoCommit() throws SQLException {
	    return connection.getAutoCommit();
	}


	/**
	 *  Gets the catalog attribute of the ConnectionWrapper object
	 *
	 *@return                   The catalog value
	 *@exception  SQLException  Description of the Exception
	 */
	public String getCatalog() throws SQLException {
	    return connection.getCatalog();
	}


	/**
	 *  Gets the metaData attribute of the ConnectionWrapper object
	 *
	 *@return                   The metaData value
	 *@exception  SQLException  Description of the Exception
	 */
	public DatabaseMetaData getMetaData() throws SQLException {
	    return connection.getMetaData();
	}


	/**
	 *  Gets the transactionIsolation attribute of the ConnectionWrapper
	 *  object
	 *
	 *@return                   The transactionIsolation value
	 *@exception  SQLException  Description of the Exception
	 */
	public int getTransactionIsolation() throws SQLException {
	    return connection.getTransactionIsolation();
	}


	/**
	 *  Gets the typeMap attribute of the ConnectionWrapper object
	 *
	 *@return                   The typeMap value
	 *@exception  SQLException  Description of the Exception
	 */
	public Map getTypeMap() throws SQLException {
	    return connection.getTypeMap();
	}


	/**
	 *  Gets the warnings attribute of the ConnectionWrapper object
	 *
	 *@return                   The warnings value
	 *@exception  SQLException  Description of the Exception
	 */
	public SQLWarning getWarnings() throws SQLException {
	    return connection.getWarnings();
	}


	/**
	 *  Gets the closed attribute of the ConnectionWrapper object
	 *
	 *@return                   The closed value
	 *@exception  SQLException  Description of the Exception
	 */
	public boolean isClosed() throws SQLException {
	    return connection.isClosed();
	}


	/**
	 *  Gets the readOnly attribute of the ConnectionWrapper object
	 *
	 *@return                   The readOnly value
	 *@exception  SQLException  Description of the Exception
	 */
	public boolean isReadOnly() throws SQLException {
	    return connection.isReadOnly();
	}


	/**
	 *  Description of the Method
	 *
	 *@param  s                 Description of the Parameter
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public String nativeSQL(String s) throws SQLException {
	    return connection.nativeSQL(s);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  s                 Description of the Parameter
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public CallableStatement prepareCall(String s) throws SQLException {
	    return connection.prepareCall(s);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  s                 Description of the Parameter
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public PreparedStatement prepareStatement(String s) throws SQLException {
	    return connection.prepareStatement(s);
	}


	/**
	 *  Description of the Method
	 *
	 *@param  s                 Description of the Parameter
	 *@param  i                 Description of the Parameter
	 *@param  j                 Description of the Parameter
	 *@return                   Description of the Return Value
	 *@exception  SQLException  Description of the Exception
	 */
	public PreparedStatement prepareStatement(String s, int i, int j) throws SQLException {
	    return  connection.prepareStatement(s, i, j);
	}

        public PreparedStatement prepareStatement(String s, String columnNames[]) throws SQLException {
            return  connection.prepareStatement(s,columnNames);
        }

        public PreparedStatement prepareStatement(String s, int columnIndexes[]) throws SQLException {
            return  connection.prepareStatement(s,columnIndexes);
        }

        public PreparedStatement prepareStatement(String s, int autoGeneratedKeys) throws SQLException {
            return  connection.prepareStatement(s,autoGeneratedKeys);
        }

        public PreparedStatement prepareStatement(String s, int resultSetType,int resultSetConcurrency, int resultSetHoldability) throws SQLException {
            return  connection.prepareStatement(s,resultSetType,resultSetConcurrency,resultSetHoldability);
        }


	/**
	 *  Description of the Method
	 *
	 *@exception  SQLException  Description of the Exception
	 */
	public void rollback() throws SQLException {
	    connection.rollback();
	}

        public void rollback(Savepoint savepoint) throws SQLException {
            connection.rollback(savepoint);
        }

        public void  releaseSavepoint(Savepoint savepoint) throws SQLException{
           connection.releaseSavepoint(savepoint);
        }
        /**
	 *  Sets the autoCommit attribute of the ConnectionWrapper object
	 *
	 *@param  flag              The new autoCommit value
	 *@exception  SQLException  Description of the Exception
	 */
	public void setAutoCommit(boolean flag) throws SQLException {
	    connection.setAutoCommit(flag);
	}


	/**
	 *  Sets the catalog attribute of the ConnectionWrapper object
	 *
	 *@param  s                 The new catalog value
	 *@exception  SQLException  Description of the Exception
	 */
	public void setCatalog(String s) throws SQLException {
	    connection.setCatalog(s);
	}

        public  Savepoint setSavepoint(String str) throws SQLException{
            return  connection.setSavepoint(str);
        }

        public  Savepoint setSavepoint() throws SQLException{
            return  connection.setSavepoint();
        }

        public  int  getHoldability() throws SQLException{
            return   connection.getHoldability();
        }

        public void  setHoldability(int holdability) throws SQLException
        {
             connection.setHoldability(holdability);
        }
	/**
	 *  Sets the readOnly attribute of the ConnectionWrapper object
	 *
	 *@param  flag              The new readOnly value
	 *@exception  SQLException  Description of the Exception
	 */
	public void setReadOnly(boolean flag) throws SQLException {
	    connection.setReadOnly(flag);
	}


	/**
	 *  Sets the transactionIsolation attribute of the ConnectionWrapper
	 *  object
	 *
	 *@param  i                 The new transactionIsolation value
	 *@exception  SQLException  Description of the Exception
	 */
	public void setTransactionIsolation(int i) throws SQLException {
	    connection.setTransactionIsolation(i);
	}


	/**
	 *  Sets the typeMap attribute of the ConnectionWrapper object
	 *
	 *@param  map               The new typeMap value
	 *@exception  SQLException  Description of the Exception
	 */
	public void setTypeMap(Map map) throws SQLException {
	    connection.setTypeMap(map);
	}


	/**
	 *  Description of the Method
	 *
	 *@return    Description of the Return Value
	 */
	public String toString() {
	    if (connection != null) {
		return connection.toString();
	    } else {
		return "Mindsware connection wrapper";
	    }
	}
	//just return it Connection
    }
}

⌨️ 快捷键说明

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