org.apache.commons.dbcp
クラス BasicDataSource

java.lang.Object
  拡張org.apache.commons.dbcp.BasicDataSource
すべての実装インタフェース:
DataSource

public class BasicDataSource
extends Object
implements DataSource

JavaBeans プロパティを介して設定される javax.sql.DataSource の基本的な実装です。 commons-dbcp パッケージと commons-pool パッケージと共にでなければ使用できないわけではありませんが、 基本的な要求に対する "ワンストップ・ショッピング(要は上記パッケージに依存する機能)" ソリューションを提供しています。

Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is not the only way to combine the commons-dbcp and commons-pool packages, but provides a "one stop shopping" solution for basic requirements.

バージョン:
$Revision: 1.1.1.1 $ $Date: 2004/02/13 10:02:03 $
作成者:
Glenn L. Nielsen, Craig R. McClanahan
翻訳者:
日置 聡
翻訳状況:
初稿(校正者募集中)
翻訳更新日:
2003/09/13

フィールドの概要
protected  org.apache.commons.pool.impl.GenericObjectPool connectionPool
          内部でコネクションを管理するオブジェクトプールです。
protected  Properties connectionProperties
          新たなコネクションを確立する際に JDBC ドライバに渡されるコネクションプロパティです。
protected  DataSource dataSource
          コネクションの管理に使用するデータソースです。
protected  boolean defaultAutoCommit
          このプールにて生成されるコネクションのデフォルトのオートコミットのステータス。
protected  boolean defaultReadOnly
          このプールにて生成されるコネクションのデフォルトの読み込み専用のステータス。
protected  String driverClassName
          使用する JDBC ドライバの Java クラスの完全修飾名です。
protected  PrintWriter logWriter
          メッセージを直接ログする対象となる PrintWriter です。
protected  int maxActive
          このプールから1度に割り当てることのできるアクティブなコネクションの最大数です。
protected  int maxIdle
          このプール内で開放されずにアイドル状態でいられるアクティブなコネクションの最大数です。
protected  long maxWait
          利用可能なコネクションがない場合に例外を投げるまでプールが待機するミリセカンドの最大値です。
protected  String password
          コネクションを確立する際に JDBC ドライバに渡されるコネクションパスワードです。
protected  String url
          コネクションを確立する際に JDBC ドライバに渡されるコネクションURLです。
protected  String username
          コネクションを確立する際に JDBC ドライバに渡されるコネクションユーザ名です。
protected  String validationQuery
          このプールにコネクションが返された後にコネクションのチェックに使用される SQL クエリです。
 
コンストラクタの概要
BasicDataSource()
           
 
メソッドの概要
 void addConnectionProperty(String name, String value)
          JDBC ドライバに渡すプロパティのセットにカスタムコネクションプロパティを追加します。
 void close()
          このデータソースに関連づいているコネクションプールに現在保持されている全てのコネクションをクローズし、開放します。
protected  DataSource createDataSource()
           コネクションの管理に使用するデータソースを(必要であれば)生成し、返します。
 Connection getConnection()
          データベースへのコネクションを(必要であれば)生成し、返します。
 Connection getConnection(String username, String password)
          データベースへのコネクションを(必要であれば)生成し、返します。
 boolean getDefaultAutoCommit()
           
 boolean getDefaultReadOnly()
           
 String getDriverClassName()
           
 boolean getLogAbandoned()
          ステートメントまたはコネクションを破棄したアプリケーションのスタックトレースをログするかどうかのフラグです。
 int getLoginTimeout()
          データベースに接続する際のログインタイムアウト時間(秒)を返します。
 PrintWriter getLogWriter()
          このデータソースで使用されるログライターを返します。
 int getMaxActive()
           
 int getMaxIdle()
           
 long getMaxWait()
           
 int getNumActive()
          [読取専用] 現在このデータソースから割り当てられているアクティブなコネクションの数を取得します。
 int getNumIdle()
          [読取専用] 現在このデータソース内で割り当てられるのを待っているアイドル状態のコネクションの数を取得します。
 String getPassword()
           
 boolean getRemoveAbandoned()
          removeAbandonedTimeout を超えた場合に破棄されたコネクションを削除するかどうかのフラグです。
 int getRemoveAbandonedTimeout()
          破棄されたコネクションを削除する処理のタイムアウト時間(秒)です。
 String getUrl()
           
 String getUsername()
           
 String getValidationQuery()
           
 void setDefaultAutoCommit(boolean defaultAutoCommit)
           
 void setDefaultReadOnly(boolean defaultReadOnly)
           
 void setDriverClassName(String driverClassName)
           
 void setLogAbandoned(boolean logAbandoned)
           
 void setLoginTimeout(int loginTimeout)
          データベースに接続する際のログインタイムアウト時間(秒)を設定します。
 void setLogWriter(PrintWriter logWriter)
          このデータソースで使用されるログライターを設定します。
 void setMaxActive(int maxActive)
           
 void setMaxIdle(int maxIdle)
           
 void setMaxWait(long maxWait)
           
 void setPassword(String password)
           
 void setRemoveAbandoned(boolean removeAbandoned)
           
 void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
 void setValidationQuery(String validationQuery)
           
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

connectionPool

protected org.apache.commons.pool.impl.GenericObjectPool connectionPool
内部でコネクションを管理するオブジェクトプールです。
The object pool that internally manages our connections.


connectionProperties

protected Properties connectionProperties
新たなコネクションを確立する際に JDBC ドライバに渡されるコネクションプロパティです。 - "user" と "password" のプロパティは他の場所で設定されるため、ここに含まれる必要はありません。
The connection properties that will be sent to our JDBC driver when establishing new connections. NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here.


dataSource

protected DataSource dataSource
コネクションの管理に使用するデータソースです。 このオブジェクトは createDataSource() メソッドを呼ぶことによってのみ取得されるべきです。
The data source we will use to manage connections. This object should be acquired ONLY by calls to the createDataSource() method.


defaultAutoCommit

protected boolean defaultAutoCommit
このプールにて生成されるコネクションのデフォルトのオートコミットのステータス。
The default auto-commit state of connections created by this pool.


defaultReadOnly

protected boolean defaultReadOnly
このプールにて生成されるコネクションのデフォルトの読み込み専用のステータス。
The default read-only state of connections created by this pool.


driverClassName

protected String driverClassName
使用する JDBC ドライバの Java クラスの完全修飾名です。
The fully qualified Java class name of the JDBC driver to be used.


logWriter

protected PrintWriter logWriter
メッセージを直接ログする対象となる PrintWriter です。
The PrintWriter to which log messages should be directed.


maxActive

protected int maxActive
このプールから1度に割り当てることのできるアクティブなコネクションの最大数です。 0が設定された場合には制限を行いません。
The maximum number of active connections that can be allocated from this pool at the same time, or zero for no limit.


maxIdle

protected int maxIdle
このプール内で開放されずにアイドル状態でいられるアクティブなコネクションの最大数です。 0が設定された場合には制限を行いません。
The maximum number of active connections that can remain idle in the pool, without extra ones being released, or zero for no limit.


maxWait

protected long maxWait
利用可能なコネクションがない場合に例外を投げるまでプールが待機するミリセカンドの最大値です。 -1が設定された場合には期限を持たず待機します。
The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception, or -1 to wait indefinitely.


password

protected String password
コネクションを確立する際に JDBC ドライバに渡されるコネクションパスワードです。
The connection password to be passed to our JDBC driver to establish a connection.


url

protected String url
コネクションを確立する際に JDBC ドライバに渡されるコネクションURLです。
The connection URL to be passed to our JDBC driver to establish a connection.


username

protected String username
コネクションを確立する際に JDBC ドライバに渡されるコネクションユーザ名です。
The connection username to be passed to our JDBC driver to establish a connection.


validationQuery

protected String validationQuery
このプールにコネクションが返された後にコネクションのチェックに使用される SQL クエリです。 指定する場合にはこのクエリは少なくとも1つの列を返す SQL SELECT ステートメントでなくてはなりません
The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row.

コンストラクタの詳細

BasicDataSource

public BasicDataSource()
メソッドの詳細

addConnectionProperty

public void addConnectionProperty(String name,
                                  String value)
JDBC ドライバに渡すプロパティのセットにカスタムコネクションプロパティを追加します。 これは最初のコネクションを取得する前に(他の接続の設定と共に)行わなくてはなりません。
Add a custom connection property to the set that will be passed to our JDBC driver. This MUST be called before the first connection is retrieved (along with all the other configuration property setters).

パラメータ:
name - カスタムコネクションプロパティの名前
Name of the custom connection property
value - カスタムコネクションプロパティの値
Value of the custom connection property

close

public void close()
           throws SQLException
このデータソースに関連づいているコネクションプールに現在保持されている全てのコネクションをクローズし、開放します。
Close and release all connections that are currently stored in the connection pool associated with our data source.

例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

createDataSource

protected DataSource createDataSource()
                               throws SQLException

コネクションの管理に使用するデータソースを(必要であれば)生成し、返します。

Create (if necessary) and return the internal data source we are using to manage our connections.

実装の注 - このメソッドの同期化を行わず "double-checked locking" イディオムの使用を試みる誘惑にかられますが、 JVM の動作に関する正規のいくつかの最適化が行われた場合、このイディオムは正確に機能しません。

[訳注: "double-checked locking" の問題に関しては developerWorks に良い記事があります。]
IMPLEMENTATION NOTE - It is tempting to use the "double checked locking" idiom in an attempt to avoid synchronizing on every single call to this method. However, this idiom fails to work correctly in the face of some optimizations that are legal for a JVM to perform.

例外:
SQLException - オブジェクトプールが生成できなかった場合
if the object pool cannot be created.

getConnection

public Connection getConnection()
                         throws SQLException
データベースへのコネクションを(必要であれば)生成し、返します。
Create (if necessary) and return a connection to the database.

定義:
インタフェース DataSource 内の getConnection
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
データベースへのコネクションを(必要であれば)生成し、返します。
Create (if necessary) and return a connection to the database.

定義:
インタフェース DataSource 内の getConnection
パラメータ:
username - コネクションを生成するためのデータベースユーザ
Database user on whose behalf the Connection is being made
password - データベースユーザのパスワード
The database user's password
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

getDefaultAutoCommit

public boolean getDefaultAutoCommit()

getDefaultReadOnly

public boolean getDefaultReadOnly()

getDriverClassName

public String getDriverClassName()

getLogAbandoned

public boolean getLogAbandoned()
ステートメントまたはコネクションを破棄したアプリケーションのスタックトレースをログするかどうかのフラグです。 デフォルトの値は false です。 破棄されたステートメントまたはコネクションのログ処理は 全てのコネクションを開く処理またはステートメントの生成時にスタックトレースを生成するためオーバヘッドを与えます。
Flag to log stack traces for application code which abandoned a Statement or Connection. Defaults to false. Logging of abandoned Statements and Connections adds overhead for every Connection open or new Statement because a stack trace has to be generated.


getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
データベースに接続する際のログインタイムアウト時間(秒)を返します。
Return the login timeout (in seconds) for connecting to the database.

定義:
インタフェース DataSource 内の getLoginTimeout
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
このデータソースで使用されるログライターを返します。
Return the log writer being used by this data source.

定義:
インタフェース DataSource 内の getLogWriter
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

getMaxActive

public int getMaxActive()

getMaxIdle

public int getMaxIdle()

getMaxWait

public long getMaxWait()

getNumActive

public int getNumActive()
[読取専用] 現在このデータソースから割り当てられているアクティブなコネクションの数を取得します。
[Read Only] The current number of active connections that have been allocated from this data source.


getNumIdle

public int getNumIdle()
[読取専用] 現在このデータソース内で割り当てられるのを待っているアイドル状態のコネクションの数を取得します。
[Read Only] The current number of idle connections that are waiting to be allocated from this data source.


getPassword

public String getPassword()

getRemoveAbandoned

public boolean getRemoveAbandoned()
removeAbandonedTimeout を超えた場合に破棄されたコネクションを削除するかどうかのフラグです。 true か false を設定してください。デフォルトは false です。 true を設定した場合、アイドル時間が removeAbandonedTimeout を超えたコネクションは破棄され、削除されるべきであるとみなされます。 true を設定することによりコネクションのクローズ処理を失敗したときの処理があまり考慮されていない アプリケーションのデータベースコネクションを回復させることができます。
Flag to remove abandoned connections if they exceed the removeAbandonedTimeout. Set to true or false, default false. If set to true a connection is considered abandoned and eligible for removal if it has been idle longer than the removeAbandonedTimeout. Setting this to true can recover db connections from poorly written applications which fail to close a connection.


getRemoveAbandonedTimeout

public int getRemoveAbandonedTimeout()
破棄されたコネクションを削除する処理のタイムアウト時間(秒)です。 デフォルトは300秒です。
Timeout in seconds before an abandoned connection can be removed. Defaults to 300 seconds.


getUrl

public String getUrl()

getUsername

public String getUsername()

getValidationQuery

public String getValidationQuery()

setDefaultAutoCommit

public void setDefaultAutoCommit(boolean defaultAutoCommit)

setDefaultReadOnly

public void setDefaultReadOnly(boolean defaultReadOnly)

setDriverClassName

public void setDriverClassName(String driverClassName)

setLogAbandoned

public void setLogAbandoned(boolean logAbandoned)

setLoginTimeout

public void setLoginTimeout(int loginTimeout)
                     throws SQLException
データベースに接続する際のログインタイムアウト時間(秒)を設定します。
Set the login timeout (in seconds) for connecting to the database.

定義:
インタフェース DataSource 内の setLoginTimeout
パラメータ:
loginTimeout - 新たなログインタイムアウト時間、0の場合タイムアウトしません
The new login timeout, or zero for no timeout
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

setLogWriter

public void setLogWriter(PrintWriter logWriter)
                  throws SQLException
このデータソースで使用されるログライターを設定します。
Set the log writer being used by this data source.

定義:
インタフェース DataSource 内の setLogWriter
パラメータ:
logWriter - 新たなログライター
The new log writer
例外:
SQLException - データベースアクセスで例外が発生した場合
if a database access error occurs

setMaxActive

public void setMaxActive(int maxActive)

setMaxIdle

public void setMaxIdle(int maxIdle)

setMaxWait

public void setMaxWait(long maxWait)

setPassword

public void setPassword(String password)

setRemoveAbandoned

public void setRemoveAbandoned(boolean removeAbandoned)

setRemoveAbandonedTimeout

public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)

setUrl

public void setUrl(String url)

setUsername

public void setUsername(String username)

setValidationQuery

public void setValidationQuery(String validationQuery)


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation