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.hayabusa.taglib; 017 018import static org.opengion.fukurou.util.StringUtil.nval; 019 020import java.io.IOException; 021import java.io.ObjectInputStream; 022import java.io.ObjectOutputStream; 023import java.util.Locale; 024 025import org.opengion.fukurou.db.DBUtil; 026import org.opengion.fukurou.db.Transaction; 027import org.opengion.fukurou.db.TransactionReal; 028import org.opengion.fukurou.util.ErrorMessage; 029import org.opengion.fukurou.util.StringUtil; 030import org.opengion.hayabusa.common.HybsSystem; 031import org.opengion.hayabusa.common.HybsSystemException; 032import org.opengion.hayabusa.db.DBColumn; 033import org.opengion.hayabusa.db.DBEditConfig; 034import org.opengion.hayabusa.db.DBTableModel; 035import org.opengion.hayabusa.db.Query; 036import org.opengion.hayabusa.db.QueryFactory; 037import org.opengion.hayabusa.resource.GUIInfo; 038 039/** 040 * データベースの検索を行うタグです。 041 * 042 * このタグの内容に、SQL文を記述します。 whereタグ、 andタグ を使うと引数に応じて 043 * 実行されるSQL文が異なります(使用例参照)。 044 * また、PL/SQLのSPで検索を行うときもこのタグを使います。 045 * SystemData の USE_SQL_INJECTION_CHECK が true か、quotCheck 属性が true の場合は、 046 * SQLインジェクション対策用のクォーティションチェックを行います。リクエスト引数に 047 * クォーティション(')が含まれると、エラーになります。 048 * 同様にUSE_XSS_CHECKがtrueか、xssCheck属性がtrueの場合は、 049 * クロスサイトススクリプティング(XSS)対策のためless/greater than signのチェックを行います。 050 * 051 * ※ このタグは、Transaction タグの対象です。 052 * 053 * @og.formSample 054 * ●形式: 055 * ・<og:query command="NEW" > 056 * SELECT文 057 * </og:query> 058 * ・<og:query command="NEW" names="・・・" queryType="JDBCErrMsg" > 059 * { call PL/SQL(?,?,?,? ) } 060 * </og:query> 061 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 062 * 063 * ●Tag定義: 064 * <og:query 065 * queryType 【TAG】Query を発行する為のクラスID(JDBC,JDBCCallable,JDBCErrMsg,JDBCUpdate)を指定します{@og.doc03Link queryType 初期値:JDBC}) 066 * command 【TAG】コマンド(NEW,RENEW)をセットします(PlsqlUpdateTag,UpdateTag の場合は、ENTRY) 067 * scope 【TAG】キャッシュする場合のスコープ[request/page/session/applicaton]を指定します(初期値:session) 068 * maxRowCount 【TAG】(通常は使いません)データの最大読み込み件数を指定します (初期値:DB_MAX_ROW_COUNT[=1000])(0:[無制限]) 069 * skipRowCount 【TAG】(通常は使いません)データの読み始めの初期値を指定します 070 * displayMsg 【TAG】検索結果を画面上に表示するメッセージリソースIDを指定します (初期値:VIEW_DISPLAY_MSG[=]) 071 * overflowMsg 【TAG】検索データが最大検索数をオーバーした場合に表示するメッセージリソースIDを指定します (初期値:MSG0007[検索結果が、制限行数を超えましたので、残りはカットされました]) 072 * notfoundMsg 【TAG】検索結果がゼロ件の場合に表示するメッセージリソースIDを指定します(初期値:MSG0077[対象データはありませんでした]) 073 * names 【TAG】PL/SQLを利用する場合の引数にセットすべき データの名称をCSV形式で複数指定します 074 * stopZero 【TAG】検索結果が0件のとき処理を続行するかどうか[true/false]を指定します(初期値:false[続行する]) 075 * tableId 【TAG】(通常は使いません)結果のDBTableModelを、sessionに登録するときのキーを指定します 076 * dbid 【TAG】(通常は使いません)Queryオブジェクトを作成する時のDB接続IDを指定します 077 * trace 【TAG】引数の SQL 文を EXPLAIN PLAN を[true:行う/それ以外:行わない]を指定します(初期値:false) 078 * checkNames 【TAG】リクエスト変数の正規化を行うカラムをCSV形式で複数指定します 079 * modifyType 【TAG】DB検索時の モディファイタイプを指定します[A:追加/C:更新/D:削除] 080 * quotCheck 【TAG】リクエスト情報の クォーティション(') 存在チェックを実施するかどうか[true/false]を設定します(初期値:USE_SQL_INJECTION_CHECK) 081 * stopError 【TAG】PLSQL/SQL処理エラーの時に処理を中止するかどうか[true/false]を設定します(初期値:true) 082 * xssCheck 【TAG】リクエスト情報の HTMLTag開始/終了文字(><) 存在チェックを実施するかどうか[true/false]を設定します (初期値:USE_XSS_CHECK[=true]) 083 * mainTrans 【TAG】(通常使いません)タグで処理される処理がメインとなるトランザクション処理かどうかを指定します(初期値:true) 084 * caseKey 【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null) 085 * caseVal 【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null) 086 * caseNN 【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:true) 087 * caseNull 【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:true) 088 * useBeforeHtmlTag 【TAG】 処理時間(queryTime)などの情報出力[true:有効/false:無効]を指定します(初期値:true) 089 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 090 * > ... Body ... 091 * </og:query> 092 * 093 * ●使用例 094 * <og:query command="NEW"> 095 * select PN,YOBI,NMEN,HINM from XX01 where PN = '{@PN}' order by PN 096 * </og:query> 097 * 098 * ・検索条件が入力された時({@PN}がNOT NULLのとき) 099 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 where PN = 'AAA' order by PN 100 * ・検索条件が入力されなかった時({@PN}がNULLのとき) 101 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 where PN = '' order by PN 102 * 103 * <og:query command="NEW"> 104 * select PN,YOBI,NMEN,HINM from XX01 105 * <og:where> 106 * <og:and value="PN = '{@PN}%'" /> 107 * <og:and value="YOBI like '{@YOBI}%'" /> 108 * </og:where> 109 * order by PN 110 * </og:query> 111 * 112 * ・検索条件が入力された時({@PN}がNOT NULLのとき) 113 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 PN = 'AAA%' and YOBI like 'BBB%' order by PN 114 * ・検索条件が入力されなかった時({@PN}がNULLのとき) WHERE句がなくなる。 115 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 order by PN 116 * 117 * 注意:WhereTagを使った場合、下のようにはなりません。 118 * select PN,YOBI,NMEN,HINM from XX01 PN = '' and YOBI like '%' order by PN 119 * 120 * <og:query command="NEW"> 121 * select PN,YOBI,NMEN,HINM from XX01 where PN="11111" 122 * <og:where startKey="and"> 123 * <og:and value="YOBI like '{@PN}%'" /> 124 * </og:where> 125 * order by PN 126 * </og:query> 127 * 128 * ・検索条件が入力された時({@YOBI}がNOT NULLのとき) 129 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 PN = '11111' and YOBI like 'BBB%' order by PN 130 * ・検索条件が入力されなかった時({@YOBI}がNULLのとき) WHERE句がなくなる。 131 * 作成されるSQL文⇒select PN,YOBI,NMEN,HINM from XX01 PN = '11111' order by PN 132 * 133 * <og:query 134 * command = "NEW" 135 * names = "SYSTEM_ID,LANG,CLM,NAME_JA,LABEL_NAME,KBSAKU,USER.ID" 136 * checkNames = "CLM,NAME_JA" 137 * queryType = "JDBCErrMsg" 138 * displayMsg = ""> 139 * {call TYPE3B01.TYPE3B01(?,?,?,?)} 140 * </og:query> 141 * 142 * ・queryType に JDBCErrMsg を指定して、PL/SQL をコールできます。 143 * 引数は、names 属性をキーにリクエスト変数から読み込みます。 144 * ・checkNames にカラム名を指定すると、columns.valueSet による 145 * リクエスト変数の正規化を行います。 146 * 147 * @og.group DB検索 148 * @og.group DB登録 149 * 150 * @version 4.0 151 * @author Kazuhiko Hasegawa 152 * @since JDK5.0, 153 */ 154public class QueryTag extends CommonTagSupport { 155 //* このプログラムのVERSION文字列を設定します。 {@value} */ 156 private static final String VERSION = "5.6.5.3 (2013/06/28)" ; 157 158 private static final long serialVersionUID = 565320130628L ; 159 160 /** command 引数に渡す事の出来る コマンド 新規 {@value} */ 161 public static final String CMD_NEW = "NEW" ; 162 /** command 引数に渡す事の出来る コマンド 再検索 {@value} */ 163 public static final String CMD_RENEW = "RENEW" ; 164 /** command 引数に渡す事の出来る コマンド リスト */ 165 private static final String[] COMMAND_LIST = new String[] { CMD_NEW , CMD_RENEW }; 166 167 /** エラーメッセージID {@value} */ 168 protected static final String errMsgId = HybsSystem.ERR_MSG_KEY; 169 170 private String queryType = null; 171 // 4.0.0.0 (2007/10/10) dbid の初期値を、"DEFAULT" から null に変更 172 private String dbid = null ; 173 protected transient DBTableModel table = null; 174 protected transient ErrorMessage errMessage = null; 175 protected String tableId = HybsSystem.TBL_MDL_KEY; 176 protected String command = CMD_NEW; 177 protected int skipRowCount = 0; 178 protected int maxRowCount = -1; 179 protected String sql = null; 180 protected int executeCount = -1; // 検索/実行件数 181 protected String names = null; 182 protected boolean outMessage = true; 183 protected int errCode = ErrorMessage.OK; 184 protected boolean quotCheck = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" ); // 4.0.0 (2005/08/31) 185 private boolean trace = false; // 4.0.0 (2005/01/31) 廃止 186 private boolean stopZero = false; 187 private String modifyType = null; // 3.8.5.1 (2006/05/08) modifyType 属性を追加します。 188 protected String displayMsg = HybsSystem.sys( "VIEW_DISPLAY_MSG" ); 189 private String overflowMsg = "MSG0007"; // 検索結果が、制限行数を超えましたので、残りはカットされました。 190 private String notfoundMsg = "MSG0077"; // 対象データはありませんでした。 191 private boolean isMainTrans = true; // 5.1.6.0 (2010/05/01) DBLastSqlの処理の見直し 192 193 // 3.5.4.7 (2004/02/06) 実行時間測定用のDIV要素を出力します。 194 protected long dyStart = 0; 195 // 4.3.3.0 (2008/09/22) PLSQL/SQL実行エラーの際に、処理を中止するかどうか。 196 protected boolean stopError = true; 197 198 private StringBuilder debugMsg = null; // 3.5.6.0 (2004/06/18) 199 200 // 3.8.0.5 (2005/08/20) リクエスト変数の正規化を行います。 201 private String checkNames = null; 202 203 // 3.8.5.3 (2006/08/07) トレース時のメッセージ文字列を保存しておきます。 204 private String traceMsg = null; 205 206 protected boolean xssCheck = HybsSystem.sysBool( "USE_XSS_CHECK" ); // 5.0.0.2 (2009/09/15) 207 208 // 5.3.5.0 (2011/05/01) 処理時間(queryTime)などの情報出力の有効/無効を指定します。 209 private boolean useBeforeHtmlTag = true ; 210 211 /** 212 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 213 * 214 * @og.rev 3.5.4.7 (2004/02/06) 実行時間測定用に、開始時刻を取得します。 215 * @og.rev 3.5.6.5 (2004/08/09) 暫定的に、DBTableModelを先行削除します。 216 * @og.rev 3.6.0.0 (2004/09/24) DBTableModel の先行削除は、scope="session" の場合のみ。 217 * @og.rev 5.1.6.0 (2010/05/01) DBLastSqlの処理は、DBTableModelが新規作成された処理でのみ行う。 218 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 219 * 220 * @return 後続処理の指示 221 */ 222 @Override 223 public int doStartTag() { 224 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 225 if( useTag() ) { 226 dyStart = System.currentTimeMillis(); 227 if( ! check( command, COMMAND_LIST ) ) { return SKIP_BODY ; } 228 229 useMainTrans( isMainTrans ); // 5.1.6.0 (2010/05/01) DBLastSqlの処理の見直し 230 startQueryTransaction( tableId ); // 3.6.0.8 (2004/11/19) 231 232 // 3.5.6.5 (2004/08/09) 削除するのは、セッションのオブジェクトでよい。 233 // 3.6.0.0 (2004/09/24) 削除するのは、scope="session" の場合のみ。 234 if( "session".equals( getScope() ) ) { 235 removeSessionAttribute( tableId ); 236 removeSessionAttribute( HybsSystem.VIEWFORM_KEY ); 237 } 238 239 return EVAL_BODY_BUFFERED ; // Body を評価する。( extends BodyTagSupport 時) 240 } 241 return SKIP_BODY ; // Body を評価しない 242 } 243 244 /** 245 * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。 246 * 247 * @og.rev 3.1.1.0 (2003/03/28) ボディの内容を取得する処理を、CommonTagSupport で行う。 248 * @og.rev 3.6.0.8 (2004/11/19) エラー発生時に確実にリリースされるように try finally 追加 249 * @og.rev 3.8.5.3 (2006/08/07) USER.LASTSQL へのSQL文の保存は、実行前に行っておきます。 250 * @og.rev 3.8.6.3 (2006/11/30) SQL 文の前後のスペースを取り除きます。 251 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得の為,ApplicationInfoオブジェクトを設定 252 * @og.rev 4.0.0.0 (2005/01/31) lang ⇒ ResourceManager へ変更 253 * @og.rev 4.0.0.0 (2005/08/31) useQuotCheck() によるSQLインジェクション対策 254 * @og.rev 4.3.4.0 (2008/12/01) GE20(ユーザー定数)へ登録するかのフラグへの対応 255 * @og.rev 5.0.0.2 (2009/09/15) XSS対応 256 * @og.rev 5.1.6.0 (2010/05/01) DBLastSqlの処理は、DBTableModelが新規作成された処理でのみ行う。 257 * @og.rev 5.1.9.0 (2010/08/01) TransactionTag 対応。上位に TransactionTag があれば、そこからConnection をもらう。 258 * @og.rev 5.3.6.0 (2011/06/01) 集計、合計などのEdit機能に対応します。 259 * @og.rev 5.3.7.0 (2011/07/01) TransactionReal の引数変更 260 * @og.rev 5.3.7.0 (2011/07/01) PL/SQLかつscope="request"で正しく出力するためqueryType,namesも保存する。 261 * @og.rev 5.3.8.0 (2011/08/01) Transaction発生箇所でclose() 262 * @og.rev 5.5.3.4 (2012/06/19) trace 時は、実際の検索処理を行わない様に変更。 263 * @og.rev 5.6.5.3 (2013/06/28) LASTQUERYTYPE ⇒ LASTSQLTYPE 変更。 264 * 265 * @return 後続処理の指示(SKIP_BODY) 266 */ 267 @Override 268 public int doAfterBody() { 269 270 // 4.0.0 (2005/08/31) useQuotCheck() によるSQLインジェクション対策 271 useQuotCheck( quotCheck ); 272 // 5.0.0.2 (2009/09/15) XSS対策 273 useXssCheck( xssCheck ); 274 275 sql = getBodyString().trim(); 276 277 // 3.2.1.0 (2003/05/28) 最終SQL文を、UserInfo に、キャッシュしておく。 278 // 5.1.6.0 (2010/05/01) DBLastSqlの処理の見直し 279 if( isMainTrans ) { 280 setUserInfo( "LASTSQL", sql, false ); 281 // 5.3.7.0 (2011/07/01) PL/SQLかつscope="request"で正しく出力するためqueryType,namesも保存する。 282 setUserInfo( "LASTSQLTYPE", queryType, false ); // 5.6.5.3 (2013/06/28) 283 setUserInfo( "LASTNAMES", names, false ); 284 } 285 286 Query query = QueryFactory.newInstance( queryType ); 287 Transaction tran = null; 288 try { 289 if( maxRowCount < 0 ) { 290 maxRowCount = sysInt( "DB_MAX_ROW_COUNT" ); 291 } 292 293 // 5.1.9.0 (2010/08/01) TransactionTag 対応 294 TransactionTag tranTag = (TransactionTag)findAncestorWithClass( this,TransactionTag.class ); 295 if( tranTag == null ) { 296 tran = new TransactionReal( getApplicationInfo() ); // 5.3.7.0 (2011/07/01) 引数変更 297 } 298 else { 299 tran = tranTag.getTransaction(); 300 } 301 query.setTransaction( dbid,tran ); // 5.1.9.0 (2010/08/01) TransactionTag 対応 302 303 query.setSkipRowCount( skipRowCount ); 304 query.setMaxRowCount( maxRowCount ); 305 query.setResourceManager( getResource() ); // 4.0.0 (2005/01/31) 306 307 if( trace ) { 308 traceMsg = traceQuery( sql,tran ); // 5.1.9.0 (2010/08/01) TransactionTag 対応 309 // 5.5.3.4 (2012/06/19) trace 時は、実際の検索処理を行わない様に変更 310 return SKIP_BODY ; 311 } 312 query.setStatement( sql ); 313 314 // 5.3.6.0 (2011/06/01) 集計、合計などのEdit機能に対応します。 315 if( isMainTrans ) { 316 String guikey = getGUIInfoAttri( "KEY" ); 317 String editName = getRequestValue( "editName" ); 318 DBEditConfig config = getUser().getEditConfig( guikey, editName ); 319 if( config != null ) { 320 query.setEditConfig( config ); 321 } 322 } 323 324 execute( query ); 325 326 executeCount = query.getExecuteCount(); 327 if( errCode < ErrorMessage.NG && executeCount >= 0 ) { // 異常以外の場合 328 table = query.getDBTableModel(); 329 // 3.8.5.1 (2006/05/08) modifyType 属性を追加します。 330 if( modifyType != null ) { 331 for( int row=0; row<executeCount; row++ ) { 332 table.setModifyType( row,modifyType ); 333 } 334 } 335 } 336 } 337 finally { 338 QueryFactory.close( query ); 339 if( tran != null ) { tran.close(); } // 5.3.8.0 (2011/08/01) Transaction発生箇所でclose() 340 } 341 return SKIP_BODY ; 342 } 343 344 /** 345 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 346 * 347 * @og.rev 2.0.0.8 (2002/10/09) command="NEW" のときのみ、displayMsg を表示させます。 348 * @og.rev 2.1.1.4 (2002/11/25) デバッグ時に最終SQLをユーザー情報をセットするように変更。 349 * @og.rev 2.1.2.1 (2002/11/27) ErrorMessage をクリアしないように変更。 350 * @og.rev 3.1.1.0 (2003/03/28) JspWriter オブジェクトの使用箇所を、jspPrint() を使用するように変更。 351 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 352 * @og.rev 3.2.1.0 (2003/05/28) 最終SQL文を、UserInfo に、キャッシュしておく。 353 * @og.rev 3.3.3.3 (2003/08/06) 検索結果の件数を、"DB.COUNT" キーでリクエストにセットする。 354 * @og.rev 3.3.3.3 (2003/08/06) 検索結果を、"DB.ERR_CODE" キーでリクエストにセットする。 355 * @og.rev 3.5.4.7 (2004/02/06) 実行時間測定用のDIV要素を出力しておきます。 356 * @og.rev 3.5.4.9 (2004/02/25) 警告時に停止していましたが、継続処理させます。 357 * @og.rev 3.5.5.0 (2004/03/12) ErrorMessage オブジェクトを、query が成功した時にもクリアするように変更 358 * @og.rev 3.5.5.2 (2004/04/02) TaglibUtil.makeHTMLErrorTable メソッドを利用 359 * @og.rev 3.5.5.8 (2004/05/20) ErrorMessage オブジェクトを、コマンドが NEW の場合のみ、クリア 360 * @og.rev 3.5.6.0 (2004/06/18) debugMsg 属性を出力するように修正します。 361 * @og.rev 3.6.0.8 (2004/11/19) DBTableModel をセーブする時に、トランザクションチェックを行います。 362 * @og.rev 3.8.5.3 (2006/08/07) USER.LASTSQL へのSQL文の保存は、実行前に行っておきます。 363 * @og.rev 4.0.0.0 (2006/11/14) notfoundMsg 属性を追加。displayMsg は、VIEW_USE_DISPLAY_MSG で制御 364 * @og.rev 4.0.0.0 (2007/10/18) メッセージリソース統合( getResource().getMessage ⇒ getResource().getLabel ) 365 * @og.rev 4.3.3.0 (2008/09/22) 属性 stopError の設定により、JSP処理を中止するかどうかを制御します。 366 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 367 * @og.rev 5.3.5.0 (2011/05/01) 処理時間(queryTime)などの情報出力の有効/無効を指定します。 368 * @og.rev 5.5.0.3 (2012/03/13) オーバーフローメッセージが存在しないときは、何もしない。(改行も入れない) 369 * @og.rev 5.5.3.4 (2012/06/19) trace 時は、実際の検索処理を行わない様に変更。 370 * @og.rev 5.6.3.0 (2013/04/01) エラー時メッセージ変更 371 * 372 * @return 後続処理の指示 373 */ 374 @Override 375 public int doEndTag() { 376 debugPrint(); // 4.0.0 (2005/02/28) 377 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 378 if( !useTag() ) { return EVAL_PAGE ; } 379 380 if( trace ) { 381 jspPrint( traceMsg ); 382 return SKIP_PAGE; // 5.5.3.4 (2012/06/19) trace 時は、実際の検索処理を行わない様に変更。 383 } 384 385 String label = ""; // 4.0.0 (2005/11/30) 検索しなかった場合。 386 if( check( command, COMMAND_LIST ) ) { 387 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL ); 388 389 // 実行件数の表示 command="NEW" のときのみ、displayMsg を表示させます。 390 // 4.0.0 (2005/11/30) 出力順の変更。一番最初に出力します。 391 if( CMD_NEW.equals( command ) ) { 392 if( executeCount > 0 && displayMsg != null && displayMsg.length() > 0 ) { 393 buf.append( executeCount ); 394 buf.append( getResource().getLabel( displayMsg ) ); 395 buf.append( HybsSystem.BR ); 396 } 397 else if( executeCount == 0 && notfoundMsg != null && notfoundMsg.length() > 0 ) { 398 buf.append( getResource().getLabel( notfoundMsg ) ); 399 buf.append( HybsSystem.BR ); 400 } 401 } 402 403 // 3.3.3.3 (2003/08/06) 検索結果の件数を、"DB.COUNT" キーでリクエストにセットする。 404 setRequestAttribute( "DB.COUNT" , String.valueOf( executeCount ) ); 405 // 3.3.3.3 (2003/08/06) 検索結果を、"DB.ERR_CODE" キーでリクエストにセットする。 406 setRequestAttribute( "DB.ERR_CODE", String.valueOf( errCode ) ); 407 408 // オーバーフロー時のメッセージを表示 409 // 5.5.0.3 (2012/03/09) オーバーフローメッセージが存在しないときは、何もしない。(改行も入れない) 410 if( table != null && table.isOverflow() && overflowMsg != null && overflowMsg.length() > 0 ) { 411 buf.append( getResource().getLabel( overflowMsg ) ); 412 buf.append( HybsSystem.BR ); 413 } 414 415 // 3.5.5.2 (2004/04/02) TaglibUtil.makeHTMLErrorTable メソッドを利用 416 String err = TaglibUtil.makeHTMLErrorTable( errMessage,getResource() ); 417 if( err != null && err.length() > 0 ) { 418 buf.append( err ); 419 setSessionAttribute( errMsgId,errMessage ); 420 } 421 else if( CMD_NEW.equals( command ) ) { // 3.5.5.8 (2004/05/20) 422 removeSessionAttribute( errMsgId ); 423 } 424 label = buf.toString(); 425 426 if( table != null && ! commitTableObject( tableId, table ) ) { 427 // 3.6.0.8 (2004/11/19) トランザクションチェックを行います。 428 // jspPrint( "QueryTag Query処理が割り込まれました。DBTableModel は登録しません。" ); 429 430 // 5.6.4.0 (2013/04/01) リソースから出力するように対応 431 ErrorMessage errMsgObj = new ErrorMessage( "QueryTag Query Error!" ); 432 errMsgObj.addMessage( 0,ErrorMessage.NG,"ERR0041" ); 433 jspPrint( TaglibUtil.makeHTMLErrorTable( errMsgObj,getResource() ) ); 434 435 return SKIP_PAGE ; 436 } 437 } 438 439 jspPrint( label ); 440 441 // 3.5.4.9 (2004/02/25) 警告時に停止していましたが、継続処理させます。 442 final int rtnCode ; 443 if( errCode >= ErrorMessage.NG ) { // 異常 444 if( stopError ) { // 4.3.3.0 (2008/09/22) 属性 stopError の設定により、処理を中止するかを判断します。 445 rtnCode = SKIP_PAGE; 446 } 447 else { 448 rtnCode = EVAL_PAGE; 449 } 450 } 451 else { 452 // 件数0件かつ stopZero = true 453 if( executeCount == 0 && stopZero ) { 454 rtnCode = SKIP_PAGE; 455 } 456 else { 457 rtnCode = EVAL_PAGE; 458 } 459 } 460 461 // 3.5.4.7 (2004/02/06) 462 long dyTime = System.currentTimeMillis()-dyStart; 463 464 // 5.3.5.0 (2011/05/01) 処理時間(queryTime)などの情報出力の有効/無効を指定します。 465 if( useBeforeHtmlTag ) { 466 jspPrint( "<div id=\"queryTime\" value=\"" + (dyTime) + "\"></div>" ); // 3.5.6.3 (2004/07/12) 467 } 468 469 // 4.0.0 (2005/01/31) セキュリティチェック(データアクセス件数登録) 470 GUIInfo guiInfo = (GUIInfo)getSessionAttribute( HybsSystem.GUIINFO_KEY ); 471 if( guiInfo != null ) { guiInfo.addReadCount( executeCount,dyTime,sql ); } 472 473 return rtnCode ; 474 } 475 476 /** 477 * タグリブオブジェクトをリリースします。 478 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 479 * 480 * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加 481 * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。 482 * @og.rev 3.5.4.7 (2004/02/06) 実行時間測定用に、dyStart を追加します。 483 * @og.rev 3.5.6.0 (2004/06/18) debugMsg 属性を追加します。 484 * @og.rev 3.8.0.5 (2005/08/20) checkNames 属性を追加します。 485 * @og.rev 3.8.5.1 (2006/05/08) modifyType 属性を追加します。 486 * @og.rev 3.8.5.1 (2006/05/08) traceMsg 属性(トレース時のメッセージ文字列)を追加します。 487 * @og.rev 4.0.0.0 (2005/08/31) quotCheck 属性の追加 488 * @og.rev 4.0.0.0 (2007/10/10) dbid の初期値を、"DEFAULT" から null に変更 489 * @og.rev 4.3.3.0 (2008/09/22) stopError 属性の追加 490 * @og.rev 5.0.0.2 (2009/09/15) XSS対応 491 * @og.rev 5.1.6.0 (2010/05/01) DBLastSqlの処理は、DBTableModelが新規作成された処理でのみ行う。 492 * @og.rev 5.3.5.0 (2011/05/01) 処理時間(queryTime)などの情報出力の有効/無効を指定します。 493 * 494 */ 495 @Override 496 protected void release2() { 497 super.release2(); 498 tableId = HybsSystem.TBL_MDL_KEY; 499 queryType = null; 500 dbid = null; 501 command = CMD_NEW; 502 skipRowCount = 0; 503 maxRowCount = -1; 504 table = null; 505 sql = null; 506 displayMsg = HybsSystem.sys( "VIEW_DISPLAY_MSG" ); 507 overflowMsg = "MSG0007"; // 検索結果が、制限行数を超えましたので、残りはカットされました。 508 notfoundMsg = "MSG0077"; // 対象データはありませんでした。 509 executeCount = -1; // 検索/実行件数 510 names = null; 511 outMessage = true; 512 trace = false; 513 errCode = ErrorMessage.OK; 514 errMessage = null; 515 stopZero = false; 516 stopError = true; // 4.3.3.0 (2008/09/22) 517 dyStart = 0; 518 debugMsg = null; // 3.5.6.0 (2004/06/18) 519 checkNames = null; // 3.8.0.5 (2005/08/20) 520 quotCheck = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" ); // 4.0.0 (2005/08/31) 521 modifyType = null; // 3.8.5.1 (2006/05/08) 522 traceMsg = null; // 3.8.5.3 (2006/08/07) 523 xssCheck = HybsSystem.sysBool( "USE_XSS_CHECK" ); // 5.0.0.2 (2009/09/15) 524 isMainTrans = true; // 5.1.6.0 (2010/05/01) DBLastSqlの処理の見直し 525 useBeforeHtmlTag = true ; // 5.3.5.0 (2011/05/01) 526 } 527 528 /** 529 * Query を実行します。 530 * 531 * @og.rev 2.1.2.3 (2002/12/02) データベース更新時に、更新フラグをセットするように変更 532 * @og.rev 3.4.0.0 (2003/09/01) 登録エラー時のキーと値を表示するように変更。 533 * @og.rev 3.5.6.0 (2004/06/18) デバッグ情報出力用に、printDebug メソッドを追加。 534 * @og.rev 3.6.1.0 (2005/01/05) エラーコードによる commit/rollback の判断追加 535 * @og.rev 5.3.7.0 (2011/07/01) nameの判定にゼロ文字列を付加 536 * 537 * @param query オブジェクト 538 */ 539 protected void execute( final Query query ) { 540 String[] nameArray = null; 541 String[] values = null; 542 try { 543 if( names == null || names.length() == 0 ) { 544 query.execute(); 545 } 546 else { 547 nameArray = StringUtil.csv2Array( names ); 548 values = getRequest( nameArray ); 549 // 3.5.6.0 (2004/06/18) デバッグ情報出力用 550 if( isDebug() ) { printDebug( nameArray,values ); } 551 query.execute( values ); 552 } 553 errCode = query.getErrorCode(); 554 errMessage = query.getErrorMessage(); 555 // 3.6.1.0 (2005/01/05) エラーコードによる commit/rollback の判断追加 556 if( query.isUpdate() ) { 557 if( errCode < ErrorMessage.NG ) { // 異常以下の場合 558 query.commit(); 559 } 560 else { 561 query.rollback(); 562 } 563 } 564 } 565 catch( HybsSystemException ex ) { 566 query.rollback(); 567 568 // 4.0.0 (2005/02/28) エラー時の表示とデバッグ時の表示を統一する。 569 String errMsg = "DATABASE ERROR! " + HybsSystem.CR ; 570 if( nameArray != null ) { 571 printDebug( nameArray,values ); 572 errMsg += debugMsg; 573 } 574 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数の並び順変更 575 } 576 finally { 577 if( query != null ) { query.close(); } 578 } 579 } 580 581 /** 582 * デバッグ用に、配列データを書き出します。 583 * 584 * @og.rev 3.5.6.0 (2004/06/18) 新規追加 585 * 586 * @param nms 引数 names の配列データ 587 * @param vals names に対応するリクエスト情報の配列 588 */ 589 private void printDebug( final String[] nms,final String[] vals ) { 590 if( debugMsg == null ) { debugMsg = new StringBuilder(); } 591 592 debugMsg.append( " names=[" ); 593 debugMsg.append( StringUtil.array2csv( nms ) ); 594 debugMsg.append( "]" ); 595 debugMsg.append( HybsSystem.CR ); 596 debugMsg.append( " values=[" ); 597 debugMsg.append( StringUtil.array2csv( vals ) ); 598 debugMsg.append( "]" ); 599 debugMsg.append( HybsSystem.CR ); 600 } 601 602 /** 603 * 名称配列を元に、リクエスト情報のデータを取得します。 604 * checkNames 属性に設定されているカラムがあれば、値を正規化します。 605 * 606 * @og.rev 3.8.0.5 (2005/08/20) リクエスト変数の正規化(checkNames)対応 607 * 608 * @param nameArray キーとなる名称の配列 609 * 610 * @return そのリクエスト情報の配列 611 */ 612 protected String[] getRequest( final String[] nameArray ) { 613 String[] rtn = new String[nameArray.length]; 614 615 for( int i=0; i<rtn.length; i++ ) { 616 rtn[i] = getRequestValue( nameArray[i] ); 617 618 // 3.8.0.5 (2005/08/20) checkNames があり、rtn[i] がある場合。 619 if( checkNames != null && checkNames.length() > 0 && rtn[i].length() > 0 ) { 620 if( ( "," + checkNames + "," ).indexOf( "," + nameArray[i] + "," ) >= 0 ) { 621 DBColumn dbColumn = getDBColumn( nameArray[i] ); 622 String val = dbColumn.valueSet( rtn[i] ); 623 if( val != null ) { rtn[i] = val; } 624 } 625 } 626 } 627 628 return rtn; 629 } 630 631 /** 632 * 【TAG】(通常は使いません)データの読み始めの初期値を指定します。 633 * 634 * @og.tag 635 * データベース自体の検索は,指定されたSQLの全件を検索しますが, 636 * DBTableModelのデータとしては、スキップ件数分は登録されません。 637 * サーバーのメモリ資源と応答時間の確保の為です。 638 * 639 * @param count 読み始めの初期値 640 */ 641 public void setSkipRowCount( final String count ) { 642 skipRowCount = nval( getRequestParameter( count ),skipRowCount ); 643 } 644 645 /** 646 * 【TAG】(通常は使いません)データの最大読み込み件数を指定します 647 * (初期値:DB_MAX_ROW_COUNT[={@og.value org.opengion.hayabusa.common.SystemData#DB_MAX_ROW_COUNT}])。 648 * 649 * @og.tag 650 * データベース自体の検索は,指定されたSQLの全件を検索しますが, 651 * DBTableModelのデータとして登録する最大件数をこの値に設定します。 652 * サーバーのメモリ資源と応答時間の確保の為です。 653 * 0 をセットすると、無制限(Integer.MAX_VALUE)になります。 654 * (初期値:ユーザー定数のDB_MAX_ROW_COUNT[={@og.value org.opengion.hayabusa.common.SystemData#DB_MAX_ROW_COUNT}])。 655 * 656 * @og.rev 5.5.8.5 (2012/11/27) 0を無制限として処理します。 657 * 658 * @param count 最大読み込み件数 659 * @see org.opengion.hayabusa.common.SystemData#DB_MAX_ROW_COUNT 660 */ 661 public void setMaxRowCount( final String count ) { 662 maxRowCount = nval( getRequestParameter( count ),maxRowCount ); 663 if( maxRowCount == 0 ) { maxRowCount = Integer.MAX_VALUE ; } // 5.5.8.5 (2012/11/27) 664 } 665 666 /** 667 * 【TAG】(通常は使いません)結果のDBTableModelを、sessionに登録するときのキーを指定します 668 * (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])。 669 * 670 * @og.tag 671 * 検索結果より、DBTableModelオブジェクトを作成します。これを、下流のviewタグ等に 672 * 渡す場合に、通常は、session を利用します。その場合の登録キーです。 673 * query タグを同時に実行して、結果を求める場合、同一メモリに配置される為、 674 * この tableId 属性を利用して、メモリ空間を分けます。 675 * (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])。 676 * 677 * @param id sessionに登録する時の ID 678 */ 679 public void setTableId( final String id ) { 680 tableId = nval( getRequestParameter( id ),tableId ); // 3.8.0.9 (2005/10/17) 681 } 682 683 /** 684 * 【TAG】Query を発行する為のクラスID(JDBC,JDBCCallable,JDBCErrMsg,JDBCUpdate)を指定します({@og.doc03Link queryType 初期値:JDBC})。 685 * 686 * @og.tag 687 * 検索を実行する手段は、Query インターフェースの実装クラスになります。 688 * このタグでは、Query.execute( String[] ) メソッドが呼ばれます。 689 * 例えば、ストアドプロシージャ等を実行する場合に、queryType="JDBCErrMsg" 690 * を指定することができます。 691 * 初期値は、"JDBC" です。 692 * queryType は、システムリソースの Query_**** 宣言の **** を与えます。 693 * これらは、Query インターフェースを継承したサブクラスである必要があります。 694 * 標準で、org.opengion.hayabusa.db 以下の Query_**** クラスが、Query_**** 宣言 と 695 * して、定義されています。 696 * 属性クラス定義の {@link org.opengion.hayabusa.db.Query Query} を参照願います。 697 * {@og.doc03Link queryType Query_**** クラス} 698 * 699 * @param id Query を発行する為の実クラス ID 700 * @see org.opengion.hayabusa.db.Query Queryのサブクラス 701 * @see org.opengion.hayabusa.db.Query#execute( String[] ) 702 */ 703 public void setQueryType( final String id ) { 704 queryType = getRequestParameter( id ); 705 } 706 707 /** 708 * 【TAG】(通常は使いません)Queryオブジェクトを作成する時のDB接続IDを指定します。 709 * 710 * @og.tag 711 * Queryオブジェクトを作成する時のDB接続IDを指定します。 712 * これは、システムリソースで、DEFAULT_DB_URL 等で指定している データベース接続先 713 * 情報に、XX_DB_URL を定義することで、 dbid="XX" とすると、この 接続先を使用して 714 * データベースにアクセスできます。 715 * 716 * @param id データベース接続ID 717 */ 718 public void setDbid( final String id ) { 719 dbid = nval( getRequestParameter( id ),dbid ); 720 } 721 722 /** 723 * 【TAG】コマンド(NEW,RENEW)をセットします(PlsqlUpdateTag,UpdateTag の場合は、ENTRY)。 724 * 725 * @og.tag 726 * コマンドは,HTMLから(get/post)指定されますので,CMD_xxx で設定される 727 * フィールド定数値のいづれかを、指定できます。 728 * 729 * @param cmd コマンド(public static final 宣言されている文字列) 730 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.QueryTag.CMD_NEW">コマンド定数</a> 731 */ 732 public void setCommand( final String cmd ) { 733 String cmd2 = getRequestParameter( cmd ); 734 if( cmd2 != null && cmd2.length() >= 0 ) { command = cmd2.toUpperCase(Locale.JAPAN); } 735 } 736 737 /** 738 * 【TAG】検索結果が0件のとき処理を続行するかどうか[true/false]を指定します(初期値:false[続行する])。 739 * 740 * @og.tag 741 * 初期値は、false(続行する)です。 742 * 743 * @param cmd 検索結果が0件のとき、[true:処理を中止する/false:続行する] 744 */ 745 public void setStopZero( final String cmd ) { 746 stopZero = nval( getRequestParameter( cmd ),stopZero ); 747 } 748 749 /** 750 * 【TAG】検索結果を画面上に表示するメッセージリソースIDを指定します 751 * (初期値:VIEW_DISPLAY_MSG[={@og.value org.opengion.hayabusa.common.SystemData#VIEW_DISPLAY_MSG}])。 752 * 753 * @og.tag 754 * ここでは、検索結果の件数や登録された件数をまず出力し、 755 * その次に、ここで指定したメッセージをリソースから取得して表示します。 756 * 件数を表示させたい場合は、displayMsg = "MSG0033"[ 件検索しました] をセットしてください。 757 * 表示させたくない場合は, displayMsg = "" をセットしてください。 758 * (初期値:システム定数のVIEW_DISPLAY_MSG[={@og.value org.opengion.hayabusa.common.SystemData#VIEW_DISPLAY_MSG}])。 759 * 760 * @param id ディスプレイに表示させるメッセージ ID 761 * @see org.opengion.hayabusa.common.SystemData#VIEW_DISPLAY_MSG 762 */ 763 public void setDisplayMsg( final String id ) { 764 String ids = getRequestParameter( id ); 765 if( ids != null ) { displayMsg = ids; } 766 } 767 768 /** 769 * 【TAG】検索データが最大検索数をオーバーした場合に表示するメッセージリソースIDを指定します 770 * (初期値:MSG0007[検索結果が、制限行数を超えましたので、残りはカットされました])。 771 * 772 * @og.tag 773 * 検索結果が、maxRowCount で設定された値より多い場合、何らかのデータは検索されず 774 * 切り捨てられたことになります。 775 * ここでは、displayMsg を表示した後、必要に応じて、このメッセージを表示します。 776 * 表示させたくない場合は, overflowMsg = "" をセットしてください。 777 * 初期値は、MSG0007[検索結果が、制限行数を超えましたので、残りはカットされました]です。 778 * 779 * @param id ディスプレイに表示させるメッセージ ID 780 */ 781 public void setOverflowMsg( final String id ) { 782 String ids = getRequestParameter( id ); 783 if( ids != null ) { overflowMsg = ids; } 784 } 785 786 /** 787 * 【TAG】検索結果がゼロ件の場合に表示するメッセージリソースIDを指定します(初期値:MSG0077[対象データはありませんでした])。 788 * 789 * @og.tag 790 * ここでは、検索結果がゼロ件の場合のみ、特別なメッセージを表示させます。 791 * 従来は、displayMsg と兼用で、『0 件検索しました』という表示でしたが、 792 * displayMsg の初期表示は、OFF になりましたので、ゼロ件の場合のみ別に表示させます。 793 * 表示させたくない場合は, notfoundMsg = "" をセットしてください。 794 * 初期値は、MSG0077[対象データはありませんでした]です。 795 * 796 * @param id ディスプレイに表示させるメッセージ ID 797 */ 798 public void setNotfoundMsg( final String id ) { 799 String ids = getRequestParameter( id ); 800 if( ids != null ) { notfoundMsg = ids; } 801 } 802 803 /** 804 * 【TAG】PL/SQLを利用する場合の引数にセットすべき データの名称をCSV形式で複数指定します。 805 * 806 * @og.tag 807 * 複数ある場合は、カンマ区切り文字で渡します。 808 * names 属性は、queryType に応じて設定可否が異なりますので、ご注意ください。 809 * names なし:JDBC,JDBCUpdate 810 * names あり:JDBCCallable,JDBCErrMsg,JDBCUpdate 811 * (JDBCUpdateは、names 属性のあり/なし両方に対応しています。) 812 * 813 * @og.rev 3.0.1.3 (2003/03/11) names 属性に null で渡す場合のバグを修正 814 * 815 * @param nm 引数の名称(複数ある場合は、カンマ区切り文字) 816 */ 817 public void setNames( final String nm ) { 818 names = nval( getRequestParameter( nm ),names ); 819 } 820 821 /** 822 * 【TAG】検索結果のメッセージを表示する/しない[true/false]を指定します(初期値:true)。 823 * 824 * @og.tag 825 * 初期値は、表示する:true です。 826 * 827 * @param flag [true:表示する/それ以外:含めない] 828 */ 829 public void setOutMessage( final String flag ) { 830 outMessage = nval( getRequestParameter( flag ),outMessage ); 831 } 832 833 /** 834 * 【TAG】引数の SQL 文を EXPLAIN PLAN を[true:行う/それ以外:行わない]を指定します(初期値:false)。 835 * 836 * @og.tag 837 * 838 * ここでは、以下の処理を行います。 839 * 1.引数の SQL 文を画面に表示します。 840 * 2.引数の SQL 文を EXPLAIN PLAN した結果を、画面に表示します。 841 * なお、以前は、セッションのトレースを行っていましたが、その機能は、廃止いたします。 842 * 初期値は、行わない:false です。 843 * 844 * @param flag トレース [true:行う/それ以外:行わない] 845 */ 846 public void setTrace( final String flag ) { 847 trace = nval( getRequestParameter( flag ),trace ); 848 } 849 850 /** 851 * 【TAG】リクエスト変数の正規化を行うカラムをCSV形式で複数指定します。 852 * 853 * @og.tag 854 * PL/SQLを利用する場合の引数にセットすべき データを、リクエスト変数の 855 * 値そのままではなく、カラムオブジェクトの valueSet メソッド経由で正規化 856 * した値を使用するようにします。 857 * 858 * @og.rev 3.8.0.5 (2005/08/20) 新規追加 859 * 860 * @param nm リクエスト変数の正規化を行うカラム 861 */ 862 public void setCheckNames( final String nm ) { 863 checkNames = nval( getRequestParameter( nm ),checkNames ); 864 } 865 866 /** 867 * 【TAG】DB検索時の モディファイタイプを指定します[A:追加/C:更新/D:削除]。 868 * 869 * @og.tag 870 * DB検索時に、そのデータをA(追加)、C(更新)、D(削除)のモディファイタイプを 871 * つけた状態にします。 872 * その状態で、そのまま、update する事が可能になります。 873 * 874 * @og.rev 3.8.5.1 (2006/05/08) 新規追加 875 * 876 * @param type DB検索時の モディファイタイプ [A:追加/C:更新/D:削除] 877 */ 878 public void setModifyType( final String type ) { 879 modifyType = nval( getRequestParameter( type ),modifyType ); 880 } 881 882 /** 883 * 【TAG】リクエスト情報の クォーティション(') 存在チェックを実施するかどうか[true/false]を設定します 884 * (初期値:USE_SQL_INJECTION_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK}])。 885 * 886 * @og.tag 887 * SQLインジェクション対策の一つとして、暫定的ではありますが、SQLのパラメータに 888 * 渡す文字列にクォーティション(') を許さない設定にすれば、ある程度は防止できます。 889 * 数字タイプの引数には、 or 5=5 などのクォーティションを使用しないコードを埋めても、 890 * 数字チェックで検出可能です。文字タイプの場合は、必ず (')をはずして、 891 * ' or 'A' like 'A のような形式になる為、(')チェックだけでも有効です。 892 * (') が含まれていたエラーにする(true)/かノーチェックか(false)を指定します。 893 * 初期値は、SystemData#USE_SQL_INJECTION_CHECK です。 894 * 895 * @og.rev 4.0.0.0 (2005/08/31) 新規追加 896 * 897 * @param flag クォーティションチェック [true:する/それ以外:しない] 898 */ 899 public void setQuotCheck( final String flag ) { 900 quotCheck = nval( getRequestParameter( flag ),quotCheck ); 901 } 902 903 /** 904 * 【TAG】リクエスト情報の HTMLTag開始/終了文字(><) 存在チェックを実施するかどうか[true/false]を設定します 905 * (初期値:USE_XSS_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK}])。 906 * 907 * @og.tag 908 * クロスサイトスクリプティング(XSS)対策の一環としてless/greater than signについてのチェックを行います。 909 * (><) が含まれていたエラーにする(true)/かノーチェックか(false)を指定します。 910 * (初期値:システム定数のUSE_XSS_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK}]) 911 * 912 * @og.rev 5.0.0.2 (2009/09/15) 新規追加 913 * 914 * @param flag XSSチェック [true:する/false:しない] 915 * @see org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK 916 */ 917 public void setXssCheck( final String flag ) { 918 xssCheck = nval( getRequestParameter( flag ),xssCheck ); 919 } 920 921 /** 922 * 【TAG】PLSQL/SQL処理エラーの時に処理を中止するかどうか[true/false]を設定します(初期値:true)。 923 * 924 * @og.tag 925 * false(中止しない)に設定する場合、後続処理では、{@DB.ERR_CODE}の値により、 926 * PLSQL/SQLの異常/正常終了によって分岐処理は可能となります。 927 * 初期値は、true(中止する)です。 928 * 929 * @og.rev 4.3.3.0 (2008/09/22) 新規追加 930 * 931 * @param flag [true:中止する/false:中止しない] 932 */ 933 public void setStopError( final String flag ) { 934 stopError = nval( getRequestParameter( flag ),stopError ); 935 } 936 937 /** 938 * 引数の SQL 文を EXPLAIN PLAN します。 939 * 940 * ここでは、以下の処理を行います。 941 * 1.引数の SQL 文を画面に表示します。 942 * 2.引数の SQL 文を EXPLAIN PLAN した結果を、画面に表示します。 943 * なお、この処理は、ORACLE 専用処理です。 944 * 945 * @og.rev 3.8.5.3 (2006/08/07) 新規追加 946 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得の為,ApplicationInfoオブジェクトを設定 947 * @og.rev 5.1.9.0 (2010/08/01) Transaction 対応します。 948 * @og.rev 5.5.3.4 (2012/06/19) getUserInfo は、キー部分だけで処理します。 949 * 950 * @param sql EXPLAIN PLANするSQL 文 951 * @param tran Transactionオブジェクト 952 * 953 * @return トレース結果の文字列 954 */ 955 private String traceQuery( final String sql , final Transaction tran ) { 956 String userId = getUserInfo( "ID" ) ; // 5.5.3.4 (2012/06/19) getUserInfo は、キー部分だけで処理します。 957 958 String[] arg1 = new String[] { userId }; 959 DBUtil.dbExecute( "DELETE FROM PLAN_TABLE WHERE STATEMENT_ID = ?",arg1,tran,dbid ); // 5.1.9.0 (2010/08/01) 960 961 String explan1 = "EXPLAIN PLAN SET STATEMENT_ID = '" + userId + "' FOR " + sql ; 962 DBUtil.dbExecute( explan1,null,tran,dbid ); // 5.1.9.0 (2010/08/01) 963 964 String[] arg2 = new String[] { userId,userId,userId }; 965 String explan2 = "select LEVEL as LVL" 966 + ",lpad(' ',LEVEL,' ') || rtrim( OPERATION ) || ' ' || rtrim( OPTIONS ) || ' ' || rtrim( OBJECT_NAME ) as EXECUTION_PLAN" 967 + ",OBJECT_NAME as OBJ_NAME" 968 + ",DECODE(INSTR(OBJECT_TYPE,' '),0,OBJECT_TYPE,SUBSTR(OBJECT_TYPE,1,INSTR(OBJECT_TYPE,' ')-1)) as OBJ_TYPE" 969 + ",OPTIMIZER as OPT" 970 + ",COST as CST" 971 + ",CARDINALITY as CARD" 972 + ",BYTES as BYTE" 973 + ",ACCESS_PREDICATES as ACCS" 974 + ",FILTER_PREDICATES as FILTER" 975 + " from PLAN_TABLE" 976 + " where STATEMENT_ID = ?" 977 + " start with ID = 0" 978 + " and STATEMENT_ID = ?" 979 + " connect by prior ID = PARENT_ID" 980 + " and STATEMENT_ID = ?" ; 981 982 String[][] plan = DBUtil.dbExecute( explan2,arg2,tran,dbid,true ); // 5.5.3.4 (2012/06/19) ヘッダー情報も同時に取得する。 983 984 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 985 buf.append( "<pre>" ).append( sql ).append( "</pre>" ).append( HybsSystem.BR ); 986 buf.append( "<table>" ); 987 // 1行目のヘッダーの出力 988 int colsize = plan[0].length; 989 buf.append( "<tr class=\"row_h\">" ); 990 for( int j=0; j<colsize; j++ ) { 991 buf.append( "<th>" ).append( plan[0][j] ).append( "</th>" ); 992 } 993 buf.append( "</tr>" ); 994 995 for( int i=1; i<plan.length; i++ ) { 996 buf.append( "<tr class=\"row_" ).append( i%2 ).append( "\">" ); 997 for( int j=0; j<colsize; j++ ) { 998 if( j==1 ) { 999 buf.append( "<td><pre>" ).append( plan[i][1] ).append( "</pre></td>" ); 1000 } 1001 else { 1002 buf.append( "<td>" ).append( plan[i][j] ).append( "</td>" ); 1003 } 1004 } 1005 buf.append( "</tr>" ); 1006 } 1007 buf.append( "</table>" ).append( HybsSystem.BR ); 1008 return buf.toString(); 1009 } 1010 1011 /** 1012 * 【TAG】(通常使いません)タグで処理される処理がメインとなるトランザクション処理かどうかを指定します(初期値:true)。 1013 * 1014 * @og.tag 1015 * この値は、ファイルダウンロード処理に影響します。この値がtrueに指定された時にcommitされたDBTableModelが 1016 * ファイルダウンロードの対象の表になります。 1017 * 1018 * このパラメーターは、通常、各タグにより実装され、ユーザーが指定する必要はありません。 1019 * 但し、1つのJSP内でDBTableModelが複数生成される場合に、前に処理したDBTableModelについてファイルダウンロードをさせたい 1020 * 場合は、後ろでDBTableModelを生成するタグで、明示的にこの値をfalseに指定することで、ファイルダウンロード処理の対象から 1021 * 除外することができます。 1022 * 1023 * @og.rev 5.1.6.0 (2010/05/01) 新規作成 1024 * 1025 * @param flag メイントランザクションかどうか 1026 */ 1027 public void setMainTrans( final String flag ) { 1028 isMainTrans = nval( getRequestParameter( flag ),isMainTrans ); 1029 } 1030 1031 /** 1032 * 【TAG】 処理時間(queryTime)などの情報出力[true:有効/false:無効]を指定します(初期値:true)。 1033 * 1034 * @og.tag 1035 * Query で、検索する場合に、処理時間(queryTime)などの情報を出力していますが、 1036 * ViewForm で、CustomData などの 非HTML表示ビューを使用する場合、データとして、 1037 * 紛れ込んでしまうため、出力を抑制する必要があります。 1038 * true(有効)にすると、これらのHTMLが出力されます。false にすると、出力されません。 1039 * 初期値は、true(有効) です。 1040 * 1041 * @og.rev 5.3.5.0 (2011/05/01) 新規追加 1042 * 1043 * @param useTag 情報出力の有効/無効を指定 [true:有効/false:無効] 1044 */ 1045 public void setUseBeforeHtmlTag( final String useTag ) { 1046 useBeforeHtmlTag = nval( getRequestParameter( useTag ),useBeforeHtmlTag ); 1047 } 1048 1049 /** 1050 * シリアライズ用のカスタムシリアライズ書き込みメソッド 1051 * 1052 * @og.rev 4.0.0.0 (2006/09/31) 新規追加 1053 * @serialData 一部のオブジェクトは、シリアライズされません。 1054 * 1055 * @param strm ObjectOutputStreamオブジェクト 1056 * @throws IOException 入出力エラーが発生した場合 1057 */ 1058 private void writeObject( final ObjectOutputStream strm ) throws IOException { 1059 strm.defaultWriteObject(); 1060 } 1061 1062 /** 1063 * シリアライズ用のカスタムシリアライズ読み込みメソッド 1064 * 1065 * ここでは、transient 宣言された内部変数の内、初期化が必要なフィールドのみ設定します。 1066 * 1067 * @og.rev 4.0.0.0 (2006/09/31) 新規追加 1068 * @serialData 一部のオブジェクトは、シリアライズされません。 1069 * 1070 * @param strm ObjectInputStreamオブジェクト 1071 * @see #release2() 1072 * @throws IOException シリアライズに関する入出力エラーが発生した場合 1073 * @throws ClassNotFoundException クラスを見つけることができなかった場合 1074 */ 1075 private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException { 1076 strm.defaultReadObject(); 1077 } 1078 1079 /** 1080 * このオブジェクトの文字列表現を返します。 1081 * 基本的にデバッグ目的に使用します。 1082 * 1083 * @return このクラスの文字列表現 1084 */ 1085 @Override 1086 public String toString() { 1087 return sql ; 1088 1089 // return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 1090 // .println( "VERSION" ,VERSION ) 1091 // .println( "tableId" ,tableId ) 1092 // .println( "queryType" ,queryType ) 1093 // .println( "dbid" ,dbid ) 1094 // .println( "command" ,command ) 1095 // .println( "skipRowCount" ,skipRowCount ) 1096 // .println( "maxRowCount" ,maxRowCount ) 1097 // .println( "sql" ,sql ) 1098 // .println( "displayMsg" ,displayMsg ) 1099 // .println( "overflowMsg" ,overflowMsg ) 1100 // .println( "executeCount" ,executeCount ) 1101 // .println( "names" ,names ) 1102 // .println( "outMessage" ,outMessage ) 1103 // .println( "trace" ,trace ) 1104 // .println( "errCode" ,errCode ) 1105 // .println( "stopZero" ,stopZero ) 1106 // .println( "quotCheck" ,quotCheck ) 1107 // .println( "dyStart" ,dyStart ) 1108 // .println( "checkNames" ,checkNames ) 1109 // .println( "Other..." ,getAttributes().getAttribute() ) 1110 // .fixForm().toString() ; 1111 } 1112}