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    }