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.fukurou.process; 017 018import org.opengion.fukurou.util.ApplicationInfo; 019 020import java.sql.Connection; 021import java.sql.DriverManager; 022import java.sql.SQLException; 023import java.sql.DatabaseMetaData; 024 025import java.net.InetAddress; 026import 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接続履歴取得用の実行プログラムID 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,操作,プログラムID 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}