📄 oracleconnectionpool.java
字号:
package jodd.db.pool;
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleConnectionCacheImpl;
/**
* Oracle connection pool uses OracleConnectionCacheImpl and adopts it to
* ConnectionPool interface.
*/
public class OracleConnectionPool implements ConnectionPool {
// ---------------------------------------------------------------- properties
private String url;
public void setUrl(String s) {
url = s;
}
private String user;
public void setUser(String s) {
user = s;
}
private String password;
public void setPassword(String s) {
password = s;
}
private int maxLimit = 10;
public void setMaxLimit(int i) {
if (i > 0) {
maxLimit = i;
}
}
private int minLimit = 5;
public void setMinLimit(int i) {
if (i > maxLimit) {
i = maxLimit;
}
minLimit = i;
}
// ---------------------------------------------------------------- misc
/**
* Return the total no of connections in the Cache.
*
* @return total no of connections opened.
*/
public int getCacheSize() {
return occi.getCacheSize();
}
/**
* Returns the total no of connections that are being used.
*
* @return total no of active connections.
*/
public int getActiveSize() {
return occi.getActiveSize();
}
// ---------------------------------------------------------------- init/close
private OracleConnectionCacheImpl occi = null;
public OracleConnectionPool() {
}
public void init() throws SQLException {
occi = new OracleConnectionCacheImpl();
occi.setURL(url);
occi.setUser(user);
occi.setPassword(password);
occi.setMaxLimit(maxLimit);
occi.setMinLimit(minLimit);
}
public void close() {
try {
occi.close();
} catch (SQLException sex) {
} finally {
occi = null;
}
}
// ---------------------------------------------------------------- get/free
/**
* Get one free connection from the connection pool.
*
* @return Connection object representing free database connection
* @exception Exception
*/
public Connection getConnection() throws SQLException {
return occi.getConnection();
}
/**
* Return connection to connection pool
*
* @param conn database connection
*/
public void freeConnection(Connection conn) {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException se) {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -