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 }