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.hayabusa.taglib; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.common.HybsSystemException; 020 import org.opengion.hayabusa.db.DBConstValue; 021 022 import org.opengion.fukurou.util.StringUtil ; 023 import static org.opengion.fukurou.util.StringUtil.nval ; 024 025 import java.util.Map; 026 import java.util.LinkedHashMap; 027 028 /** 029 * TableUpdateTag にパラメーターを渡す為のタグクラスです? 030 * 031 * 汎用???タベ?ス登録処?行えるタグ tableUpdate タグを新規作?します? 032 * これは、?体的なSLQを作?する tableUpdateParam タグと?合わせて使用できます? 033 * tableUpdate タグは、queryType に JDBCTableUpdate を指定します?基本?これ? 034 * です?tableUpdateParam では、sqlType に、INSERT,COPY,UPDATE,MODIFY,DELETE の 035 * どれかを指定する事で、SQL??タイプを?します?COPY,MODIFY は command と 036 * 関連を持たす為に追?て?タイプで、INSERTやUPDATE と同じ処?行います? 037 * tableUpdateParam の table には、作?した?SQL の??ブルを指定します? 038 * where 属?は、検索結果の DBTableModel の更新時に使用する条件を指定します? 039 * 040 * @og.formSample 041 * ●形式?lt;og:tableUpdate command="{@command}" queryType="JDBCTableUpdate" > 042 * <og:tableUpdateParam 043 * sqlType = "{@sqlType}" // INSERT,COPY,UPDATE,MODIFY,DELETE 044 * table = "{@TABLE_NAME}" // 処?象の??ブル? 045 * names = "{@names}" // 処?象のカラ? 046 * omitNames = "{@omitNames}" // 処?象外?カラ? 047 * where = "{@where}" // 処?象を特定するキー 048 * whereNames = "{@whereNames}" // 処?象を特定するキー条件(where句)をCSV形? 049 * constKeys = "{@constKeys}" // 処?ラ?の中の固定情報カラ? 050 * constVals = "{@constVals}" // 処?ラ?の中の固定情報設定? 051 * asNames = "{@asNames}" // 別名を付けたカラ?(select A as B from TBL の B を指? 052 * orgNames = "{@orgNames}" // tableの実際のカラ?(select A as B from TBL の A を指? 053 * funcKeys = "{@funcKeys}" // 関数等を設定するカラ? 054 * funcVals = "{@funcVals}" // 関数等?設定? 055 * logicalDelete = "{@logicalDelete}" // sqlTypeがDELETEの場合にもUPDATE?発? 056 * /> 057 * </og:tableUpdate> 058 * 059 * ●body?な? 060 * 061 * ●Tag定義?? 062 * <og:tableUpdateParam 063 * sqlType ○?TAG】BODY部に書かれて? SQLタイプを?しま???) 064 * table ○?TAG】??象の??ブル名を?しま???) 065 * names 【TAG】??象のカラ?をCSV形式で??しま? 066 * omitNames 【TAG】??象外?カラ?をCSV形式で??しま? 067 * where 【TAG】??象を特定するキー条件(where句)を指定しま? 068 * whereNames 【TAG】??象を特定するキー条件(where句)をCSV形式で??しま? 069 * constKeys 【TAG】設定?を固定?と置き換える対象となるカラ?をCSV形式で??しま? 070 * constVals 【TAG】設定?を固定?と置き換える対象となる設定?をCSV形式で??しま? 071 * funcKeys 【TAG】関数等を設定するカラ?をCSV形式で??しま? 072 * funcVals 【TAG】関数等?設定?をCSV形式で??しま? 073 * asNames 【TAG】別名を付けたカラ?(select A as B from TBL の B を指?をCSV形式で??しま? 074 * orgNames 【TAG】tableの実際のカラ?(select A as B from TBL の A を指?をCSV形式で??しま? 075 * quotCheck 【TAG】リクエスト情報の クォー?ション(') 存在チェ?を実施するかど?[true/false]を設定しま?(初期値:USE_SQL_INJECTION_CHECK[=true]) 076 * constObjKey 【TAG】固定情報カラ??処?ブジェクトを特定するキーを設定しま?初期値:SYSTEM_ID) 077 * logicalDelete 【TAG】sqlType="DELETE"の場合に論理削除(UPDATE)を行うかど?を指定しま?初期値:false) 078 * debug 【TAG】デバッグ??を?力するかど?[true/false]を指定しま?初期値:false) 079 * /> 080 * 081 * ●使用? 082 * ・【entry.jsp? 083 * <og:tableUpdate command="{@command}" queryType="JDBCTableUpdate" > 084 * <og:tableUpdateParam 085 * sqlType = "{@sqlType}" 086 * table = "{@MEM.TABLE_NAME}" 087 * where = "ROWID = [ROWID]" 088 * /> 089 * </og:tableUpdate> 090 * 091 * @og.rev 3.8.8.0 (2007/12/22) 新規作? 092 * @og.rev 4.1.2.0 (2008/03/12) 実??大?修正 093 * @og.group ??登録 094 * 095 * @version 4.0 096 * @author Kazuhiko Hasegawa 097 * @since JDK5.0, 098 */ 099 public class TableUpdateParamTag extends CommonTagSupport { 100 //* こ?プログラ??VERSION??を設定します? {@value} */ 101 private static final String VERSION = "4.0.0.0 (2005/11/30)" ; 102 103 private static final long serialVersionUID = 4000 ; // 4.0.0 (2005/11/30) 104 105 /** sqlType属?に設定できる値 {@value} */ 106 public static final String SQL_TYPE = "|INSERT|COPY|UPDATE|MODIFY|DELETE|" ; 107 108 // 3.8.0.4 (2005/08/08) 印刷時に使用するシス?ID 109 private static final String SYSTEM_ID =HybsSystem.sys( "SYSTEM_ID" ); 110 111 // 4.3.6.0 (2009/05/01) ?ォルトで利用するconstObjのシス?リソース? 112 private static final String DEFAULT_CONST_OBJ = HybsSystem.sys( "DEFAULT_CONST_CLASS" ); 113 114 private String sqlType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE 115 private String table = null; // 処?象の??ブル? 116 private String[] names = null; // 処?象のカラ? 117 private String omitNames = ",ROWID,ROWNUM,WRITABLE,"; // 処?象外?カラ? 118 private String where = null; // 処?象を特定するキー 119 private String whereNames = null; // 5.5.8.5 (2012/11/27) 処?象を特定するCSV形式?カラ? 120 private String[] constKeys = null; // 処?ラ?の中の固定情報カラ? 121 private String[] constVals = null; // 処?ラ?の中の固定情報設定? 122 private String[] funcKeys = null; // 5.5.1.9 (2012/04/19) 関数等を設定するカラ? 123 private String[] funcVals = null; // 5.5.1.9 (2012/04/19) 関数等?設定? 124 private String[] asNames = null; // 5.5.1.9 (2012/04/19) 別名を付けたカラ?(select A as B from TBL の B を指? 125 private String[] orgNames = null; // 5.5.1.9 (2012/04/19) tableの実際のカラ?(select A as B from TBL の A を指? 126 private String constObjKey = SYSTEM_ID; // 固定情報カラ??処?ブジェクトを特定するキー 127 private boolean quotCheck = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" ); 128 private boolean logicalDelete = false; // 4.3.7.0 (2009/06/01) sqlTypeがDELETEの場合にもUPDATE?発? 129 130 /** 131 * Taglibの開始タグが見つかったときに処??doStartTag() ?オーバ?ライドします? 132 * 133 * @og.rev 5.5.1.9 (2012/04/19) エラーチェ?を?に行います? 134 * 135 * @return 後続????( SKIP_BODY ) 136 */ 137 @Override 138 public int doStartTag() { 139 140 // constKeys,constVals の個数チェ? 141 if( constKeys != null ) { 142 if( constVals == null || constKeys.length != constVals.length ) { 143 String errMsg = "<b>constKeys と、constVals の個数が異なります?</b><br />" 144 + " constKeys=[" + StringUtil.array2csv( constKeys ) + "]" 145 + " constVals=[" + StringUtil.array2csv( constVals ) + "]" ; 146 throw new HybsSystemException( errMsg ); 147 } 148 } 149 150 // funcKeys,funcVals の個数チェ? 151 if( funcKeys != null ) { 152 if( funcVals == null || funcKeys.length != funcVals.length ) { 153 String errMsg = "<b>funcKeys と、funcVals の個数が異なります?</b><br />" 154 + " funcKeys=[" + StringUtil.array2csv( funcKeys ) + "]" 155 + " funcVals=[" + StringUtil.array2csv( funcVals ) + "]" ; 156 throw new HybsSystemException( errMsg ); 157 } 158 } 159 160 // asNames,orgNames の個数チェ? 161 if( orgNames != null ) { 162 if( asNames == null || orgNames.length != asNames.length ) { 163 String errMsg = "<b>orgNames と、asNames の個数が異なります?</b><br />" 164 + " orgNames=[" + StringUtil.array2csv( orgNames ) + "]" 165 + " asNames=[" + StringUtil.array2csv( asNames ) + "]" ; 166 throw new HybsSystemException( errMsg ); 167 } 168 } 169 170 return(SKIP_BODY); // Body を評価しな? 171 } 172 173 /** 174 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします? 175 * 176 * @og.rev 4.3.7.0 (2009/06/01) 論理削除対? 177 * 178 * @return 後続???? 179 */ 180 @Override 181 public int doEndTag() { 182 debugPrint(); 183 184 TableUpdateTag updateTag = (TableUpdateTag)findAncestorWithClass( this,TableUpdateTag.class ); 185 if( updateTag == null ) { 186 String errMsg = "<b>こ?タグは、TableUpdateTagの??(要?に記述してください?/b>"; 187 throw new HybsSystemException( errMsg ); 188 } 189 190 String upSqlType = updateTag.getSqlType() ; 191 if( upSqlType == null || upSqlType.equals( sqlType ) ) { 192 // 通常の names カラ??列を設定します? 193 if( names == null ) { names = updateTag.getNames(); } 194 NamesData namesData = makeNamesData( names ); 195 196 String query = null; 197 if( "INSERT".equalsIgnoreCase( sqlType ) || "COPY".equalsIgnoreCase( sqlType ) ) { 198 query = getInsertSQL( namesData ); 199 } 200 else if( "UPDATE".equalsIgnoreCase( sqlType ) || "MODIFY".equalsIgnoreCase( sqlType ) 201 || ( "DELETE".equalsIgnoreCase( sqlType ) && logicalDelete ) ) { // 4.3.7.0 (2009/06/01) 202 query = getUpdateSQL( namesData ); 203 } 204 else if( "DELETE".equalsIgnoreCase( sqlType ) ) { 205 query = getDeleteSQL(); 206 } 207 208 jspPrint( query ); 209 } 210 211 return(EVAL_PAGE); 212 } 213 214 /** 215 * タグリブオブジェクトをリリースします? 216 * キャ?ュされて再利用される?で、フィールド?初期設定を行います? 217 * 218 * @og.rev 4.3.7.0 (2009/06/01) logicalDelete属?追? 219 * @og.rev 5.5.1.9 (2012/04/19) asNames、orgNames、funcKeys、funcVals属?追? 220 * @og.rev 5.5.8.5 (2012/11/27) 処?象を特定するCSV形式?カラ? 221 */ 222 @Override 223 protected void release2() { 224 super.release2(); // 3.5.6.0 (2004/06/18) 追?抜けて?) 225 sqlType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE 226 table = null; // 処?象の??ブル? 227 names = null; // 処?象のカラ? 228 omitNames = ",ROWID,ROWNUM,WRITABLE,"; // 処?象外?カラ? 229 where = null; // 処?象を特定するキー 230 whereNames = null; // 5.5.8.5 (2012/11/27) 処?象を特定するCSV形式?カラ? 231 constKeys = null; // 処?ラ?の中の固定情報カラ? 232 constVals = null; // 処?ラ?の中の固定情報設定? 233 quotCheck = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" ); 234 constObjKey = SYSTEM_ID; // 固定情報カラ??処?ブジェクトを特定するキー 235 logicalDelete = false; // 4.3.7.0 (2009/06/01) 236 funcKeys = null; // 5.5.1.9 (2012/04/19) 関数等を設定するカラ? 237 funcVals = null; // 5.5.1.9 (2012/04/19) 関数等?設定? 238 asNames = null; // 5.5.1.9 (2012/04/19) 別名を付けたカラ?(select A as B from TBL の B を指? 239 orgNames = null; // 5.5.1.9 (2012/04/19) tableの実際のカラ?(select A as B from TBL の A を指? 240 } 241 242 /** 243 * 【TAG】BODY部に書かれて? SQLタイプを?します? 244 * 245 * @og.tag 246 * SQLタイプ?、INSERT,COPY,UPDATE,MODIFY,DELETE の中から?す? 247 * ?があります?これら?、?部に書かれるSQLの形式を?する?に使用します? 248 * ?処??、DBTableModelの改?ー?A,C,D)に対して使用され? 249 * SQL を選択する?合???に使用されます? 250 * なお?COPY と MODIFY は、command で?できる簡易機?として用意して?す? 251 * 上位? TableUpdateTag の sqlType 属? と同じsqlType 属?の場合?み、SQL? 252 * 合?・出力します?(上位?sqlTypeがnullの場合?、無条件実行します?) 253 * ??タイプが、異なる?合?、なにも??行いません? 254 * 255 * @param type BODY部に書かれて? SQL タイ? 256 */ 257 public void setSqlType( final String type ) { 258 sqlType = nval( getRequestParameter( type ),sqlType ); 259 if( sqlType != null && SQL_TYPE.indexOf( "|" + sqlType + "|" ) < 0 ) { 260 sqlType = null; 261 // String errMsg = "sqlType属?には? + SQL_TYPE + "以外設定できません? 262 // + " typeIn=[" + type + "]" 263 // + " sqlType=[" + sqlType + "]" ; 264 // throw new HybsSystemException( errMsg ); 265 } 266 } 267 268 /** 269 * 【TAG】??象の??ブル名を?します? 270 * 271 * @og.tag 272 * ??ブル名を?することで、sqlTypeに応じ?QUERYを生成することが?来ます? 273 * 生?する場合?カラ?特定する?合?、names 属?で?できます? 274 * また?WHERE条件は、where属?で?します? 275 * 276 * @param tbl ??ブル? 277 * @see #setNames( String ) 278 * @see #setWhere( String ) 279 * @see #setSqlType( String ) 280 */ 281 public void setTable( final String tbl ) { 282 table = nval( getRequestParameter( tbl ),table ); 283 } 284 285 /** 286 * 【TAG】??象のカラ?をCSV形式で??します? 287 * 288 * @og.tag 289 * 生?するQUERYのカラ?をカンマ区???CSV)で??します? 290 * ?がな??合?、DBTableModel の全カラ?※)を使用して、QUERYを構築します? 291 * ?に、テーブル結合してDBTableModelを構築した?合?、登録すべきカラ? 292 * ?する?があります? 293 * (※)正確には、DBTableModel の全カラ???、ROWID,ROWNUM,WRITABLE カラ?? 294 * 無視します? 295 * ?方法???常のパラメータ取得後に、CSV?します? 296 * 297 * @og.rev 3.8.8.5 (2007/03/09) 通常のパラメータ取得後に、CSV?に戻します? 298 * 299 * @param nms カラ?(CSV形? 300 * @see #setTable( String ) 301 * @see #setOmitNames( String ) 302 */ 303 public void setNames( final String nms ) { 304 names = StringUtil.csv2Array( getRequestParameter( nms ) ); 305 if( names.length == 0 ) { names = null; } 306 } 307 308 /** 309 * 【TAG】??象外?カラ?をCSV形式で??します? 310 * 311 * @og.tag 312 * 生?するQUERYのカラ?に?しな?ラ?をカンマ区???CSV)で??します? 313 * ?がな??合?、DBTableModel の全カラ?※)を使用して、QUERYを構築します? 314 * ??ブル結合などで、??たくな?ラ?の方が少な??合に、names ですべて? 315 * ?するより少な?述ですみます? 316 * (※)正確には、DBTableModel の全カラ???、ROWID,ROWNUM,WRITABLE カラ?? 317 * 無視します? 318 * 319 * @og.rev 5.7.0.0 (2013/11/3) 空白?削除 320 * 321 * @param nms カラ?(CSV形? 322 * @see #setTable( String ) 323 * @see #setNames( String ) 324 */ 325 public void setOmitNames( final String nms ) { 326 // omitNames = omitNames + nval( getRequestParameter( nms ),"" ) + ","; 327 omitNames = omitNames + StringUtil.deleteWhitespace( nval( getRequestParameter( nms ),"" ) ) + ","; 328 } 329 330 /** 331 * 【TAG】??象を特定するキー条件(where句)を指定します? 332 * 333 * @og.tag 334 * 生?するQUERYのwhere 句を指定します?通常の WHERE 句の書き方と同じで? 335 * DBTableModelの値を割り当てたい?に[カラ?] を記述します? 336 * ??の場合?設定?をセ?するときに、シングルコー??ション? 337 * 使用しますが、[カラ?]で?する?合?、その前後に?')シングル 338 * コー??ションは、不要です? 339 * {@XXXX}変数を使用する場合?、パース時に固定文字に置き換えられる為? 340 * ???時の(')シングルコー??ションが?になります? 341 * ※ 5.5.8.5 (2012/11/27) whereNames 属?と併用した場合?、where が?and を付けて、文字?結合されます? 342 * 例:FGJ='1' and CLM=[CLM] and SYSTEM_ID in ([SYSID],'**') and KBSAKU='{@KBSAKU}' 343 * 344 * @param wr 検索条件(where句) 345 */ 346 public void setWhere( final String wr ) { 347 where = nval( getRequestParameter( wr ),where ); 348 } 349 350 /** 351 * 【TAG】??象を特定するキー条件(where句)をCSV形式で??します? 352 * 353 * @og.tag 354 * 生?するQUERYのwhere 句を指定する方法として、?のカラ?をCSV?し、?部で 355 * KEY=[KEY] ??を作?します? 356 * ここでは、カラ?は、データベ?スのカラ?と同じで、かつ、DBTableModel に? 357 * 同じカラ????タが存在して?こと、と?条件付きとします? 358 * また?where 条件との併用を行いますが、こちら?条件が?に使用され、where 条件は? 359 * and を付けて、文字?結合されます? 360 * 例?CLM,SYSTEM_ID,KBSAKU ? CLM=[CLM] and SYSTEM_ID=[SYSTEM_ID] and KBSAKU=[KBSAKU] 361 * 362 * @og.rev 5.5.8.5 (2012/11/27) 新規追? 363 * 364 * @param wrnm 検索条件(where句)作?のためのカラ?(CSV形? 365 */ 366 public void setWhereNames( final String wrnm ) { 367 whereNames = nval( getRequestParameter( wrnm ),whereNames ); 368 } 369 370 /** 371 * 【TAG】設定?を固定?と置き換える対象となるカラ?をCSV形式で??します? 372 * 373 * @og.tag 374 * names 属?のカラ? table 属?より、QUERYを作?して、DBTableModelの値? 375 * 割り当てる?合?DBTableModelの値ではなく?外部から?した固定?? 376 * 割り当てたい場合に、そのカラ?をカンマ区???CSV)で??します? 377 * <del>ここで?するカラ?は、names 属?に含まれるか?DBTableModelのカラ?して 378 * 存在する?があります?なお?names 属?に含まれる場合?、DBTableModelのカラ? 379 * 含まれる??ありません?/del> 380 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 381 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 382 * 383 * @param keys カラ?(CSV形? 384 * @see #setConstVals( String ) 385 */ 386 public void setConstKeys( final String keys ) { 387 constKeys = getCSVParameter( keys ); 388 } 389 390 /** 391 * 【TAG】設定?を固定?と置き換える対象となる設定?をCSV形式で??します? 392 * 393 * @og.tag 394 * names 属?のカラ? table 属?より、QUERYを作?して、DBTableModelの 395 * 値を割り当てる?合?DBTableModelの値ではなく?外部から?した固定?? 396 * 割り当てたい場合に、そのカラ?に対応する設定?をカンマ区???CSV)で 397 * ??します?ここで?する設定?は、constKeys 属?と対応させます? 398 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 399 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 400 * 401 * @param vals 設定?(CSV形? 402 * @see #setConstKeys( String ) 403 */ 404 public void setConstVals( final String vals ) { 405 constVals = getCSVParameter( vals ); 406 } 407 408 /** 409 * 【TAG】関数等を設定するカラ?をCSV形式で??します? 410 * 411 * @og.tag 412 * constVals 属?で設定する?は、?シングルクオートが付与されます? 413 * そ?場合?関数などを設定したい場合でも???として設定しようとします? 414 * ここで?するカラ?(funcKeys)自身は、constKeys と同じ書式です? 415 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 416 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 417 * 418 * @og.rev 5.5.1.9 (2012/04/19) 新規追? 419 * 420 * @param keys カラ?(CSV形? 421 * @see #setFuncVals( String ) 422 */ 423 public void setFuncKeys( final String keys ) { 424 funcKeys = getCSVParameter( keys ); 425 } 426 427 /** 428 * 【TAG】関数等?設定?をCSV形式で??します? 429 * 430 * @og.tag 431 * funcKeys 属?に対応す?関数などの設定?を割り当てます? 432 * constVals 属?との違いは、funcVals の設定?は、そのままの形で、SQL?? 433 * 構築に使われます? 434 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 435 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 436 * 437 * @og.rev 5.5.1.9 (2012/04/19) 新規追? 438 * 439 * @param vals 設定?(CSV形? 440 * @see #setFuncKeys( String ) 441 */ 442 public void setFuncVals( final String vals ) { 443 funcVals = getCSVParameter( vals ); 444 } 445 446 /** 447 * 【TAG】別名を付けたカラ?(select A as B from TBL の B を指?をCSV形式で??します? 448 * 449 * @og.tag 450 * SELECT ?記述したとき?別名を付けて?り?SELECTした??ブルと別の??ブルに 451 * DBTableModelの値を書き込??合?DBTableModel の持って?カラ?と、実際に 452 * 書き込?ラ?が異なります?そ?ようなケースに、?の別名カラ??します? 453 * orgNames属?の並び?、asNames属?の並び?合わせておく?があります? 454 * こ?カラ?は、DBTableModel には持って?が???ブル側には持って??? 455 * なので、?部? omitNames 属?に値を設定します?利用??、omitNames に 456 * 書き込???ありません? 457 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 458 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 459 * 460 * @og.rev 5.5.1.9 (2012/04/19) 新規追? 461 * 462 * @param keys カラ?(CSV形? 463 * @see #setOrgNames( String ) 464 */ 465 public void setAsNames( final String keys ) { 466 asNames = getCSVParameter( keys ); 467 } 468 469 /** 470 * 【TAG】tableの実際のカラ?(select A as B from TBL の A を指?をCSV形式で??します? 471 * 472 * @og.tag 473 * SELECT ?記述したとき?別名を付けて?り?SELECTした??ブルと別の??ブルに 474 * DBTableModelの値を書き込??合?DBTableModel の持って?カラ?と、実際に 475 * 書き込?ラ?が異なります?そ?ようなケースに、テーブルの実カラ??します? 476 * orgNames属?の並び?、asNames属?の並び?合わせておく?があります? 477 * こ?カラ?は、DBTableModel には持って?せんが???ブル側には持って?値 478 * なので、このカラ?で、SQL?構築します? UPDATE TBL SET A=[B] WHERE … となります? 479 * ?方法?、CSV変数を?に?してから、getRequestParameter で値を取得します? 480 * こうしな???タ自身にカンマを持って?場合に?をミスる為です? 481 * 482 * @og.rev 5.5.1.9 (2012/04/19) 新規追? 483 * 484 * @param keys カラ?(CSV形? 485 * @see #setAsNames( String ) 486 */ 487 public void setOrgNames( final String keys ) { 488 orgNames = getCSVParameter( keys ); 489 } 490 491 /** 492 * 【TAG】リクエスト情報の クォー?ション(') 存在チェ?を実施するかど?[true/false]を設定しま? 493 * (初期値:USE_SQL_INJECTION_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK}])? 494 * 495 * @og.tag 496 * ???インジェクション対策??として、暫定的ではありますが、SQLのパラメータに 497 * 渡す文字?にクォー?ション(') を許さな?定にすれば、ある程度は防止できます? 498 * 数字タイプ?引数には?or 5=5 などのクォー?ションを使用しな?ードを埋めても? 499 * 数字チェ?で検?可能です??タイプ?場合?、? (')を?ずして? 500 * ' or 'A' like 'A のような形式になる為?')チェ??でも有効です? 501 * (') が含まれて?エラーにする(true)?かノ?チェ??false)を指定します? 502 * (初期値:シス?定数のUSE_SQL_INJECTION_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK}])? 503 * 504 * @param flag クォー?ションチェ? [true:する/それ以?しない] 505 * @see org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK 506 */ 507 public void setQuotCheck( final String flag ) { 508 quotCheck = nval( getRequestParameter( flag ),quotCheck ); 509 } 510 511 /** 512 * 【TAG】固定情報カラ??処?ブジェクトを特定するキーを設定しま?初期値:SYSTEM_ID)? 513 * 514 * @og.tag 515 * 固定情報カラ?をシス?単位にJavaクラスで管?きます? 516 * そ?クラスオブジェクト?、org.opengion.hayabusa.db.DBConstValue インターフェース? 517 * 継承した、plugin クラスになります? 518 * そ?クラスを特定するキーワードを?します? 519 * 初期値は、SYSTEM_ID でシス?単位にクラスを作?します? 520 * もし、他?シス?と共通?場合?、継承?させることも可能です? 521 * 対応したDBConstValueクラスが?ラグインとして存在しな??合?? 522 * シス?リソースのDEFAULT_CONST_CLASSで?されたクラスが利用されます? 523 * 524 * 初期値は、SYSTEM_ID です? 525 * 526 * @param key 固定情報カラ??処?ブジェクトを特定するキー 527 */ 528 public void setConstObjKey( final String key ) { 529 constObjKey = nval( getRequestParameter( key ),constObjKey ); 530 } 531 532 /** 533 * 【TAG】sqlType="DELETE"の場合に論理削除(UPDATE)を行うかど?を指定しま?初期値:false)? 534 * 535 * @og.tag 536 * sqlType="DELETE"の場合に論理削除(UPDATE)を行うかど?を指定します? 537 * trueが指定された場合?、DELETE?はなく?UPDATE?発行されます? 538 * falseが指定された場合?、DELETE?発行されます? 539 * さらに論理削除を行う場合?org.opengion.hayabusa.db.DBConstValue インターフェースに 540 * 定義されて?、getLogicalDeleteKeys()及?getLogicalDeleteValsを実?ることで? 541 * 論理削除する際?フラグの更新方法を統?に管?ることが可能になります? 542 * 初期値は、false(物?除する)で? 543 * 544 * @param flg 論理削除(UPDATE)を行うかど? 545 */ 546 public void setLogicalDelete( final String flg ) { 547 logicalDelete = nval( getRequestParameter( flg ),logicalDelete ); 548 } 549 550 /** 551 * ??タをインサートする?合に使用するSQL?作?します? 552 * 553 * @og.rev 4.1.2.1 (2008/03/17) DBConstValue による固定?セ?を採用 554 * @og.rev 4.3.6.4 (2009/05/01) ?ォルト設定をシス?リソースで設定可能にする 555 * @og.rev 5.3.4.0 (2011/04/01) DEFAULT_CONST_OBJの初期値変更(null→ゼロ??) 556 * 557 * @param namesData NamesDataオブジェク? 558 * 559 * @return インサー?QL 560 */ 561 private String getInsertSQL( final NamesData namesData ) { 562 String cls = HybsSystem.sys( "DBConstValue_" + constObjKey ) ; 563 564 // 4.3.6.4 (2009/05/01) 標準?追? 565 if( cls == null){ 566 cls = DEFAULT_CONST_OBJ; 567 } 568 569 // if( cls != null ) { // 5.3.4.0 (2011/04/01) 570 if( cls != null && !cls.isEmpty() ) { 571 DBConstValue constVal = (DBConstValue)HybsSystem.newInstance( cls ); 572 // 4.2.1.0 (2008/04/16) 初期化追? 573 constVal.init( table,getUser().getUserID(),getGUIInfoAttri( "KEY" ) ); 574 String[] keys = constVal.getInsertKeys(); 575 String[] vals = constVal.getInsertVals(); 576 namesData.add( keys,vals ); 577 } 578 579 String[] nms = namesData.getNames(); 580 String[] vls = namesData.getVals(); 581 582 StringBuilder sql = new StringBuilder(); 583 sql.append( "INSERT INTO " ).append( table ); 584 sql.append( " ( " ); 585 sql.append( nms[0] ); 586 for( int i=1; i<nms.length; i++ ) { 587 sql.append( "," ).append( nms[i] ); 588 } 589 sql.append( " ) VALUES ( " ); 590 sql.append( vls[0] ); 591 for( int i=1; i<vls.length; i++ ) { 592 sql.append( "," ).append( vls[i] ); 593 } 594 sql.append( " )" ); 595 596 return sql.toString(); 597 } 598 599 /** 600 * ??タをア????トする?合に使用するSQL?作?します? 601 * 602 * where と whereNames が同時に?された場合?、whereNames が?に処?? 603 * where 条件は、and 結合されます? 604 * 605 * @og.rev 4.1.2.1 (2008/03/17) DBConstValue による固定?セ?を採用 606 * @og.rev 4.3.6.4 (2009/05/01) ?ォルト設定をシス?リソースで設定可能にする 607 * @og.rev 4.3.7.0 (2009/06/01) 論理削除対? 608 * @og.rev 5.3.7.0 (2011/07/01) DEFAULT_CONST_OBJの初期値変更(null→ゼロ??) 対応忘れ 609 * @og.rev 5.5.8.5 (2012/11/27) whereNames 対? 610 * 611 * @param namesData NamesDataオブジェク? 612 * 613 * @return ア?????QL 614 */ 615 private String getUpdateSQL( final NamesData namesData ) { 616 String cls = HybsSystem.sys( "DBConstValue_" + constObjKey ) ; 617 618 // 4.3.6.4 (2009/05/01) 標準?追? 619 if( cls == null){ 620 cls = DEFAULT_CONST_OBJ; 621 } 622 623 // if( cls != null ) { 624 if( cls != null && !cls.isEmpty() ) { // 5.3.7.0 (2011/07/01) 625 DBConstValue constVal = (DBConstValue)HybsSystem.newInstance( cls ); 626 // 4.2.1.0 (2008/04/16) 初期化追? 627 constVal.init( table,getUser().getUserID(),getGUIInfoAttri( "KEY" ) ); 628 // 4.3.7.0 (2009/06/01) 論理削除対? 629 String[] keys = null; 630 String[] vals = null; 631 if( "DELETE".equalsIgnoreCase( sqlType ) ) { 632 keys = constVal.getLogicalDeleteKeys(); 633 vals = constVal.getLogicalDeleteVals(); 634 } 635 else { 636 keys = constVal.getUpdateKeys(); 637 vals = constVal.getUpdateVals(); 638 } 639 namesData.add( keys,vals ); 640 } 641 642 String[] nms = namesData.getNames(); 643 String[] vls = namesData.getVals(); 644 645 StringBuilder sql = new StringBuilder(); 646 sql.append( "UPDATE " ).append( table ).append( " SET " ); 647 sql.append( nms[0] ).append( "=" ).append( vls[0] ); 648 649 for( int i=1; i<nms.length; i++ ) { 650 sql.append( "," ); 651 sql.append( nms[i] ).append( "=" ).append( vls[i] ); 652 } 653 654 // 5.5.8.5 (2012/11/27) whereNames 対? 655 String whereAnd = " WHERE " ; 656 if( whereNames != null && whereNames.length() > 0 ) { 657 String[] wnms = whereNames.split(","); 658 sql.append( whereAnd ).append( wnms[0] ).append( "=[" ).append( wnms[0] ).append( "]" ); 659 660 for( int i=1; i<wnms.length; i++ ) { 661 sql.append( " AND " ).append( wnms[i] ).append( "=[" ).append( wnms[i] ).append( "]" ); 662 } 663 whereAnd = " AND " ; // whereNames 優先?ここを?らなければ、?期?のまま? WHERE " が使われ? 664 } 665 666 // 5.5.8.5 (2012/11/27) whereNames 対応?whereNames が登録されて?ば、AND で繋げる? 667 if( where != null && where.length() > 0 ) { 668 // sql.append( " WHERE " ).append( where ); 669 sql.append( whereAnd ).append( where ); 670 } 671 672 return sql.toString(); 673 } 674 675 /** 676 * ??タをデリートする?合に使用するSQL?作?します? 677 * 678 * where と whereNames が同時に?された場合?、whereNames が?に処?? 679 * where 条件は、and 結合されます? 680 * 681 * @og.rev 5.5.8.5 (2012/11/27) whereNames 対? 682 * 683 * @return ?ー?QL 684 */ 685 private String getDeleteSQL() { 686 StringBuilder sql = new StringBuilder(); 687 sql.append( "DELETE FROM " ).append( table ); 688 689 // 5.5.8.5 (2012/11/27) whereNames 対? 690 String whereAnd = " WHERE " ; 691 if( whereNames != null && whereNames.length() > 0 ) { 692 String[] wnms = whereNames.split(","); 693 sql.append( whereAnd ).append( wnms[0] ).append( "=[" ).append( wnms[0] ).append( "]" ); 694 695 for( int i=1; i<wnms.length; i++ ) { 696 sql.append( " AND " ).append( wnms[i] ).append( "=[" ).append( wnms[i] ).append( "]" ); 697 } 698 whereAnd = " AND " ; // whereNames 優先?ここを?らなければ、?期?のまま? WHERE " が使われ? 699 } 700 701 // 5.5.8.5 (2012/11/27) whereNames 対応?whereNames が登録されて?ば、AND で繋げる? 702 if( where != null && where.length() > 0 ) { 703 // sql.append( " WHERE " ).append( where ); 704 sql.append( whereAnd ).append( where ); 705 } 706 return sql.toString(); 707 } 708 709 /** 710 * names,constKeys,omitNames から、?なキー??と、属???を持っ?NamesData を作?します? 711 * 712 * @og.rev 4.1.2.1 (2008/03/17) 固定?の constVals の前後に?'" を?れる? 713 * @og.rev 5.5.1.9 (2012/04/19) asNames、orgNames、funcKeys、funcVals属?追? 714 * 715 * @param nms カラ?配? 716 * 717 * @return 属???を持ったNamesData 718 */ 719 private NamesData makeNamesData( final String[] nms ) { 720 721 NamesData namesData = new NamesData(); 722 723 // 5.5.1.9 (2012/04/19) omitNames に、asNames配?の値を設定しておきます? 724 if( asNames != null ) { 725 for( int i=0; i<asNames.length; i++ ) { 726 if( asNames[i] != null && asNames[i].length() > 0 ) { 727 omitNames = omitNames + asNames[i] + ","; 728 } 729 } 730 } 731 732 // names で?されたカラ? 733 for( int i=0; i<nms.length; i++ ) { 734 String nm = nms[i]; 735 if( nm != null && nm.length() > 0 && omitNames.indexOf( "," + nm + "," ) < 0 ) { 736 namesData.add( nm,"[" + nm + "]" ) ; 737 } 738 } 739 740 // 固定?の constKeys カラ??列を設定します? 741 if( constKeys != null && constKeys.length > 0 ) { 742 for( int j=0; j<constKeys.length; j++ ) { 743 String nm = constKeys[j]; 744 if( nm != null && nm.length() > 0 ) { 745 namesData.add( nm,"'" + constVals[j] + "'" ) ; // constVals は、シングルクオートで囲?す? 746 } 747 } 748 } 749 750 // 関数値の funcKeys カラ??列を設定します? 751 if( funcKeys != null && funcKeys.length > 0 ) { 752 for( int j=0; j<funcKeys.length; j++ ) { 753 String nm = funcKeys[j]; 754 if( nm != null && nm.length() > 0 ) { 755 namesData.add( nm, funcVals[j] ) ; // funcVals は、シングルクオートで囲?せん? 756 } 757 } 758 } 759 760 // 別名? asNames,orgNames カラ??列を設定します? 761 if( orgNames != null && orgNames.length > 0 ) { 762 for( int j=0; j<orgNames.length; j++ ) { 763 String onm = orgNames[j]; 764 if( onm != null && onm.length() > 0 ) { 765 namesData.add( onm,"[" + asNames[j] + "]" ) ; 766 } 767 } 768 } 769 770 return namesData ; 771 } 772 773 /** 774 * ???タを受け渡す為の、簡易クラスです? 775 * 更新するカラ?と値のセ?配?を管?て?す? 776 * 777 */ 778 private static class NamesData { 779 final Map<String,String> data = new LinkedHashMap<String,String>() ; 780 781 /** 782 * キーと値のセ?を追?ます? 783 * 784 * @param nm String 785 * @param val String 786 */ 787 public void add( final String nm,final String val ) { 788 data.put( nm,val ); 789 } 790 791 /** 792 * キー配?と対応する?値配?のセ?を追?ます? 793 * 794 * @param nms String[] 795 * @param vals String[] 796 */ 797 public void add( final String[] nms,final String[] vals ) { 798 if( nms != null ) { 799 for( int i=0; i<nms.length; i++ ) { 800 data.put( nms[i],vals[i] ); 801 } 802 } 803 } 804 805 /** 806 * キー配?を返します? 807 * 808 * @return String[] 809 */ 810 public String[] getNames() { 811 return data.keySet().toArray( new String[data.size()] ); 812 } 813 814 /** 815 * 値配?を返します? 816 * 817 * @return String[] 818 */ 819 public String[] getVals() { 820 return data.values().toArray( new String[data.size()] ); 821 } 822 } 823 824 /** 825 * こ?オブジェクト???表現を返します? 826 * 基本???目?使用します? 827 * 828 * @return こ?クラスの??表現 829 */ 830 @Override 831 public String toString() { 832 return org.opengion.fukurou.util.ToString.title( this.getClass().getName() ) 833 .println( "VERSION" ,VERSION ) 834 .println( "sqlType" ,sqlType ) 835 .println( "table" ,table ) 836 .println( "names" ,names ) 837 .println( "omitNames" ,omitNames ) 838 .println( "where" ,where ) 839 .println( "whereNames" ,whereNames ) 840 .println( "constKeys" ,constKeys ) 841 .println( "constVals" ,constVals ) 842 .println( "logicalDelete" ,logicalDelete ) 843 .fixForm().toString() ; 844 } 845 }