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.process;
017    
018    import org.opengion.fukurou.util.ApplicationInfo;
019    
020    import java.sql.Connection;
021    import java.sql.DriverManager;
022    import java.sql.SQLException;
023    import java.sql.DatabaseMetaData;
024    
025    import java.net.InetAddress;
026    import java.net.UnknownHostException;
027    
028    /**
029     * ConnData は、Connection を管ç�?�™るã?独立したDB接続実è£?‚¯ラスですã?
030     *
031     *
032     * @version  4.0
033     * @author   Kazuhiko Hasegawa
034     * @since    JDK5.0,
035     * @deprecated 5.1.9.0 (2010/08/01) å»?­¢クラスですã?org.opengion.fukurou.db.ConnectionFactory 等をご使用くださいã€?
036     */
037    @Deprecated public final class ConnData {
038            /** 実行してã�?‚‹サーバã?の名称 */
039            private static final String HOST_NAME ;
040            /** 実行してã�?‚‹サーバã?のIPアドレス */
041            private static final String HOST_ADRS ;
042    
043            static {
044                    String dmnHost ;
045                    String dnmAdrs ;
046                    try {
047                            InetAddress address = InetAddress.getLocalHost();
048                            dmnHost = address.getHostName() ;
049                            dnmAdrs = address.getHostAddress() ;
050                    }
051                    catch( UnknownHostException ex ) {
052                            dmnHost = "Unknown";
053                            dnmAdrs = "Unknown";
054                    }
055                    HOST_NAME = dmnHost;
056                    HOST_ADRS = dnmAdrs;
057            }
058    
059            private final boolean useAppInfo ;
060            private final Connection connection ;
061            private final int uniq;
062            private final long createTime;
063            private final String info ;
064    
065            /**
066             * 【å»?­¢】引数を指定してのコンストラクター
067             *
068             * @og.rev 5.1.1.0 (2009/12/01) MySQL対å¿?明示çš?�«、TRANSACTION_READ_COMMITTED を指定するã?
069             *
070             * @param       url             接続å?URL
071             * @param       user    接続ユーザー
072             * @param       passwd  パスワーãƒ?
073             * @param       uniq    å†?ƒ¨çš?�ªユニã?クコーãƒ?
074             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
075             */
076            @Deprecated public ConnData( final String url,final String user, final String passwd,final int uniq ) {
077                    createTime = System.currentTimeMillis();
078                    this.uniq = uniq ;
079    
080                    try {
081                            connection = DriverManager.getConnection( url, user, passwd );
082                            connection.setAutoCommit( false );
083                            connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);  // 5.1.1.0 (2009/12/01)
084    
085                            DatabaseMetaData meta = connection.getMetaData();
086                            String productName  = meta.getDatabaseProductName();
087                            useAppInfo = "ORACLE".equalsIgnoreCase( productName ) ;
088                    }
089                    catch (SQLException ex) {
090                            String errMsg = "Connection の作æ?に失敗しましたã€?" + url + "],[" + user + "]";
091                            throw new RuntimeException( errMsg,ex );
092                    }
093    
094                    info = url + "," + user + " (" + createTime + ")" ;
095            }
096    
097            /**
098             * 【å»?­¢】管ç�?�—てã�?‚‹コネクションを返しますã?
099             *
100             * @return      管ç�?�—てã�?‚‹コネクション
101             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
102             */
103            @Deprecated public Connection getConnection() { return connection; }
104    
105            /**
106             * 【å»?­¢】管ç�?�—てã�?‚‹接続å?のユニã?クキーを返しますã?
107             *
108             * @return      接続å?のユニã?クキー
109             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
110             */
111            @Deprecated public int getUniq() { return uniq; }
112    
113            /**
114             * 【å»?­¢】管ç�?�—てã�?‚‹接続å?の作æ?時刻を返しますã?
115             *
116             * @return      接続å?の作æ?時刻
117             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
118             */
119            @Deprecated public long getCreateTime() { return createTime; }
120    
121            /**
122             * 【å»?­¢】データベã?ス接続にå†?ƒ¨æƒ??を設定しますã?
123             * 処ç�??、ApplicationInfoオブジェクトã?適用ですã?
124             *
125             * @param       user    DB接続履歴取得用の実行ユーザー
126             * @param       pgid    DB接続履歴取得用の実行ã?ログラãƒ?D
127             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
128             */
129            @Deprecated public void makeApplicationInfo( final String user,final String pgid ) {
130                    if( useAppInfo ) {
131                            ApplicationInfo appInfo = new ApplicationInfo();
132                            // JavaVM 起動時のユーザーID,IPアドレス,ホスト名をセãƒ?ƒˆしますã?
133                            appInfo.setClientInfo( user,HOST_ADRS,HOST_NAME );
134    
135                            // 画面ID,操ä½?プログラãƒ?D
136                            appInfo.setModuleInfo( pgid,null,"ConnData" );
137    
138                            appInfo.callAppInfo( connection );
139                    }
140            }
141    
142            /**
143             * 【å»?­¢】このオブジェクトã?å†?ƒ¨æ–?­—å?表現を返しますã?
144             *
145             * 接続URL + "," + 接続ユーザー + " (" + 作æ?日ä»?+ ")" ですã?
146             *
147             * @return å†?ƒ¨æ–?­—å?表現
148             * @deprecated  5.1.9.0 (2010/08/01) å»?­¢クラスでã�?
149             */
150            @Deprecated public String toString() {
151                    return info ;
152            }
153    }