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 org.opengion.hayabusa.common.HybsSystemException; 019import org.opengion.hayabusa.db.Query; 020 021import static org.opengion.fukurou.util.StringUtil.nval ; 022 023import java.util.ArrayList; 024import java.util.Enumeration; 025 026/** 027 * 検索結果の DBTableModel を使用せず、直接エントリーデータを登録するタグです。 028 * 029 * このオブジェクトに、 dbid を与えることにより、dbid に対応した 030 * Queryオブジェクト(のサブクラスのオブジェクト)が作成されます。 031 * 032 * ※ このタグは、Transaction タグの対象です。 033 * 034 * @og.formSample 035 * ●形式: 036 * <og:entryQuery 037 * queryType = "JDBCKeyEntry" 038 * command = "{@command}" > 039 * { call DYNAMIC_PKG.DYNAMIC_TEST( ?,?,?,? ) } 040 * </og:query> 041 * 042 * queryType : Queryオブジェクトを作成する時のキー(オプション) 043 * QueryFactory参照 044 * command : 処理コマンド( NEWのみ )(オプション) 045 * skipRowCount : データの読み始めの初期値を指定(オプション) 046 * maxRowCount : データの最大読み込み件数を指定(オプション) 047 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 048 * 049 * ●Tag定義: 050 * <og:entryQuery 051 * queryType ○【TAG】Query を発行する為のクラスIDを指定します({@og.doc03Link queryType 初期値:JDBCKeyEntry})(必須)。 052 * command 【TAG】コマンド(NEW,RENEW)をセットします(PlsqlUpdateTag,UpdateTag の場合は、ENTRY) 053 * scope 【TAG】キャッシュする場合のスコープ[request/page/session/applicaton]を指定します(初期値:session) 054 * maxRowCount 【TAG】(通常は使いません)データの最大読み込み件数を指定します (初期値:DB_MAX_ROW_COUNT[=1000]) 055 * skipRowCount 【TAG】(通常は使いません)データの読み始めの初期値を指定します 056 * displayMsg 【TAG】検索結果を画面上に表示するメッセージリソースIDを指定します (初期値:VIEW_DISPLAY_MSG[=]) 057 * notfoundMsg 【TAG】検索結果がゼロ件の場合に表示するメッセージリソースIDを指定します(初期値:MSG0077[対象データはありませんでした]) 058 * names 【TAG】PL/SQLを利用する場合の引数にセットすべき データの名称をCSV形式で複数指定します 059 * tableId 【TAG】(通常は使いません)結果のDBTableModelを、sessionに登録するときのキーを指定します 060 * dbid 【TAG】(通常は使いません)Queryオブジェクトを作成する時のDB接続IDを指定します 061 * debug 【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false) 062 * > ... Body ... 063 * </og:entryQuery> 064 * 065 * ●使用例 066 * 例1) 067 * <table><tr><og:input name="PN" value="{@PN}" /></tr> 068 * <tr><og:input name="CD" value="{@CD}" /></tr> 069 * </table> 070 * 071 * 例2) 072 * <table><tr><og:input name="PN" value="{@PN}" >部品入力フィールド</og:input></tr> 073 * <tr><og:input name="CD" value="{@CD}" >コードフィールド</og:input></tr> 074 * </table> 075 * 076 * BODY 部分は、無視されます。コメント等に使用できます。 077 * HTMLファイルには、コメント部分は出力されません。 078 * 079 * @og.group DB登録 080 * 081 * @version 4.0 082 * @author Kazuhiko Hasegawa 083 * @since JDK5.0, 084 */ 085public class EntryQueryTag extends QueryTag { 086 //* このプログラムのVERSION文字列を設定します。 {@value} */ 087 private static final String VERSION = "4.0.0.0 (2005/01/31)" ; 088 089 private static final long serialVersionUID = 400020050131L ; 090 091 /** 092 * Query を実行します。 093 * 094 * @og.rev 3.5.4.2 (2003/12/15) JDBCKeyEntryQuery クラス名変更(⇒ Query_JDBCKeyEntry) 095 * @og.rev 4.0.0.0 (2005/01/31) execute( String[] ,String[] )を標準メソッドに格上げします。 096 * 097 * @param query オブジェクト 098 */ 099 @Override 100 protected void execute( final Query query ) { 101 String[] nameArray = getRequestKeys(); 102 String[] values = getRequest( nameArray ); 103 try { 104 query.execute( nameArray,values ); // 4.0.0 (2005/01/31) 105 errCode = query.getErrorCode(); 106 errMessage = query.getErrorMessage(); 107 query.commit(); 108 } 109 catch( HybsSystemException ex ) { 110 query.rollback(); 111 query.realClose(); 112 throw ex; 113 } 114 finally { 115 if( query != null ) { query.close(); } 116 } 117 } 118 119 /** 120 * リクエスト情報のキー配列データを取得します。 121 * 122 * @og.rev 3.1.0.0 (2003/03/20) Vector を使用している箇所で、非同期でも構わない箇所を、ArrayList に置換え。 123 * 124 * @return そのリクエストのキー配列情報 125 */ 126 protected String[] getRequestKeys() { 127 ArrayList<String> list = new ArrayList<String>(); 128 129 Enumeration<?> enume = getParameterNames(); // 4.3.3.6 (2008/11/15) Generics警告対応 130 131 while( enume.hasMoreElements() ) { 132 String key = (String)(enume.nextElement()); 133 list.add( key ); 134 } 135 136 String[] rtn = list.toArray( new String[list.size()] ); 137 138 return rtn; 139 } 140 141 /** 142 * 【TAG】Query を発行する為のクラスIDを指定します({@og.doc03Link queryType 初期値:JDBCKeyEntry})。 143 * 144 * @og.tag 145 * 引数指定のINSERT/UPDATE文を実行する場合の、queryType 属性を使用します。 146 * このタグでは、execute( String[] , String[] )を実行します。 147 * 代表的なクラスとして、"JDBCKeyEntry" が標準で用意されています。 148 * 149 * タグにより使用できる/出来ないがありますが、これは、org.opengion.hayabusa.db 150 * 以下の Query_**** クラスの **** を与えます。 151 * これらは、Query インターフェースを継承したサブクラスです。 152 * {@og.doc03Link queryType Query_**** クラス} 153 * 154 * @og.rev 3.5.4.2 (2003/12/15) JavaDocコメント用にメソッド追加。 155 * 156 * @param id Query を発行する為の実クラス ID 157 * @see org.opengion.hayabusa.db.Query Queryのサブクラス 158 * @see org.opengion.hayabusa.db.Query#execute( String[] , String[] ) 159 */ 160 @Override 161 public void setQueryType( final String id ) { 162 super.setQueryType( nval( id,"JDBCKeyEntry" ) ); 163 } 164}