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.HybsSystemException;
019    import org.opengion.hayabusa.db.Query;
020    
021    import static org.opengion.fukurou.util.StringUtil.nval ;
022    
023    import java.util.ArrayList;
024    import 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     *    例ï¼?
067     *        <table><tr><og:input name="PN" value="{@PN}" /></tr>
068     *            <tr><og:input name="CD" value="{@CD}" /></tr>
069     *        </table>
070     *
071     *    例ï¼?
072     *        <table><tr><og:input name="PN" value="{@PN}" >部品å?力フィールãƒ?lt;/og:input></tr>
073     *            <tr><og:input name="CD" value="{@CD}" >コードフィールãƒ?lt;/og:input></tr>
074     *        </table>
075     *
076     *        BODY 部åˆ??、無視されますã?コメント等に使用できますã?
077     *        HTMLファイルには、コメント部åˆ??出力されませんã€?
078     *
079     * @og.group ?¤?¢登録
080     *
081     * @version  4.0
082     * @author   Kazuhiko Hasegawa
083     * @since    JDK5.0,
084     */
085    public 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    }