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( "<b>【Connection Informationã€?/b>" ).append( CR );       // 5.6.7.3 (2013/08/23) 若干の修正
305    
306                    int rtnCnt = 0;
307                    synchronized( DEF_POOL ) {
308                            if( ! DEF_POOL.isEmpty() ) {
309                                    rtnCnt += DEF_POOL.size();
310                                    // 5.3.4.0 (2011/04/01) 詳細メãƒ?‚»ージ用引数を追åŠ?
311                                    if( isDetail ) {
312                                            strBuf.append( DEF_POOL.toString() );
313                                            strBuf.append( "<br /><hr />" );
314                                    }
315                                    else {
316                                            strBuf.append( DEF_POOL.dbidInfo() );
317                                    }
318                            }
319                    }
320    
321                    ConnectionPool[] pools = null;
322                    synchronized( map ) {
323                            if( !map.isEmpty() ) {
324                                    pools = map.values().toArray( new ConnectionPool[map.size()] ) ;
325                            }
326                    }
327    
328                    if( pools != null ) {
329                            for( int i=0; i<pools.length ; i++ ) {
330                                    ConnectionPool pool = pools[i];
331                                    if( pool != null && ! pool.isEmpty() ) {
332                                            rtnCnt += pool.size();
333                                            // 5.3.4.0 (2011/04/01) 詳細メãƒ?‚»ージ用引数を追åŠ?
334                                            if( isDetail ) {
335                                                    strBuf.append( pool.toString() );
336                                                    strBuf.append( "<br /><hr />" );
337                                            }
338                                            else {
339                                                    strBuf.append( pool.dbidInfo() );
340                                            }
341                                    }
342                            }
343                    }
344    
345                    strBuf.append( CR );
346    
347                    return strBuf.toString();
348            }
349    
350            /**
351             * こã?接続が、PreparedStatement#getParameterMetaData() を使用するかどã�?�‹を判定しますã?
352             *
353             * PreparedStatement に対して、String化された 数字などã‚?setObject( int,String ) するときã?
354             * ORACLE と SQLServer は、そのまま設定すれã?、è?動的に変換されますã?
355             * postgreSQL では、ParameterMetaData#getParameterType(int) で、カラãƒ?‚¿イプを取得しã€?
356             * setObject( int,String,int ) するå¿?¦�がありますã?
357             * そã?判定に、このメソãƒ?ƒ‰を使用しますã?
358             * こã?結果は、あくまで、各種ãƒ??タベã?ス毎ã?実地調査の結果をå?に、判定結果ã‚?
359             * 返すようにしてã�?�¾すã?
360             * ORACLE の場合ã?、使用しなã�?false)が返るように設定してã�?�¾すã?
361             * SQLServer では、ORACLEと同様に、false を返しますã?
362             *
363             * こã?メソãƒ?ƒ‰は、å?ã€??ApplicationInfo#useParameterMetaData(Connection) に有ったものã‚?
364             * EDbid から取得するよã�?�«修正したもã?ですã?
365             *
366             * @og.rev 5.3.8.0 (2011/08/01) 新規追åŠ?
367             *
368             * @param dbid 接続å?ID
369             *
370             * @return      [true:使用する/false:そã?他]
371             */
372            public static boolean useParameterMetaData( final String dbid ) {
373                    final String udbid ;
374                    if( dbid == null || dbid.length() == 0 ) {
375                            udbid = DBID ;
376                    }
377                    else {
378                            udbid = dbid.toUpperCase( Locale.JAPAN );       // 大æ–?­—化
379                    }
380    
381                    EDbid edbid = dbc.getDbid( udbid );
382    
383                    return edbid.useParamMetaData();
384            }
385    
386            /**
387             * 接続å?のDB名に対応したã?enum (DBName) を返しまã�?toUpperCase)ã€?
388             *
389             * @og.rev 5.1.4.0 (2010/03/01) getDBFullName の代わりに新規作æ?
390             * @og.rev 5.7.7.2 (2014/06/20) æœ??の取得時のエラー回避
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 );        // 5.7.7.2 (2014/06/20) æœ??の取得時のエラー回避
409                                            connection( dbid, null );       // ãƒ?ƒŸーで、コネクトするã?
410                                            pool = map.get( udbid );        // もうä¸?º¦、設定するã?
411                                    }
412                            }
413                            if( pool != null ) {
414                                    dbName = pool.getDBName();
415                            }
416                            else {
417                                    final String errMsg = "æŒ?®šã?DBIDキーに対応するデータベã?ス名を取得å?来ませんã€?
418                                            + "[Key =" + dbid + "]";
419                                    throw new RuntimeException( errMsg );
420                            }
421                    }
422    
423                    return dbName.toUpperCase( Locale.JAPAN );
424            }
425    }
426    
427    /**
428     * ConnectionPool は、AbstractObjectPool を継承した オブジェクトã?ールですã?
429     *
430     * コネクションオブジェクトをプã?ルすることにより、ConnectionFactory で
431     * 管ç�?�™ã‚?Map オブジェクトã?実æ?として、各ID毎ã? コネクションをキープしますã?
432     *
433     * @og.group ?¤?¢/Shell制御
434     *
435     * @version  4.0
436     * @author   Kazuhiko Hasegawa
437     * @since    JDK5.0,
438     */
439    class ConnectionPool extends AbstractObjectPool<Connection> {
440            private final transient EDbid edbid;
441    
442            // 4.0.0.0 (2007/10/17) シスãƒ?ƒ 依存ã?改行記号をセãƒ?ƒˆしますã?
443            private static final String CR = System.getProperty( "line.separator" );
444    
445            /**
446             *  DBID を指定して作æ?する コンストラクター
447             *  DBID をキーに?¤ HybsSystem.sys メソãƒ?ƒ‰のãƒ??タベã?ス変数を取得しますã?
448             *  取得するã?は?¤ DBID + _DB_URL?�_DB_USER?�_DB_PASSWD?�_DB_MINCOUNT?�_DB_MAXCOUNT
449             *  ですã?
450             *  DBID ã�?null の場合ã???DEFAULT" が使用されますã?
451             *
452             * @og.rev 3.5.4.3 (2004/01/05) キャãƒ?‚·ュの寿命を指å®?
453             * @og.rev 3.5.4.7 (2004/02/06) DBID のゼロストリングチェãƒ?‚¯追åŠ?
454             * @og.rev 4.0.0.0 (2007/10/10) キャãƒ?‚·ュされたã?初期ConnectionPool を使用
455             * @og.rev 4.0.0.0 (2007/10/25) DB設定情報のXML化に伴ã�?¤‰更
456             *
457             * @param   edbid 接続å?æƒ??オブジェクãƒ?
458             */
459            public ConnectionPool( final EDbid edbid ) {
460                    // 4.0.0.0 XML化に伴ã�?ƒ­ードå?を変更
461                    this.edbid      =       edbid;
462                    init( edbid.getMincount(),edbid.getMaxcount(),true,edbid.getPooltime() );
463            }
464    
465            /**
466             * オブジェクトã?ールから削除するときに呼ばれますã?
467             * こã?メソãƒ?ƒ‰でå�?‚ªブジェクトごとの終äº??ç�?‚’行いますã?
468             * 例えば?¤ãƒ??タベã?スコネクションであれば?¤close() 処ç�?�ªどですã?
469             *
470             * @og.rev 3.5.4.8 (2004/02/23) SQLException は無視しますã?
471             * @og.rev 3.5.6.0 (2004/06/18) synchronized を解除しますã?
472             *
473             * @param  obj 終äº??ç�?‚’行うオブジェクãƒ?
474             */
475            protected void objectFinal( final Connection obj ) {
476                    Closer.connClose( obj );
477            }
478    
479            /**
480             * コネクションオブジェクトを作æ?しますã?
481             * DriverManager.getConnection により作æ?されたConnection ã‚?Connection で
482             * ラãƒ?ƒ”ングしますã?
483             * Connectionオブジェクトã?,close()メソãƒ?ƒ‰で,自åˆ??身ã‚?ConnectionFactory の
484             * プã?ルに戻しますã?
485             *
486             * @og.rev 3.3.3.3 (2003/08/06) コネクションに対して、setTransactionIsolation をã?設定しておくã€?
487             * @og.rev 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
488             * @og.rev 3.5.6.0 (2004/06/18) synchronized を解除しますã?
489             * @og.rev 3.8.8.2 (2007/01/26) useAppInfo を設定しますã?
490             * @og.rev 4.0.0.0 (2007/10/30) 保持æƒ??オブジェクト化に伴ã�?¤‰更
491             * @og.rev 5.1.2.0 (2010/01/01) MySQL対å¿?明示çš?�«、TRANSACTION_READ_COMMITTED を指定するã?
492             * @og.rev 5.5.2.0 (2012/05/01) properties対å¿?
493             *
494             * @return  コネクションオブジェクãƒ?
495             */
496            protected Connection createInstance() {
497                    Connection conn = null;
498                    try {
499            //              DriverManager.setLogWriter( HybsSystem.out );                   // ドライバã?のログ
500    
501                            // 5.5.2.0 (2012/05/01) propertyの追åŠ??ç�?�¨、接続ã?propertiesåŒ?
502                            Properties prop = new Properties (edbid.getProps());
503                            prop.put ( "user", edbid.getUser() );
504                            prop.put ( "password", edbid.getPassword() );
505    
506                            conn = DriverManager.getConnection( edbid.getUrl(), prop );
507            //              conn.setReadOnly( true );
508                            conn.setReadOnly( edbid.isReadonly() );
509    
510                            conn.setAutoCommit( false );
511                            conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);  // 初期値
512            //              ((OracleConnection)conn).setDefaultExecuteBatch(1);  // 初期値
513            //              ((OracleConnection)conn).setDefaultRowPrefetch(20);  // 初期値
514    
515                            // 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
516                            // 4.0.0.0 (2007/10/26) 登録先をオブジェクト化
517                            if( edbid.getDbProductName() == null ) {
518                                    DatabaseMetaData meta = conn.getMetaData();
519                                    edbid.setMetaDataInfo( meta );
520                            }
521                            return conn ;
522                    }
523                    catch ( SQLException ex ) {
524                            String errMsg = "コネクトすることがå?来ませんã€? + CR
525                                                    + "DBID=[" + edbid.getDbidKey() + "]" + CR
526                                                    + ex.getMessage() + " , status=" + ex.getSQLState();
527                            Closer.connClose( conn );
528                            throw new RuntimeException( errMsg,ex );                // 3.5.5.4 (2004/04/15) 引数の並びé ?¤‰更
529                    }
530            }
531    
532            /**
533             * アクセスログ取得ã?為のDBMS_APPLICATION_INFOの使用可否を取得しまã�?初期値:true)ã€?
534             *
535             * ãƒ??タベã?スへのアクセスログ取得ã?為、エンジンで接続するコネクションにつã�?�¦
536             * DBMS_APPLICATION_INFO.SET_CLIENT_INFO と SET_MODULE を呼び出してã�?�¾すã?
537             * こã?処ç�??、ORACLEとの接続ã?み有効ですã?で、接続å?ãƒ??タベã?スã�?ORACLE 以外ã?
538             * false を返しますã?
539             * ORACLE の場合ã?、シスãƒ?ƒ リソースの USE_DB_APPLICATION_INFO 属æ?の設定å?ã‚?
540             * 返しますã?
541             * こã?設定å?の初期値は、true ですã?
542             *
543             * @og.rev 3.8.8.2 (2007/01/26) 新規追åŠ?
544             *
545             * @return  true:使用する/false:使用しなã�?
546             */
547            public boolean useApplicationInfo() { return edbid.isApplicationInfo(); }
548    
549            /**
550             * 接続å?のDB名を返しますã?
551             *
552             * @og.rev 4.3.7.0 (2009/06/01) 新規作æ?
553             *
554             * @return  接続å?のDBå�?
555             */
556            public String getDBName() {
557                    return edbid.getDbProductName();
558            }
559    
560            /**
561             * 接続å?のDBバã?ジョンを返しますã?
562             *
563             * @og.rev 4.3.7.0 (2009/06/01) 新規作æ?
564             *
565             * @return 接続å?のDBバã?ジョン
566             */
567            public String getDBVersion() {
568                    return edbid.getDbProductVersion();
569            }
570    
571            /**
572             * 接続å?の簡易なå†?ƒ¨æƒ??を返しますã?
573             *
574             * @og.rev 5.3.4.0 (2011/04/01) toString() の簡易版
575             *
576             * @return 接続å?の簡易なå†?ƒ¨æƒ??
577             */
578            public String dbidInfo() {
579                    return edbid.info();
580            }
581    
582            /**
583             * å†?ƒ¨状況を簡易的に表現したæ–?­—å?を返しますã?
584             * DBID?�URL?�USER?�ã?ールサイズ を返しますã?
585             *
586             * @og.rev 3.5.2.0 (2003/10/20) 接続情報に、データベã?ス名ã?ドライバ名æƒ??を追åŠ?�™るã?
587             * @og.rev 3.5.6.6 (2004/08/23) 同期化方法を統ä¸?�™る為、synchronized をつけますã?(別é€?要検è¨?
588             * @og.rev 4.0.0.0 (2007/10/29) EDbidのtoStringを呼ぶように変更
589             *
590             * @return   こã?オブジェクトã?ールのæ–?­—å?表現
591             */
592            @Override
593            public String toString() {
594                    StringBuilder buf = new StringBuilder();
595                    buf.append( edbid.toString() );
596                    buf.append( super.toString() );
597                    return buf.toString();
598            }
599    }