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.fukurou.db;
017
018 import org.opengion.fukurou.util.AbstractObjectPool;
019 import org.opengion.fukurou.util.ApplicationInfo;
020 import org.opengion.fukurou.util.Closer;
021
022 import java.util.Map;
023 import java.util.HashMap;
024 import java.util.Locale;
025 import java.util.Properties;
026 import java.sql.Connection;
027 import java.sql.SQLException;
028 import java.sql.DriverManager;
029 import java.sql.DatabaseMetaData;
030
031 /**
032 * ãƒ??タベã?スのコネクションオブジェクトを取得する為に使用する?Œファクトリクラスですã?
033 *
034 * Connection.connection() メソãƒ?ƒ‰で?ŒConnectionオブジェクトを取得しますã?
035 * Connection#close() メソãƒ?ƒ‰で?Œå?部çš?�« ConnectionFactory にオブジェクトを戻ã�?
036 * 事によって,Connectionオブジェクトã?プã?リングを行なってã�?�¾すã?
037 *
038 * コネクションオブジェクトã??Œã?ールから貸しå?しますã?
039 * つまり,貸しå?し中には,プã?ルには?Œオブジェクトã?残ってã�?�¾せんã€?
040 * そã?状態で,コネクションオブジェクトをclose()しなã�??合ã?,オブジェクトが破æ£?�•れて,
041 * 貸しå?し中カウントと実際のオブジェクト数が食い違い,リソースが不足しますã?
042 * å¿?�š,作æ?したオブジェクトã?,close()メソãƒ?ƒ‰を呼び出して,プã?ルに返して下さã�??
043 *
044 * シスãƒ?ƒ リソースの USE_DB_APPLICATION_INFO=true の場合ã?コネクションにアプリケーション
045 * æƒ??を追記するためã?ApplicationInfoオブジェクトを使用しますã?
046 * こã?オブジェクトã?、jsp/common/session-init.jsp にてユーザーæƒ??とアプリケーション
047 * æƒ??を画面アクセスごとに設定しますã?
048 *
049 * @og.group ?¤?¢/Shell制御
050 * @og.rev 4.0.0.0 (2007/10/16) パッケージ移å‹?hayabusa/db â‡?fukurou/db)
051 *
052 * @version 4.0
053 * @author Kazuhiko Hasegawa
054 * @since JDK5.0,
055 */
056 public final class ConnectionFactory {
057 private static final Map<String,ConnectionPool> map = new HashMap<String,ConnectionPool>();
058
059 // 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
060 // 4.0.0.0 (2007/10/29) 初期値をここでセãƒ?ƒˆする
061 private static String DBID = "DEFAULT";
062 private static ConnectionPool DEF_POOL ;
063
064 // 4.0.0.0 (2007/10/17) シスãƒ?ƒ 依存ã?改行記号をセãƒ?ƒˆしますã?
065 private static final String CR = System.getProperty( "line.separator" );
066
067 // 4.0.0.0 (2007/10/25) hayabusa依存をåˆ?‚‹ために追åŠ?�—まã�?
068 private static final int BUFFER_MIDDLE = 200;
069
070 private static DatabaseConfig dbc;
071
072 /**
073 * ãƒ?ƒ•ォルトコンストラクターをprivateにしてã€?
074 * オブジェクトã?生æ?をさせなã�?‚ˆã�?�«するã€?
075 *
076 */
077 private ConnectionFactory() {
078 }
079
080 /**
081 * 初期化メソãƒ?ƒ‰ですã?
082 * <pre>
083 * ??第二引数にXMLファイルをクラスローãƒ?Ÿº底からã?相対パスでæŒ?®šしたå?合ã?
084 * ã€??そã?XMLを利用してDBConfigオブジェクトを作æ?しますã?例:ConnectionFactory.init( CONTEXT_NAME, "../DBConfig.xml")
085 * ã€??nullの場合ã?WEB-INF/DBConfig.xmlを利用しますã?例:ConnectionFactory.init( CONTEXT_NAME, null)
086 * ??キャãƒ?‚·ュ初期ConnectionPoolのキーを設定してキャãƒ?‚·ュプã?ルを作りますã?
087 * ã€??こã?値がnullの場合ã?"DEFAULT"が設定されますã?
088 * </pre>
089 *
090 * <strong>こã?クラスを利用する場合ã?å¿?�šæœ??にこã?メソãƒ?ƒ‰を実行するå¿?¦�がありますã?</strong>
091 * キャãƒ?‚·ュとDBConfigオブジェクトã?同期化ã?されてã�?�ªã�??で初期化以外での利用は避けて下さã�??
092 *
093 * @og.rev 4.0.0.0 (2007/11/05) 新規作æ?
094 *
095 * @param defPoolKey 初期DBIDå�?nullの場合ã?ã€?DEFAULT")
096 * @param xmlFileName DBConfig.xmlファイルのファイルå�?nullの場合ã?、WEB-INF/DBConfig.xml)
097 */
098 public static void init( final String defPoolKey, final String xmlFileName ) {
099 // DBConfigオブジェクトã?作æ?
100 if( xmlFileName == null || xmlFileName.length() == 0 ) {
101 dbc = new DatabaseConfig();
102 }
103 else {
104 dbc = new DatabaseConfig( xmlFileName );
105 }
106
107 if( defPoolKey == null || defPoolKey.length() == 0 || dbc.getDbid( defPoolKey ) == null ) {
108 DBID = "DEFAULT";
109 }
110 else {
111 DBID = defPoolKey;
112 }
113 EDbid edbid = dbc.getDbid( DBID );
114 if( edbid == null ) {
115 final String errMsg = "初期化時に、指定ã?DBIDキーが存在しませんã€?
116 + "[Key ="
117 + DBID
118 + "]";
119 throw new RuntimeException( errMsg );
120 }
121
122 DEF_POOL = new ConnectionPool( edbid );
123 }
124
125 /**
126 * コネクションオブジェクトを取得しますã?
127 * é�?�„初期化を行なã�?º‹により,実際にå¿?¦�となるまでコネクションオブジェクトã?
128 * 作æ?しませんã€?
129 * æœ?¤§プã?ル数に達して,なおかつ,すべてのConnectionが貸しå?し中の場å�?
130 *
131 * @og.rev 2.1.1.3 (2002/11/22) コネクションID ã�?null の場合に DEFAULT からæ‰?¾—するよã�?�«変更ã€?
132 * @og.rev 3.1.0.0 (2003/03/20) Hashtable を使用してã�?‚‹ç®?‰€でã€?�ž同期でも構わなã�?®?‰€をã?HashMap に置換えã€?
133 * @og.rev 3.5.6.2 (2004/07/05) æ–?—å?の連結にStringBuilderを使用しますã?
134 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
135 * @og.rev 3.8.8.2 (2007/01/26) USE_DB_APPLICATION_INFO â‡?pool.useApplicationInfo() 変更
136 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
137 * @og.rev 4.1.0.1 (2008/01/21) 登録時に、大æ–?—に変換するã€?
138 *
139 * @param dbid 接続å?ID
140 * @param appInfo アプリæƒ??オブジェクãƒ?
141 *
142 * @return コネクションオブジェクãƒ?
143 */
144 public static Connection connection( final String dbid , final ApplicationInfo appInfo ) {
145 ConnectionPool pool ;
146 if( dbid == null || dbid.length() == 0 || DBID.equalsIgnoreCase( dbid ) ) {
147 pool = DEF_POOL ;
148 }
149 else {
150 String udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
151 synchronized( map ) {
152 pool = map.get( udbid );
153 // 接続IDがã?map に存在しなã�??å�?
154 if( pool == null ) {
155 EDbid edbid = dbc.getDbid( udbid );
156 if( edbid == null ) {
157 final String errMsg = "æŒ?®šã?DBIDキーが存在しませんã€?
158 + "[Key ="
159 + udbid
160 + "]";
161 throw new RuntimeException( errMsg );
162 }
163 pool = new ConnectionPool( edbid );
164 map.put( udbid,pool );
165 }
166 }
167 }
168
169 Connection conn = pool.newInstance();
170
171 // 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを使用
172 // 3.8.8.2 (2007/01/26) ORACLE 以外ã?、使用しませんã€?
173 // 4.0.0.0 (2007/11/29) 入れ子if の統å�?
174 if( appInfo != null && pool.useApplicationInfo() ) {
175 appInfo.callAppInfo( conn );
176 }
177 return conn;
178 }
179
180 /**
181 * コネクションオブジェクトをプã?ルに戻しますã?
182 * Connectionオブジェクトã?,close()メソãƒ?ƒ‰で,自åˆ??身ã‚?ConnectionFactory の
183 * プã?ルに戻しますã?
184 * それ以外ã? コネクションオブジェクトをプã?ルに戻すå?合ã?,こã?メソãƒ?ƒ‰を使用しますã?
185 *
186 * @og.rev 2.1.1.3 (2002/11/22) コネクションID ã�?null の場合に DEFAULT からæ‰?¾—するよã�?�«変更ã€?
187 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
188 * @og.rev 4.1.0.1 (2008/01/21) 登録時に、大æ–?—に変換するã€?
189 *
190 * @param conn コネクションオブジェクãƒ?
191 * @param dbid 接続å?ID
192 */
193 public static void close( final Connection conn,final String dbid ) {
194 if( conn != null ) {
195 if( dbid == null || dbid.length() == 0 || DBID.equalsIgnoreCase( dbid ) ) {
196 DEF_POOL.release( conn ) ;
197 }
198 else {
199 String udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
200 synchronized( map ) {
201 ConnectionPool pool = map.get( udbid );
202 if( pool != null ) {
203 pool.release( conn );
204 }
205 }
206 }
207 }
208 }
209
210 /**
211 * コネクションオブジェクトを物ç�?š„に削除(クローズ)戻しますã?
212 * これは、コネクション等がエラーを起こしたå?合に、ã?ールに戻すã?ではなくã?
213 * 接続を閉じるå?合に、使用されますã?
214 *
215 * @og.rev 2.1.1.3 (2002/11/22) コネクションID ã�?null の場合に DEFAULT からæ‰?¾—するよã�?�«変更ã€?
216 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
217 * @og.rev 4.1.0.1 (2008/01/21) 登録時に、大æ–?—に変換するã€?
218 *
219 * @param conn コネクションオブジェクãƒ?
220 * @param dbid 接続å?ID
221 */
222 public static void remove( final Connection conn,final String dbid ) {
223 if( conn != null ) {
224 if( dbid == null || dbid.length() == 0 || DBID.equalsIgnoreCase( dbid ) ) {
225 DEF_POOL.remove( conn ) ;
226 }
227 else {
228 String udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
229 synchronized( map ) {
230 ConnectionPool pool = map.get( udbid );
231 if( pool != null ) {
232 pool.remove( conn );
233 // map.put( udbid,pool );
234 }
235 }
236 }
237 }
238 }
239
240 /**
241 * コネクションオブジェクトを実際にすべてクローズしますã?
242 * コネクションプã?ルの再編成や?Œ管ç�??による強制クローズに使用しますã?
243 *
244 * クローズに失æ•?コネクションが貸しå?し中)の場合ã?,å†?ƒ¨çš?�«
245 * DB_CLOSE_RETRY_TIME ã�?�‘å¾?©Ÿして, DB_CLOSE_RETRY_COUNT 回数ã�?�‘,試行しますã?
246 * それでもクローズできなã�??合ã?, RuntimeException ã‚?throw しますã?
247 *
248 * @og.rev 4.0.0.0 (2005/01/31) ロジãƒ?‚¯見直しã? pool.clear() で、基本çš?�«はすべて削除されますã?
249 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
250 */
251 public static void realClose() {
252 synchronized( DEF_POOL ) {
253 if( ! DEF_POOL.isEmpty() ) {
254 DEF_POOL.clear();
255 }
256 }
257
258 final ConnectionPool[] pools ;
259 synchronized( map ) {
260 if( map.isEmpty() ) { return; }
261
262 pools = map.values().toArray( new ConnectionPool[map.size()] ) ;
263 map.clear();
264 }
265
266 ConnectionPool pool ;
267 for( int i=0; i<pools.length ; i++ ) {
268 pool = pools[i];
269 if( pool != null && ! pool.isEmpty() ) {
270 pool.clear();
271 }
272 }
273 }
274
275 /**
276 * ConnectionFactory の現在の状æ³?詳細メãƒ?‚»ージ)を返しますã?
277 * これは?Œコネクションプã?ルの数(æœ?¤§値?Œ作æ?済み数など)を確認する為のもã?ですã?
278 *
279 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
280 *
281 * @return 現在の状態表示
282 */
283 public static String information() {
284 return information( true );
285 }
286
287 /**
288 * ConnectionFactory の現在の状況を返しますã?
289 * これは?Œコネクションプã?ルの数(æœ?¤§値?Œ作æ?済み数など)を確認する為のもã?ですã?
290 * 引数により詳細メãƒ?‚»ージかどã�?�‹を指定できますã?
291 *
292 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
293 * @og.rev 5.3.4.0 (2011/04/01) 詳細メãƒ?‚»ージ用引数を追åŠ?
294 * @og.rev 5.6.7.3 (2013/08/23) 若干の修正
295 *
296 * @param isDetail 詳細メãƒ?‚»ージかどã�?�‹ [true:詳細メãƒ?‚»ージ/false:簡易メãƒ?‚»ージ]
297 *
298 * @return 現在の状態表示
299 */
300 public static String information(final boolean isDetail ) {
301 // 4.0.0.0 (2007/10/25) hybsとの依存関係を弱めるためã€?
302 final StringBuilder strBuf = new StringBuilder( BUFFER_MIDDLE );
303
304 // strBuf.append( "Connection Information :" ).append( CR );
305 strBuf.append( "<b>【Connection Informationã€?/b>" ).append( CR ); // 5.6.7.3 (2013/08/23) 若干の修正
306
307 int rtnCnt = 0;
308 synchronized( DEF_POOL ) {
309 if( ! DEF_POOL.isEmpty() ) {
310 rtnCnt += DEF_POOL.size();
311 // 5.3.4.0 (2011/04/01) 詳細メãƒ?‚»ージ用引数を追åŠ?
312 if( isDetail ) {
313 strBuf.append( DEF_POOL.toString() );
314 strBuf.append( "<br /><hr />" );
315 }
316 else {
317 strBuf.append( DEF_POOL.dbidInfo() );
318 }
319 }
320 }
321
322 ConnectionPool[] pools = null;
323 synchronized( map ) {
324 if( !map.isEmpty() ) {
325 pools = map.values().toArray( new ConnectionPool[map.size()] ) ;
326 }
327 }
328
329 if( pools != null ) {
330 for( int i=0; i<pools.length ; i++ ) {
331 ConnectionPool pool = pools[i];
332 if( pool != null && ! pool.isEmpty() ) {
333 rtnCnt += pool.size();
334 // 5.3.4.0 (2011/04/01) 詳細メãƒ?‚»ージ用引数を追åŠ?
335 if( isDetail ) {
336 strBuf.append( pool.toString() );
337 strBuf.append( "<br /><hr />" );
338 }
339 else {
340 strBuf.append( pool.dbidInfo() );
341 }
342 }
343 }
344 }
345
346 strBuf.append( CR );
347
348 return strBuf.toString();
349 }
350
351 /**
352 * こã?接続が、PreparedStatement#getParameterMetaData() を使用するかどã�?�‹を判定しますã?
353 *
354 * PreparedStatement に対して、String化された 数字などã‚?setObject( int,String ) するときã?
355 * ORACLE と SQLServer は、そのまま設定すれã?、è?動的に変換されますã?
356 * postgreSQL では、ParameterMetaData#getParameterType(int) で、カラãƒ?‚¿イプを取得しã€?
357 * setObject( int,String,int ) するå¿?¦�がありますã?
358 * そã?判定に、このメソãƒ?ƒ‰を使用しますã?
359 * こã?結果は、あくまで、各種ãƒ??タベã?ス毎ã?実地調査の結果をå?に、判定結果ã‚?
360 * 返すようにしてã�?�¾すã?
361 * ORACLE の場合ã?、使用しなã�?false)が返るように設定してã�?�¾すã?
362 * SQLServer では、ORACLEと同様に、false を返しますã?
363 *
364 * こã?メソãƒ?ƒ‰は、å?ã€??ApplicationInfo#useParameterMetaData(Connection) に有ったものã‚?
365 * EDbid から取得するよã�?�«修正したもã?ですã?
366 *
367 * @og.rev 5.3.8.0 (2011/08/01) 新規追åŠ?
368 *
369 * @param dbid 接続å?ID
370 *
371 * @return [true:使用する/false:そã?他]
372 */
373 public static boolean useParameterMetaData( final String dbid ) {
374 final String udbid ;
375 if( dbid == null || dbid.length() == 0 ) {
376 udbid = DBID ;
377 }
378 else {
379 udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
380 }
381
382 EDbid edbid = dbc.getDbid( udbid );
383
384 return edbid.useParamMetaData();
385 }
386
387 /**
388 * 接続å?のDB名に対応したã?enum (DBName) を返しまã�?toUpperCase)ã€?
389 *
390 * @og.rev 5.1.4.0 (2010/03/01) getDBFullName の代わりに新規作æ?
391 *
392 * @param dbid 接続å?ID
393 *
394 * @return 接続å?のDBå�?
395 */
396 public static String getDBName( final String dbid ) {
397 final String dbName;
398
399 if( dbid == null || dbid.length() == 0 || DBID.equalsIgnoreCase( dbid ) ) {
400 dbName = DEF_POOL.getDBName();
401 }
402 else {
403 String udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
404 ConnectionPool pool = null;
405 synchronized( map ) {
406 pool = map.get( udbid );
407 if( pool == null ) {
408 close( connection( dbid, null ), dbid );
409 }
410 }
411 if( pool != null ) {
412 dbName = pool.getDBName();
413 }
414 else {
415 final String errMsg = "æŒ?®šã?DBIDキーに対応するデータベã?ス名を取得å?来ませんã€?
416 + "[Key =" + dbid + "]";
417 throw new RuntimeException( errMsg );
418 }
419 }
420
421 return dbName.toUpperCase( Locale.JAPAN );
422 }
423
424 /**
425 * 接続å?のDB名を返しますã?
426 *
427 * @og.rev 4.3.7.0 (2009/06/01) 新規作æ?
428 * @og.rev 5.1.4.0 (2010/03/01) å»?¢
429 *
430 * @param dbid 接続å?ID
431 *
432 * @return 接続å?のDBå�?バã?ジョン
433 */
434 // public static String getDBFullName( final String dbid ) {
435 // String dbName = null;
436 //
437 // if( dbid == null || dbid.length() == 0 || DBID.equalsIgnoreCase( dbid ) ) {
438 // dbName = DEF_POOL.getDBName() + " " + DEF_POOL.getDBVersion();
439 // }
440 // else {
441 // String udbid = dbid.toUpperCase( Locale.JAPAN ); // 大æ–?—化
442 // ConnectionPool pool = null;
443 // synchronized( map ) {
444 // pool = map.get( udbid );
445 // if( pool == null ) {
446 // close( connection( dbid, null ), dbid );
447 // }
448 // }
449 // if( pool != null ) {
450 // dbName = pool.getDBName() + " " + pool.getDBVersion();
451 // }
452 // }
453 // return dbName;
454 // }
455 }
456
457 /**
458 * ConnectionPool は、AbstractObjectPool を継承した オブジェクトã?ールですã?
459 *
460 * コネクションオブジェクトをプã?ルすることにより、ConnectionFactory で
461 * 管ç�?�™ã‚?Map オブジェクトã?実æ?として、各ID毎ã? コネクションをキープしますã?
462 *
463 * @og.group ?¤?¢/Shell制御
464 *
465 * @version 4.0
466 * @author Kazuhiko Hasegawa
467 * @since JDK5.0,
468 */
469 class ConnectionPool extends AbstractObjectPool<Connection> {
470 private final transient EDbid edbid;
471
472 // 4.0.0.0 (2007/10/17) シスãƒ?ƒ 依存ã?改行記号をセãƒ?ƒˆしますã?
473 private static final String CR = System.getProperty( "line.separator" );
474
475 /**
476 * DBID を指定して作æ?する コンストラクター
477 * DBID をキーに?¤ HybsSystem.sys メソãƒ?ƒ‰のãƒ??タベã?ス変数を取得しますã?
478 * 取得するã?は?¤ DBID + _DB_URL?�_DB_USER?�_DB_PASSWD?�_DB_MINCOUNT?�_DB_MAXCOUNT
479 * ですã?
480 * DBID ã�?null の場合ã???DEFAULT" が使用されますã?
481 *
482 * @og.rev 3.5.4.3 (2004/01/05) キャãƒ?‚·ュの寿命を指å®?
483 * @og.rev 3.5.4.7 (2004/02/06) DBID のゼロストリングチェãƒ?‚¯追åŠ?
484 * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
485 * @og.rev 4.0.0.0 (2007/10/25) DB設定情報のXML化に伴ã�?¤‰更
486 *
487 * @param edbid 接続å?æƒ??オブジェクãƒ?
488 */
489 public ConnectionPool( final EDbid edbid ) {
490 // 4.0.0.0 XML化に伴ã�?ƒードå?を変更
491 this.edbid = edbid;
492 init( edbid.getMincount(),edbid.getMaxcount(),true,edbid.getPooltime() );
493 }
494
495 /**
496 * オブジェクトã?ールから削除するときに呼ばれますã?
497 * こã?メソãƒ?ƒ‰でå�?‚ªブジェクトごとの終äº??ç�?‚’行いますã?
498 * 例えば?¤ãƒ??タベã?スコネクションであれば?¤close() 処ç�?�ªどですã?
499 *
500 * @og.rev 3.5.4.8 (2004/02/23) SQLException は無視しますã?
501 * @og.rev 3.5.6.0 (2004/06/18) synchronized を解除しますã?
502 *
503 * @param obj 終äº??ç�?‚’行うオブジェクãƒ?
504 */
505 protected void objectFinal( final Connection obj ) {
506 Closer.connClose( obj );
507 }
508
509 /**
510 * コネクションオブジェクトを作æ?しますã?
511 * DriverManager.getConnection により作æ?されたConnection ã‚?Connection で
512 * ラãƒ?ƒ”ングしますã?
513 * Connectionオブジェクトã?,close()メソãƒ?ƒ‰で,自åˆ??身ã‚?ConnectionFactory の
514 * プã?ルに戻しますã?
515 *
516 * @og.rev 3.3.3.3 (2003/08/06) コネクションに対して、setTransactionIsolation をã?設定しておくã€?
517 * @og.rev 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
518 * @og.rev 3.5.6.0 (2004/06/18) synchronized を解除しますã?
519 * @og.rev 3.8.8.2 (2007/01/26) useAppInfo を設定しますã?
520 * @og.rev 4.0.0.0 (2007/10/30) 保持æƒ??オブジェクト化に伴ã�?¤‰更
521 * @og.rev 5.1.2.0 (2010/01/01) MySQL対å¿?明示çš?�«、TRANSACTION_READ_COMMITTED を指定するã?
522 * @og.rev 5.5.2.0 (2012/05/01) properties対å¿?
523 *
524 * @return コネクションオブジェクãƒ?
525 */
526 protected Connection createInstance() {
527 Connection conn = null;
528 try {
529 // DriverManager.setLogWriter( HybsSystem.out ); // ドライバã?のログ
530
531 // 5.5.2.0 (2012/05/01) propertyの追åŠ??ç�?�¨、接続ã?propertiesåŒ?
532 Properties prop = new Properties (edbid.getProps());
533 prop.put ( "user", edbid.getUser() );
534 prop.put ( "password", edbid.getPassword() );
535
536 // conn = DriverManager.getConnection( edbid.getUrl(), edbid.getUser(), edbid.getPassword() );
537 conn = DriverManager.getConnection( edbid.getUrl(), prop );
538 // conn.setReadOnly( true );
539 conn.setReadOnly( edbid.isReadonly() );
540
541 conn.setAutoCommit( false );
542 conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); // 初期値
543 // ((OracleConnection)conn).setDefaultExecuteBatch(1); // 初期値
544 // ((OracleConnection)conn).setDefaultRowPrefetch(20); // 初期値
545
546 // 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
547 // 4.0.0.0 (2007/10/26) 登録先をオブジェクト化
548 if( edbid.getDbProductName() == null ) {
549 DatabaseMetaData meta = conn.getMetaData();
550 edbid.setMetaDataInfo( meta );
551 }
552 return conn ;
553 }
554 catch ( SQLException ex ) {
555 String errMsg = "コネクトすることがå?来ませんã€? + CR
556 + "DBID=[" + edbid.getDbidKey() + "]" + CR
557 + ex.getMessage() + " , status=" + ex.getSQLState();
558 Closer.connClose( conn );
559 throw new RuntimeException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数の並びé ?¤‰更
560 }
561 }
562
563 /**
564 * アクセスログ取得ã?為のDBMS_APPLICATION_INFOの使用可否を取得しまã�?初期値:true)ã€?
565 *
566 * ãƒ??タベã?スへのアクセスログ取得ã?為、エンジンで接続するコネクションにつã�?�¦
567 * DBMS_APPLICATION_INFO.SET_CLIENT_INFO と SET_MODULE を呼び出してã�?�¾すã?
568 * こã?処ç�??、ORACLEとの接続ã?み有効ですã?で、接続å?ãƒ??タベã?スã�?ORACLE 以外ã?
569 * false を返しますã?
570 * ORACLE の場合ã?、シスãƒ?ƒ リソースの USE_DB_APPLICATION_INFO 属æ?の設定å?ã‚?
571 * 返しますã?
572 * こã?設定å?の初期値は、true ですã?
573 *
574 * @og.rev 3.8.8.2 (2007/01/26) 新規追åŠ?
575 *
576 * @return true:使用する/false:使用しなã�?
577 */
578 public boolean useApplicationInfo() { return edbid.isApplicationInfo(); }
579
580 /**
581 * 接続å?のDB名を返しますã?
582 *
583 * @og.rev 4.3.7.0 (2009/06/01) 新規作æ?
584 *
585 * @return 接続å?のDBå�?
586 */
587 public String getDBName() {
588 return edbid.getDbProductName();
589 }
590
591 /**
592 * 接続å?のDBバã?ジョンを返しますã?
593 *
594 * @og.rev 4.3.7.0 (2009/06/01) 新規作æ?
595 *
596 * @return 接続å?のDBバã?ジョン
597 */
598 public String getDBVersion() {
599 return edbid.getDbProductVersion();
600 }
601
602 /**
603 * 接続å?の簡易なå†?ƒ¨æƒ??を返しますã?
604 *
605 * @og.rev 5.3.4.0 (2011/04/01) toString() の簡易版
606 *
607 * @return 接続å?の簡易なå†?ƒ¨æƒ??
608 */
609 public String dbidInfo() {
610 return edbid.info();
611 }
612
613 /**
614 * å†?ƒ¨状況を簡易的に表現したæ–?—å?を返しますã?
615 * DBID?�URL?�USER?�ã?ールサイズ を返しますã?
616 *
617 * @og.rev 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
618 * @og.rev 3.5.6.6 (2004/08/23) 同期化方法を統ä¸?�™る為、synchronized をつけますã?(別é€?要検è¨?
619 * @og.rev 4.0.0.0 (2007/10/29) EDbidのtoStringを呼ぶように変更
620 *
621 * @return こã?オブジェクトã?ールのæ–?—å?表現
622 */
623 public String toString() {
624 StringBuilder buf = new StringBuilder();
625 buf.append( edbid.toString() );
626 buf.append( super.toString() );
627 return buf.toString();
628 }
629 }