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 */
016 package org.opengion.hayabusa.db;
017
018 import java.sql.Connection;
019 import java.sql.ResultSet;
020 import java.sql.SQLException;
021
022 import org.opengion.fukurou.db.Transaction;
023 import org.opengion.fukurou.db.ConnectionFactory; // 5.3.8.0 (2011/08/01)
024 import org.opengion.fukurou.util.ErrorMessage;
025 import org.opengion.hayabusa.common.HybsSystem;
026 import org.opengion.hayabusa.common.HybsSystemException;
027 import org.opengion.hayabusa.resource.ResourceManager;
028
029 /**
030 * Query インターフェースを継承した Query の実è£?‚¯ラスですã?
031 * クエリークラスにスãƒ??トメントを与えて execute()することによりå†?ƒ¨に DBTableModel ã‚?
032 * 作æ?しますã?
033 * こã?クラスは、Abstract クラスのため、実è£??個ã?のサブクラスで行いますã?
034 * 唯ä¸?®Ÿè£?�™るå¿?¦�があるのは, execute() メソãƒ?ƒ‰ã�?�‘ですã?
035 *
036 * @og.group ?¤?¢検索
037 * @og.group ?¤?¢登録
038 *
039 * @version 4.0
040 * @author Kazuhiko Hasegawa
041 * @since JDK5.0,
042 */
043 public 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 }