001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.hayabusa.db;
017
018import java.sql.Connection;
019import java.sql.ResultSet;
020import java.sql.SQLException;
021
022import org.opengion.fukurou.db.Transaction;
023import org.opengion.fukurou.db.ConnectionFactory;               // 5.3.8.0 (2011/08/01)
024import org.opengion.fukurou.util.ErrorMessage;
025import org.opengion.hayabusa.common.HybsSystem;
026import org.opengion.hayabusa.common.HybsSystemException;
027import org.opengion.hayabusa.resource.ResourceManager;
028
029/**
030 * Query インターフェースを継承した Query の実装クラスです。
031 * クエリークラスにステートメントを与えて execute()することにより内部に DBTableModel を
032 * 作成します。
033 * このクラスは、Abstract クラスのため、実装は個々のサブクラスで行います。
034 * 唯一実装する必要があるのは, execute() メソッドだけです。
035 *
036 * @og.group DB検索
037 * @og.group DB登録
038 *
039 * @version  4.0
040 * @author       Kazuhiko Hasegawa
041 * @since    JDK5.0,
042 */
043public class AbstractQuery implements Query {
044        private Connection              connection      = null ;
045        private Transaction             transaction     = null ;        // 5.1.9.0 (2010/08/01)
046        private int                     rtnCode         = ErrorMessage.OK;
047        private ErrorMessage    errMessage      = null;
048        private ResourceManager resource        = null;
049//      private ApplicationInfo appInfo         = null;         // 5.1.9.0 (2010/08/01) ローカル化
050
051        private DBTableModel table                      = null;
052        private String           connID                 = null;
053        private String           stmtString             = null;
054        private int              executeCount   = -1 ;
055        private int              skipRowCount   = 0 ;
056        private int              maxRowCount    = HybsSystem.sysInt( "DB_MAX_ROW_COUNT" ) ;
057        private boolean          updateFlag             = true ;
058        private DBEditConfig config                     = null; // 5.3.6.0 (2011/06/01)
059
060        // 5.1.9.0 (2010/08/01) DB_RETRY_COUNT,DB_RETRY_TIME 廃止
061//      private static final int DB_RETRY_COUNT         = HybsSystem.sysInt( "DB_RETRY_COUNT" ) ;
062//      private static final int DB_RETRY_TIME          = HybsSystem.sysInt( "DB_RETRY_TIME" ) ;
063        protected static final int DB_MAX_QUERY_TIMEOUT = HybsSystem.sysInt( "DB_MAX_QUERY_TIMEOUT" ) ;
064
065        // 3.5.2.0 (2003/10/20) 内部オブジェクトタイプ名を システムパラメータ で定義します。
066        /** 内部オブジェクトタイプ名  {@value} */
067        public static final String ARG_ARRAY            = "ARG_ARRAY" ;
068        /** 内部オブジェクトタイプ名  {@value} */
069        public static final String SYSARG_ARRAY         = "SYSARG_ARRAY" ;
070        /** 内部オブジェクトタイプ名  {@value} */
071        public static final String ERR_MSG                      = "ERR_MSG" ;
072        /** 内部オブジェクトタイプ名  {@value} */
073        public static final String ERR_MSG_ARRAY        = "ERR_MSG_ARRAY" ;
074
075        /**
076         * Queryオブジェクトを初期化します。
077         * これは、QueryFactory のプールから取り出すときに(または戻すとき)に
078         * 初期化するのに使用します。
079         *
080         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
081         * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得の為,ApplicationInfoオブジェクトを設定
082         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性(外部Transactionの使用)追加
083         * @og.rev 5.3.6.0 (2011/06/01) DBEditConfig 追加
084         *
085         */
086        public void init() {
087                close();                                        // 先にクローズ処理を行います。(transaction = null がセット)
088                rtnCode                 = ErrorMessage.OK;
089                errMessage              = null;
090                resource                = null;
091//              appInfo                 = null;         // 5.1.9.0 (2010/08/01) ローカル化
092                table                   = null;
093                connID                  = null;
094                stmtString              = null;
095                executeCount    = -1 ;
096                skipRowCount    = 0 ;
097                maxRowCount             = HybsSystem.sysInt( "DB_MAX_ROW_COUNT" ) ;
098                updateFlag              = true ;
099                connection              = null;         // 5.1.9.0 (2010/08/01) キャッシュの初期化
100                config                  = null;         // 5.3.6.0 (2011/06/01) DBEditConfig追加
101        }
102
103        /**
104         * ステートメント文字列をセットします。
105         *
106         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
107         *
108         * @param       stmt ステートメント文字列
109         *
110         */
111        public void setStatement( final String stmt ) {
112                this.stmtString = stmt.trim();
113        }
114
115        /**
116         * ステートメント文字列を取り出します。
117         *
118         * @return       ステートメント文字列
119         *
120         */
121        public String getStatement() {
122                return stmtString;
123        }
124
125        /**
126         * クエリーを実行します。
127         * 実行方法等は各サブクラスの実装に依存します。
128         * セットされているステートメント文字列とそのタイプが合っていない場合は,
129         * エラーになります。
130         * 実行結果は、DBTableModel にセットされます。
131         * 実行結果の件数は #getExecuteCount() で取得できます。
132         * ※ このクラスでは実装されていません。
133         *
134         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
135         *
136         */
137        public void execute() {
138                String errMsg = "このクラスでは実装されていません。execute()";
139                throw new UnsupportedOperationException( errMsg );
140        }
141
142        /**
143         * 引数配列付のクエリーを実行します。
144         * 処理自体は, #execute() と同様に、各サブクラスの実装に依存します。
145         * これは、PreparedQuery で使用する引数を配列でセットするものです。
146         * select * from emp where deptno = ? and job = ? などの PreparedQuery や
147         * { call xxxx( ?,?,? ) } などの CallableStatement の ? 部分の引数を
148         * 順番にセットしていきます。
149         * ※ このクラスでは実装されていません。
150         *
151         * @param       args オブジェクトの引数配列
152         */
153        public void execute( final String[] args ) {
154                String errMsg = "このクラスでは実装されていません。execute( String[] )";
155                throw new UnsupportedOperationException( errMsg );
156        }
157
158        /**
159         * 引数配列付のクエリーを実行します。
160         * 処理自体は, #execute() と同様に、各サブクラスの実装に依存します。
161         * これは、PreparedQuery で使用する引数を配列でセットするものです。
162         * select * from emp where deptno = ? and job = ? などの PreparedQuery の
163         * ? 部分の引数を
164         * 順番にセットしていきます。
165         * ※ このクラスでは実装されていません。
166         *
167         * @og.rev 4.0.0.0 (2005/01/31) 新規追加
168         *
169         * @param   keys オブジェクトのキー配列
170         * @param   args オブジェクトの引数配列
171         */
172        public void execute( final String[] keys, final String[] args ) {
173                String errMsg = "このクラスでは実装されていません。execute( String[],String[] )";
174                throw new UnsupportedOperationException( errMsg );
175        }
176
177        /**
178         * 引数配列付のクエリーを実行します。
179         * 処理自体は, #execute() と同様に、各サブクラスの実装に依存します。
180         * これは、PreparedQuery で使用する引数を配列でセットするものです。
181         * select * from emp where deptno = ? and job = ? などの PreparedQuery の
182         * ? 部分の引数を
183         * 順番にセットしていきます。
184         * ※ このクラスでは実装されていません。
185         *
186         * @og.rev 4.0.0.0 (2005/01/31) 引数をすべて受け取って実行するメソッドを標準メソッドとして追加
187         *
188         * @param       names           カラム名(CSV形式)
189         * @param       dbArrayType     アレイタイプ名称
190         * @param       sysArg          DBSysArg配列
191         * @param       userArg         DBUserArg配列
192         */
193        public void execute( final String names,final String dbArrayType,
194                                                final DBSysArg[] sysArg,final DBUserArg[] userArg ) {
195                String errMsg = "このクラスでは実装されていません。execute( String,String,DBSysArg[],DBUserArg[] )";
196                throw new UnsupportedOperationException( errMsg );
197        }
198
199        /**
200         * 引数配列付のクエリーを実行します。
201         * 処理自体は, #execute() と同様に、各サブクラスの実装に依存します。
202         * これは、PreparedQuery で使用する引数を配列でセットするものです。
203         * select * from emp where deptno = ? and job = ? などの PreparedQuery の
204         * [カラム名] 部分の引数を、DBTableModelから順番にセットしていきます。
205         * ※ このクラスでは実装されていません。
206         *
207         * @param   rowNo 選択された行番号配列(登録する対象行)
208         * @param   table DBTableModelオブジェクト(登録する元データ)
209         */
210        public void execute( final int[] rowNo, final DBTableModel table ) {
211                String errMsg = "このクラスでは実装されていません。execute( final int[] rowNo, final DBTableModel table )";
212                throw new UnsupportedOperationException( errMsg );
213        }
214
215        /**
216         * コミットを行います。
217         *
218         * 外部からコネクションが与えられた場合は、何も行いません。
219         *
220         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
221         * @og.rev 3.8.0.8 (2005/10/03) エラーメッセージの出力順をメッセージ+Queryに変更します。
222         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性追加。
223         *
224         */
225        public void commit() {
226                if( transaction == null ) { return; }
227
228                if( !transaction.commit() ) {
229                        transaction.rollback();
230                        realClose();
231                        String errMsg = "コミットすることが出来ませんでした。" + HybsSystem.CR
232                                                + getStatement() + HybsSystem.CR ;
233                        throw new HybsSystemException( errMsg );
234                }
235
236//              if( connection == null ) { return; }
237//              try {
238//                      connection.commit();
239//              }
240//              catch( SQLException ex ) {
241//                      transaction.rollback();                         // 5.1.9.0 (2010/08/01)
242//                      realClose();
243//                      String errMsg = "コミットすることが出来ませんでした。" + HybsSystem.CR
244//                                              + ex.getMessage() + ":" + ex.getSQLState()
245//                                              + HybsSystem.CR + getStatement() + HybsSystem.CR ;
246//                      throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並び順変更
247//              }
248        }
249
250        /**
251         * ロールバックを行います。
252         *
253         * 外部からコネクションが与えられた場合は、何も行いません。
254         *
255         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
256         * @og.rev 3.8.0.8 (2005/10/03) エラーメッセージの出力順をメッセージ+Queryに変更します。
257         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性追加。
258         *
259         */
260        public void rollback() {
261                if( transaction == null ) { return; }
262
263                if( !transaction.rollback() ) {
264                        realClose();
265                        String errMsg = "ロールバックすることが出来ません。" + HybsSystem.CR
266                                                 + getStatement() + HybsSystem.CR ;
267                        throw new HybsSystemException( errMsg );
268                }
269
270//              if( connection == null ) { return; }
271//              try {
272//                      connection.rollback();
273//              }
274//              catch( SQLException ex ) {
275//                      if( transaction != null ) { transaction.rollback(); }   // 5.1.9.0 (2010/08/01)
276//                      realClose();
277//                      String errMsg = "ロールバックすることが出来ません。" + HybsSystem.CR
278//                                               + ex.getMessage() + ":" + ex.getSQLState()
279//                                               + HybsSystem.CR + getStatement() + HybsSystem.CR ;
280//                      throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並び順変更
281//              }
282        }
283
284        /**
285         * 使用した Statementオブジェクトをクロースし、Connection オブジェクトを
286         * プールに返します。
287         * 主に、正常終了した場合のクローズ処理になります。
288         *
289         * 外部からコネクションが与えられた場合は、何も行いません。
290         *
291         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
292         * @og.rev 3.6.0.4 (2004/10/14) SQLWarning の取得(getWarning)をコメントアウトします。
293         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性追加。
294         * @og.rev 5.3.8.0 (2011/08/01) Transaction発生箇所でclose()するため、ここではclose() しない。
295         *
296         */
297        public void close() {
298//              if( transaction != null ) {
299//                      transaction.close();    // 正常な場合のクローズ
300//                      transaction = null;
301//              }
302
303//              if( connection != null ) {
304//                      try {
305//                              // 4.0.0 (2005/01/31)
306//                              if( rtnCode > ErrorMessage.NG ) {
307//                                      realClose();
308//                              }
309//                      }
310//                      finally {
311//                              ConnectionFactory.close( connection,connID );   // 4.0.0 (2005/01/31)
312//                              connection = null;
313//                      }
314//              }
315        }
316
317        /**
318         * Connection オブジェクトを実際にクローズ(破棄)します。
319         * プールからも削除します。
320         * 実行時エラー等が発生したときに、このメソッドを呼び出します。
321         *
322         * 外部からコネクションが与えられた場合は、何も行いません。
323         *
324         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
325         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性追加。
326         * @og.rev 5.3.8.0 (2011/08/01) Transaction発生箇所でclose()するため、ここではclose() しない。
327         *
328         */
329        public void realClose() {
330//              if( transaction != null ) {
331//                      transaction.close( true );      // エラーが発生した場合のクローズ
332//                      transaction = null;
333//              }
334
335//              if( connection != null ) {
336//                      ConnectionFactory.remove( connection,connID );
337//                      connection = null;
338//              }
339        }
340
341        /**
342         * クエリーの実行結果件数をセットします。
343         * 初期値は -1 です。(クエリーが失敗した場合や,CallableStatement の呼び出し等で
344         * 実行件数が明確でない場合の戻り値)。
345         *
346         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
347         *
348         * @param       executeCount 実行結果件数
349         */
350        protected void setExecuteCount( final int executeCount ) {
351                this.executeCount = executeCount;
352        }
353
354        /**
355         * クエリーの実行結果を返します。
356         * クエリーが失敗した場合や,CallableStatement の呼び出し等で実行件数が明確でない
357         * 場合は, -1 が返されます。
358         *
359         * @return      実行結果件数
360         */
361        public int getExecuteCount() {
362                return executeCount;
363        }
364
365        /**
366         * DBTableModel をセットします。
367         * なお、検索系実行前に setDBTableModel() でテーブルをセットしていたとしても
368         * そのオブジェクトは破棄されて、新しい DBTableModel が生成されます。
369         *
370         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
371         *
372         * @param       table DBTableModelオブジェクト
373         */
374        protected void setDBTableModel( final DBTableModel table ) {
375                this.table = table;
376        }
377
378        /**
379         * 実行結果の DBTableModel を返します。
380         *
381         * @return      DBTableModelオブジェクト
382         */
383        public DBTableModel getDBTableModel() {
384                return table;
385        }
386
387        /**
388         * データベースの最大検索件数を返します。
389         *              (初期値:DB_MAX_ROW_COUNT[={@og.value org.opengion.hayabusa.common.SystemData#DB_MAX_ROW_COUNT}])。
390         * データベース自体の検索は,指定されたSQLの全件を検索しますが,
391         * DBTableModelのデータとして登録する最大件数をこの値に設定します。0は無制限です。
392         * サーバーのメモリ資源と応答時間の確保の為です。
393         *
394         * @return      最大検索件数
395         */
396        public int getMaxRowCount() {
397                return maxRowCount;
398        }
399
400        /**
401         * データベースの最大検索件数をセットします。
402         * データベース自体の検索は,指定されたSQLの全件を検索しますが,
403         * DBTableModelのデータとして登録する最大件数をこの値に設定します。
404         * サーバーのメモリ資源と応答時間の確保の為です。
405         * ゼロ、または、負の値を設定すると、無制限(Integer.MAX_VALUE)になります。
406         *
407         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
408         * @og.rev 4.0.0.0 (2005/08/31) ゼロ、または、負の値は、無制限(Integer.MAX_VALUE)にする。
409         *
410         * @param       maxRowCount 最大検索件数
411         */
412        public void setMaxRowCount( final int maxRowCount ) {
413                this.maxRowCount = ( maxRowCount > 0 ) ? maxRowCount : Integer.MAX_VALUE ;
414        }
415
416        /**
417         * データベースの検索スキップ件数を返します。
418         * データベース自体の検索は,指定されたSQLの全件を検索しますが,
419         * DBTableModelのデータとしては、スキップ件数分は登録されません。
420         * サーバーのメモリ資源と応答時間の確保の為です。
421         *
422         * @return      最大検索件数
423         */
424        public int getSkipRowCount() {
425                return skipRowCount;
426        }
427
428        /**
429         * データベースの検索スキップ件数をセットします。
430         * データベース自体の検索は,指定されたSQLの全件を検索しますが,
431         * DBTableModelのデータとしては、スキップ件数分は登録されません。
432         * サーバーのメモリ資源と応答時間の確保の為です。
433         *
434         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
435         *
436         * @param       skipRowCount スキップ件数
437         */
438        public void setSkipRowCount( final int skipRowCount ) {
439                this.skipRowCount = skipRowCount;
440        }
441
442        /**
443         * データベースの接続先IDをセットします。
444         * システムパラメータ ファイルに定義してある データベース識別IDによって、
445         * 接続先を切り替えます。
446         * この接続先IDを元に,Connection オブジェクトを作成します。
447         *
448         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
449         * @og.rev 5.1.9.0 (2010/08/01) 廃止
450         *
451         * @param       connID 接続先ID
452         */
453//      public void setConnectionID( final String connID ) {
454//              close();
455//              this.connID = connID;
456//      }
457
458        /**
459         * アップデートフラグをセットします。
460         * これは、Query で更新処理の SQL 文を実行したときにセットされます。
461         * 更新処理が実行:true / 検索処理のみ:false をセットします。
462         * このメソッドを呼び出さない場合は、デフォルト:true  です。
463         *
464         * @og.rev 2.1.2.3 (2002/12/02) データベース更新時に、更新フラグをセットするように変更
465         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
466         *
467         * @param       up      アップデートされたかどうか[true:更新処理/false:検索処理]
468         */
469        protected void setUpdateFlag( final boolean up ) {
470                updateFlag = up;
471        }
472
473        /**
474         * アップデートフラグを取得します。
475         * これは、Query で更新処理の SQL 文を実行したときに true にセットされます。
476         * 更新処理が実行:true / 検索処理のみ:false を取得できます。
477         *
478         * @og.rev 2.1.2.3 (2002/12/02) データベース更新時に、更新フラグをセットするように変更
479         * @og.rev 4.0.0.0 (2007/07/20) メソッド名変更( getUpdateFlag() ⇒ isUpdate() )
480         *
481         * @return       アップデートされたかどうか[true:更新処理/false:検索処理]
482         */
483        public boolean isUpdate() {
484                return updateFlag ;
485        }
486
487        /**
488         * リソースマネージャーをセットします。
489         * これは、言語(ロケール)に応じた DBColumn をあらかじめ設定しておく為に
490         * 必要です。
491         * リソースマネージャーが設定されていない、または、所定のキーの DBColumn が
492         * リソースに存在しない場合は、内部で DBColumn オブジェクトを作成します。
493         *
494         * @og.rev 4.0.0.0 (2005/01/31) lang ⇒ ResourceManager へ変更
495         *
496         * @param       resource リソースマネージャー
497         */
498        public void setResourceManager( final ResourceManager resource ) {
499                this.resource = resource;
500        }
501
502        /**
503         * アクセスログ取得の為,ApplicationInfoオブジェクトを設定します。
504         *
505         * @og.rev 3.8.7.0 (2006/12/15) 新規追加
506         * @og.rev 5.1.9.0 (2010/08/01) 廃止
507         *
508         * @param   appInfo ApplicationInfo
509         */
510//      public void setApplicationInfo( final ApplicationInfo appInfo ) {
511//              this.appInfo = appInfo;
512//      }
513
514        /**
515         * 内部のリソースを元に言語コード を返します。
516         * 内部にリソースが登録されていない場合は, null を返します。
517         *
518         * @og.rev 5.3.6.0 (2011/06/01) 廃止
519         *
520         * @return       言語コード
521         */
522//      public String getLang() {
523//              String lang = null;
524//              if( resource != null ) { lang = resource.getLang(); }
525//              return lang;
526//      }
527
528        /**
529         * エラーコード を取得します。
530         * エラーコード は、ErrorMessage クラスで規定されているコードです。
531         *
532         * @return   エラーコード
533         */
534        public int getErrorCode() { return rtnCode; }
535
536        /**
537         * エラーコード をセットします。
538         * エラーコード は、ErrorMessage クラスで規定されているコードです。
539         *
540         * @param   cd エラーコード
541         */
542        protected void setErrorCode( final int cd ) { rtnCode = cd; }
543
544        /**
545         * エラーメッセージオブジェクト を取得します。
546         *
547         * @return   エラーメッセージオブジェクト
548         */
549        public ErrorMessage getErrorMessage() { return errMessage; }
550
551        /**
552         * エラーメッセージオブジェクト をセットします。
553         *
554         * @param   em エラーメッセージオブジェクト
555         */
556        protected void setErrorMessage( final ErrorMessage em ) { errMessage = em; }
557
558        /**
559         * エディット設定オブジェクトをセットします。
560         *
561         * @og.rev 5.3.6.0 (2011/06/01) 新規追加
562         *
563         * @param config エディット設定オブジェクト
564         */
565        public void setEditConfig( final DBEditConfig config ) {
566                this.config = config;
567        }
568
569        /**
570         * エディット設定オブジェクトを取得します。
571         *
572         * @og.rev 5.3.6.0 (2011/06/01) 新規追加
573         *
574         * @return エディット設定オブジェクト
575         */
576        protected DBEditConfig getEditConfig() {
577                return config;
578        }
579
580        //////////////////////////////////////////////////////////////////////////
581        //
582        //       継承時にサブクラスから使用するメソッド類( protected )
583        //
584        //////////////////////////////////////////////////////////////////////////
585
586        /**
587         * ResultSet を DBTableModelに割り当てます。
588         *
589         * 毎回,検索毎に,DBTableModel にコピーするイメージです。
590         * ResulSet 以外のオブジェクトから,DBTableModelを作成する場合は,
591         * このメソッドをオーバーライドします。
592         *
593         * このメソッドは, execute からのみ,呼び出されます。
594         * それ以外からは呼出し出来ません。
595         *
596         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
597         * @og.rev 3.3.3.3 (2003/08/06) カラムのラベル名を、大文字に変換する。
598         * @og.rev 3.8.5.0 (2006/03/02) CLOB カラムかどうかを判定しCLOBの場合は、Clob オブジェクトから文字列を取り出します。
599         * @og.rev 3.8.8.8 (2007/05/11) ROWID対応(小数点対応 "0.3" が ".3" と表示される対策)
600         * @og.rev 4.0.0.0 (2006/01/31) CLOB カラムかどうかを判定しCLOBの場合は、ストリームから値を取り出します。
601         * @og.rev 5.3.6.0 (2011/06/01) DBTableModel作成処理をDBTableModelUtilに移動&集計機能対応
602         *
603         * @param       resultSet ResultSetオブジェクト
604         */
605        protected void createTableModel( final ResultSet resultSet ) {
606                try {
607                        if( config == null ) {
608                                table = DBTableModelUtil.makeDBTable( resultSet, getSkipRowCount(), maxRowCount, resource );
609                        }
610                        else {
611                                table = DBTableModelUtil.makeEditDBTable( resultSet, getSkipRowCount(), maxRowCount, resource, config );
612                        }
613
614                        setExecuteCount( table.getRowCount() );
615                }
616                catch( SQLException ex ) {
617                        realClose();
618                        String errMsg = "テーブルモデルを作成できませんでした。";
619                        throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並び順変更
620                }
621        }
622
623        /**
624         * ConnectionFactory.connection( String ); を利用して,Connection
625         * オブジェクトを取り出します。
626         *
627         * コネクションプールが一杯の場合は、即エラーになります。
628         *
629         * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
630         * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得の為,ApplicationInfoオブジェクトを設定
631         * @og.rev 5.1.9.0 (2010/08/01) transaction 属性追加。
632         *
633         * @return      コネクション
634         */
635        protected Connection getConnection() {
636//              if( connection != null ) { return connection; }
637
638                if( connection == null ) {
639                        // 5.1.9.0 (2010/08/01) transaction 属性追加。
640                        if( transaction == null ) {
641                                String errMsg = "Transaction をセットする前に、コネクションを取り出す要求がなされました。"
642                                                                + HybsSystem.CR
643                                                                + "connID = [" + connID + "]" ;
644                                throw new HybsSystemException( errMsg );
645                        }
646                        else {
647                                connection = transaction.getConnection( connID );
648                        }
649                }
650
651                return connection;
652
653//              MissingResourceException exTemp = null;
654//              for( int i=0; i<DB_RETRY_COUNT; i++ ) {
655//                      try {
656//                              connection = ConnectionFactory.connection( connID,appInfo );
657//                              return connection;
658//                      }
659//                      catch( MissingResourceException ex ) {
660//                              try {
661//                                      exTemp = ex;
662//                                      Thread.sleep( DB_RETRY_TIME );
663//                              }
664//                              catch ( InterruptedException ex2) {
665//                                      LogWriter.log( "InterruptedException:" + ex2.getMessage() );
666//                              }
667//                      }
668//              }
669//              String errMsg = "コネクションを取り出すことが出来ませんでした。 "
670//                                              + HybsSystem.CR
671//                                              + "connID = [" + connID + "]" ;
672//              throw new HybsSystemException( errMsg,exTemp );
673        }
674
675        /**
676         * Transactionオブジェクトを外部から設定します。
677         *
678         * 通常は、ConnectionFactory を使用して、内部で Connection を作成しますが、
679         * 一連のトランザクション処理を実施するには、外部から Transactionオブジェクトを
680         * を与えて、そこから、Connection を取り出す必要があります。
681         *
682         * ここでは、内部の connection が存在しない場合に限り、セットを許可します。
683         *
684         * @og.rev 5.1.9.0 (2010/08/01) 新規追加
685         *
686         * @param       connID  接続先ID
687         * @param       tran    Transactionオブジェクト
688         */
689        public void setTransaction( final String connID , final Transaction tran ) {
690                if( transaction == null ) {
691                        transaction     = tran;
692                        this.connID = connID;
693                }
694                else {
695                        String errMsg = "トランザクションは、すでに設定済みです。"
696                                                        + HybsSystem.CR
697                                                        + "connID = [" + connID + "]" ;
698                        throw new HybsSystemException( errMsg );
699                }
700        }
701
702        /**
703         * connection オブジェクトから,ワーニングデータを取り出します。
704         *
705         * ワーニングデータは,SQLWarning クラスのオブジェクトに複数件貯えられます。
706         * query 実行後に,確認しておく必要があります。
707         *
708         * このメソッドは, execute からのみ,呼び出されます。
709         * それ以外からは呼出し出来ません。
710         *
711         * @param       connection Connection
712         *
713         * @return      ワーニング ErrorMessage
714         */
715        //      protected ErrorMessage getWarning( final Connection connection ) {
716        //              if( connection == null ) { return null; }
717        //
718        //              try {
719        //                      ErrorMessage em = new ErrorMessage();
720        //                      for( SQLWarning warning = connection.getWarnings();
721        //                                                      warning != null ;
722        //                                                      warning = warning.getNextWarning() ) {
723        //                              em.addMessage( 0,ErrorMessage.WARNING,warning.getMessage(),warning.getSQLState() );
724        //                      }
725        //                      return em;
726        //              }
727        //              catch (SQLException ex) {
728        //                      realClose();
729        //                      String errMsg = "ワーニングを取り出すことが出来ませんでした。";
730        //                      errMsg += System.getProperty( "line.separator" );
731        //                      errMsg += ex.getMessage() + ":" + ex.getSQLState();
732        //                      throw new HybsSystemException( errMsg,ex );             // 3.5.5.4 (2004/04/15) 引数の並び順変更
733        //              }
734        //      }
735
736        /**
737         * この接続が、PreparedStatement#getParameterMetaData() を使用するかどうかを判定します。
738         *
739         * ConnectionFactory#useParameterMetaData(String) の結果を返します。(postgreSQL対応)
740         *
741         * @og.rev 5.3.8.0 (2011/08/01) 新規追加
742         *
743         * @return      使用する場合:true / その他:false
744         * @see org.opengion.fukurou.db.ConnectionFactory#useParameterMetaData(String)
745         */
746        protected boolean useParameterMetaData() {
747                return ConnectionFactory.useParameterMetaData( connID );
748        }
749
750        //////////////////////////////////////////////////////////////////////////
751        //
752        //       Object クラスのオーバーライド部分
753        //
754        //////////////////////////////////////////////////////////////////////////
755
756        /**
757         * オブジェクトの識別子として,最後のクエリーを返します。
758         *
759         * @return      最後のクエリー
760         */
761        @Override
762        public String toString() {
763                return  "LastQuery  :[" + getStatement() + "] ";
764        }
765}