kr.co.hit.live.transaction.datasource
Class PooledDataSource

java.lang.Object
  extended by kr.co.hit.live.transaction.datasource.PooledDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource
Direct Known Subclasses:
StandardPooledDataSource, XAPooledDataSource

public abstract class PooledDataSource
extends Object
implements DataSource

PooledConnectionDatasource를 사용하여 Connection pooling을 관리하는 javax.sql.DataSource의 구현을 위한 상위 추상클래스이다. Connection pooling 관리를 위한 기능을 제공하며, 실제 벤더별로 PooledConnection을 생성하는 부분은 하위 클래스에서 구현한다.

생성자에 넘겨주는 Properties 객체에 정의되는 프로퍼티들은 다음과 같다.

Since:
3.0
Version:
$Revision: 1.1 $ $Date: 2006/09/26 08:20:10 $
Author:
김형도

Field Summary
protected  String datasourceName
           
protected  boolean jdbcAutoCommit
           
protected  String jdbcDriver
           
protected  String jdbcPassword
           
protected  String jdbcUrl
           
protected  String jdbcUsername
           
protected  int poolMaxActive
           
protected  int poolMaxIdle
           
protected  long poolTimeToWait
           
protected  int readTimeout
           
 
Constructor Summary
PooledDataSource(Properties props)
           생성자이다.
 
Method Summary
protected abstract  Connection afterGetConnection(Connection con)
           getConnection() 에서 Connection를 리턴하기 전에 호출되는 메소드이다.
 void clear()
           전체 PooledConnection을 모두 close 한다.
protected abstract  PooledConnection createPooledConnection()
           새로운 PooledConnection 객체를 생성한다.
 Connection getConnection()
           Connection 객체를 리턴한다.
 Connection getConnection(String username, String password)
           주어진 사용자 아이디와 암호를 사용하여 데이터베이스에 Connection 객체를 리턴한다.
 String getDatasourceName()
           Datasouce 명을 리턴
abstract  int getLoginTimeout()
           javax.sql.DataSourcegetLoginTimeout() Operation을 구현한다.
abstract  PrintWriter getLogWriter()
           javax.sql.DataSourcegetLogWriter() Operation을 구현한다.
protected  PooledConnection getPooledConnection()
           inactive 상태의 PooledConnection 객체를 가져온다.
abstract  void setLoginTimeout(int seconds)
           javax.sql.DataSourcesetLoginTimeout() Operation을 구현한다.
abstract  void setLogWriter(PrintWriter out)
           javax.sql.DataSourcesetLogWriter() Operation을 구현한다.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Field Detail

jdbcUsername

protected String jdbcUsername

jdbcPassword

protected String jdbcPassword

jdbcUrl

protected String jdbcUrl

jdbcDriver

protected String jdbcDriver

jdbcAutoCommit

protected boolean jdbcAutoCommit

poolMaxActive

protected int poolMaxActive

poolMaxIdle

protected int poolMaxIdle

poolTimeToWait

protected long poolTimeToWait

datasourceName

protected String datasourceName

readTimeout

protected int readTimeout
Constructor Detail

PooledDataSource

public PooledDataSource(Properties props)

생성자이다. 설정에 필요한 속성값들은 Properties 객체내에 정의한다.

Parameters:
props - 생성시 사용할 속성값들이 정의된 Properties 객체
Method Detail

getDatasourceName

public String getDatasourceName()

Datasouce 명을 리턴


createPooledConnection

protected abstract PooledConnection createPooledConnection()
                                                    throws SQLException

새로운 PooledConnection 객체를 생성한다. 하위 클래스에서 구현한다.

Returns:
생성된 PooledConnection 객체
Throws:
SQLException

afterGetConnection

protected abstract Connection afterGetConnection(Connection con)
                                          throws SQLException

getConnection() 에서 Connection를 리턴하기 전에 호출되는 메소드이다. 리턴하기 전에 Connection 객체에 Vendor 별로 고유한 설정이 필요한 경우 여기에 구현한다. 하위 클래스에서 구현한다.

Parameters:
con - 추가 설정을 할 connection 객체
Returns:
Connection 객체
Throws:
SQLException

getConnection

public Connection getConnection()
                         throws SQLException

Connection 객체를 리턴한다. 현재 Transaction 진행여부와 autocommit 설정 여부에 따라서 다음과 같이 Connection 객체를 반환한다.

Specified by:
getConnection in interface DataSource
Returns:
Connection 객체
Throws:
SQLException - 데이터베이스 연결 시 에러가 발생할 때 또는 트랜젝션에 이미 다른 datasource 명으로 Connection 객체가 생성되어 트랜젝션에 연결되어 있는 경우

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException

주어진 사용자 아이디와 암호를 사용하여 데이터베이스에 Connection 객체를 리턴한다. 최초 생성자에서 정의된 사용자 ID 및 암호와 서로 다른 경우에는 SQLException이 발생된다.

Specified by:
getConnection in interface DataSource
Parameters:
username - database 연결시 사용할 사용자 ID
password - 사용자 암호
Returns:
Connection 객체
Throws:
SQLException - 사용자 아이디/암호가 최초 생성시와 다른 경우 또는 데이터베이스 연결 시 에러가 발생할 때

getLogWriter

public abstract PrintWriter getLogWriter()
                                  throws SQLException

javax.sql.DataSourcegetLogWriter() Operation을 구현한다. 하위 클래스에서 구현한다.

Specified by:
getLogWriter in interface CommonDataSource
Returns:
log writer 객체를 리턴, 설정되지 않은 경우에는 null을 리턴
Throws:
SQLException - 데이터베이스 에러가 발생할 때

setLogWriter

public abstract void setLogWriter(PrintWriter out)
                           throws SQLException

javax.sql.DataSourcesetLogWriter() Operation을 구현한다. 하위 클래스에서 구현한다.

Specified by:
setLogWriter in interface CommonDataSource
Parameters:
out - 설정할 log writer 객체
Throws:
SQLException - 데이터베이스 에러가 발생할 때

getLoginTimeout

public abstract int getLoginTimeout()
                             throws SQLException

javax.sql.DataSourcegetLoginTimeout() Operation을 구현한다. 하위 클래스에서 구현한다.

Specified by:
getLoginTimeout in interface CommonDataSource
Returns:
데이터베이스 로그인 최대 시간(초)
Throws:
SQLException - 데이터베이스 에러가 발생할 때

setLoginTimeout

public abstract void setLoginTimeout(int seconds)
                              throws SQLException

javax.sql.DataSourcesetLoginTimeout() Operation을 구현한다. 하위 클래스에서 구현한다.

Specified by:
setLoginTimeout in interface CommonDataSource
Parameters:
seconds - 데이터베이스 로그인 최대 시간(초)
Throws:
SQLException - 데이터베이스 에러가 발생할 때

getPooledConnection

protected PooledConnection getPooledConnection()
                                        throws SQLException

inactive 상태의 PooledConnection 객체를 가져온다. Idel Pool에 PooledConnection이 있다면 그것을 꺼내와 리턴한다. Idle Pool에 PooledConnection이 존재 하지 않을 경우, Active pool의 크기가 최대치보다 작은 경우에는 새로 생성하고 Active pool의 크기가 최대치보다 크거나 같다면, idle pool에 PooledConnection이 반환될 때까지 일정시간 대기한다. 리턴되는 PooledConnection 객체는 active pool에 넣는다.

Returns:
PooledConnection 객체.
Throws:
SQLException - 데이터베이스 에러가 발생할 때

clear

public void clear()

전체 PooledConnection을 모두 close 한다.



Copyright © 2014. All Rights Reserved.