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.plugin.column; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.db.AbstractEditor; 020 import org.opengion.hayabusa.db.CellEditor; 021 import org.opengion.hayabusa.db.DBColumn; 022 import org.opengion.fukurou.util.StringFormat; 023 import org.opengion.fukurou.util.XHTMLTag; 024 import org.opengion.fukurou.util.ApplicationInfo; 025 import org.opengion.fukurou.db.DBUtil; 026 027 /** 028 * QUERY エ?ターは、編?ラメータで?された SQL??実行結果をテキストエリアに表示する 029 * クラスで、?のValue を?$1 として使用可能です? 030 * 又?$Cで自身のカラ?が使用可能です? 031 * 032 * カラ??表示に?な属?は, DBColumn オブジェク?より取り出します? 033 * こ?クラスは、DBColumn オブジェクト毎に?つ作?されます? 034 * 035 * @og.rev 4.0.0.0 (2006/04/01) 新規追? 036 * @og.group ??タ編? 037 * 038 * @version 4.0 039 * @author Kazuhiko Hasegawa 040 * @since JDK5.0, 041 */ 042 public class Editor_QUERY extends AbstractEditor { 043 //* こ?プログラ??VERSION??を設定します? {@value} */ 044 private static final String VERSION = "5.7.9.0 (2014/08/08)" ; 045 046 private final String query ; 047 private final String dbid ; 048 049 /** コネクションにアプリケーション??を追記するかど???*/ 050 public static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ; 051 052 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 053 private final ApplicationInfo appInfo; 054 private static final String SYSTEM_ID = HybsSystem.sys( "SYSTEM_ID" ) ; 055 056 /** 057 * ?ォルトコンストラクター? 058 * こ?コンストラクターで、基本オブジェクトを作?します? 059 * 060 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 061 */ 062 public Editor_QUERY() { 063 // 4.3.4.4 (2009/01/01) 064 query = null; 065 dbid = null; 066 appInfo = makeApplicationInfo( null ); 067 name = null; // 4.3.4.0 (2008/12/01) 068 } 069 070 /** 071 * コンストラクター? 072 * 073 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 074 * 075 * @param clm DBColumnオブジェク? 076 */ 077 private Editor_QUERY( final DBColumn clm ) { 078 super( clm ); 079 query = clm.getEditorParam(); 080 dbid = clm.getDbid(); 081 tagBuffer.add( XHTMLTag.inputAttri( attributes ) ); 082 appInfo = makeApplicationInfo( clm.getName() ); 083 name = clm.getName(); //4.3.4.0 (2008/12/01) 084 } 085 086 /** 087 * アクセスログ取得?為,ApplicationInfoオブジェクトを作?します? 088 * 089 * @og.rev 3.8.7.0 (2006/12/15) 新規作? 090 * 091 * @param name オブジェク? 092 * 093 * @return ApplicationInfoオブジェク? 094 */ 095 private ApplicationInfo makeApplicationInfo( final String name ) { 096 ApplicationInfo infoTemp = null; 097 098 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 099 if( USE_DB_APPLICATION_INFO ) { 100 infoTemp = new ApplicationInfo(); 101 // ユーザーID,IPアドレス,ホスト名 102 infoTemp.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME ); 103 // 画面ID,操?プログラ?D 104 infoTemp.setModuleInfo( "Editor_QUERY",null,name ); 105 } 106 107 return infoTemp ; 108 } 109 110 /** 111 * ?ブジェクトから???インスタンスを返します? 112 * 自??身をキャ?ュするのか?新たに作?するのか?、各サブクラスの実? 113 * まかされます? 114 * 115 * @param clm DBColumnオブジェク? 116 * 117 * @return CellEditorオブジェク? 118 */ 119 public CellEditor newInstance( final DBColumn clm ) { 120 return new Editor_QUERY( clm ); 121 } 122 123 /** 124 * ??タの編???を返します? 125 * 126 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 127 * @og.rev 4.3.4.0 (2008/12/01) $C対? 128 * @og.rev 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 129 * 130 * @param value 入力? 131 * 132 * @return ??タの編??? 133 */ 134 @Override 135 public String getValue( final String value ) { 136 // StringFormat format = new StringFormat( query,value ); 137 StringFormat format = new StringFormat( query,value, name ); // 4.3.4.0 (2008/12/01) 138 String str = format.format(); 139 140 // 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 141 // String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid ); 142 // return super.getValue( rtn[0][0] ); 143 144 String rtnVal = (value == null) ? "" : value ; // 本来、QUERYで変換すべきだが???値を設定する? 145 try { 146 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid ); 147 rtnVal = ( rtn == null || rtn[0] == null || rtn[0][0] == null ) ? "" : rtn[0][0]; 148 } 149 catch( RuntimeException ex ) { 150 String errMsg = "SQL??処?失敗しました? + HybsSystem.CR 151 + "query=" + query + " , inValue=" + value + " , name=" + name 152 + HybsSystem.CR 153 + ex.getMessage() ; 154 System.err.println( errMsg ); 155 } 156 157 return super.getValue( rtnVal ); 158 } 159 160 /** 161 * name属?を変えた???タ表示/編?のHTML??を作?します? 162 * ??ブル上? name に 行番号を付加して、名前_行番号 で登録するキーを作?? 163 * リクエスト情報を1つ毎?フィールドで処?きます? 164 * 165 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 166 * @og.rev 4.3.4.0 (2008/12/01) $C対? 167 * @og.rev 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 168 * 169 * @param row 行番号 170 * @param value 入力? 171 * 172 * @return ??タ表示/編?の?? 173 */ 174 @Override 175 public String getValue( final int row,final String value ) { 176 // StringFormat format = new StringFormat( query,value ); 177 StringFormat format = new StringFormat( query,value,name ); // 4.3.4.0 (2008/12/01) 178 String str = format.format(); 179 180 // 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 181 // String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid ); 182 // return super.getValue( row,rtn[0][0] ); 183 184 String rtnVal = (value == null) ? "" : value ; // 本来、QUERYで変換すべきだが???値を設定する? 185 try { 186 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid ); 187 rtnVal = ( rtn == null || rtn[0] == null || rtn[0][0] == null ) ? "" : rtn[0][0]; 188 } 189 catch( RuntimeException ex ) { 190 String errMsg = "SQL??処?失敗しました? + HybsSystem.CR 191 + "row=" + row + " , query=" + query + " , inValue=" + value + " , name=" + name 192 + HybsSystem.CR 193 + ex.getMessage() ; 194 System.err.println( errMsg ); 195 } 196 197 return super.getValue( row,rtnVal ); 198 } 199 }