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.plugin.develop;
017
018import java.util.List;
019import java.util.ArrayList;
020import java.util.Map;
021
022import org.opengion.hayabusa.develop.AbstractJspCreate;
023import org.opengion.hayabusa.develop.JspConvertEntity;
024import org.opengion.fukurou.xml.OGElement;
025import org.opengion.fukurou.xml.OGAttributes;
026
027/**
028 * entry.jspの<og:tableUpdateParam>タグを作成します。
029 * tableUpdateParam は、tableUpdate タグのBODY部に記述されます。
030 * tableUpdateParam で書き換えが発生するのは、対象テーブルと、omitNames属性です。
031 * where条件の書き換えは行いません。(雛形読み込み時のまま使用します。)
032 * テーブルの書き間違いで、異なるUNIQ番号の更新を避ける意味合いで、
033 * UNIQ=[UNIQ]以外のキーを条件に入れておくと、より安全です。
034 *
035 * ●使用例
036 *  <og:tableUpdate command="{@command}" queryType="JDBCTableUpdate" debug="false">
037 *      <og:tableUpdateParam
038 *          sqlType   = "{@sqlType}"
039 *          table     = "GF02"
040 *          where     = "UNIQ=[UNIQ] and DYSET=[DYSET]"
041 *          omitNames = "SYSTEM_ID,TBLSYU,TABLESPACE_NAME"
042 *      />
043 *  </og:tableUpdate>
044 *
045 * @og.rev 5.6.1.2 (2013/02/22) 文字列連結から、XML処理するように変更します。
046 * @author Takeshi.Takada
047 *
048 */
049public class JspCreate_TABLE_UPDATE extends AbstractJspCreate {
050        /** このプログラムのVERSION文字列を設定します。   {@value} */
051        private static final String VERSION = "6.3.9.1 (2015/11/27)" ;
052
053        // 6.3.9.1 (2015/11/27) Variables should start with a lowercase character(PMD)
054        private List<JspConvertEntity> resultRows ;
055        private boolean isNULL ;
056
057        /**
058         * コンストラクター
059         *
060         * インスタンス構築時に、タグ名(key)とファイル名(names)を指定します。
061         *
062         * @og.rev 6.3.9.1 (2015/11/27) コンストラクタを用意して、KEY,NAME をセットするように変更します。
063         */
064        public JspCreate_TABLE_UPDATE() {
065                super( ":tableUpdateParam" , "entry" );
066        }
067
068        /**
069         * 初期化メソッド
070         *
071         * 内部で使用する JspConvertEntityのリストのマップを受け取り、初期化を行います。
072         *
073         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。
074         * @og.rev 5.6.1.2 (2013/02/22) 対象ファイルを、result だけから、update も含めるように変更。
075         *
076         * @param       master  JspConvertEntityのリストのマップ
077         */
078        @Override
079        protected void init( final Map<String,List<JspConvertEntity>> master ) {
080                resultRows      = master.get( "RESULT" );                                               // 6.3.9.1 (2015/11/27)
081                isNULL = !isNotEmpty( resultRows );                                                     // 6.3.9.1 (2015/11/27)
082        }
083
084        /**
085         * JSPに出力するタグの内容を作成します。
086         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
087         *
088         * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。
089         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。
090         *
091         * @param ele OGElementエレメントオブジェクト
092         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
093         *
094         * @return      変換された文字列
095         * @og.rtnNotNull
096         * @throws Throwable 変換時のエラー
097         */
098        @Override
099        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
100                if( isNULL ) { return ""; }                                                             // 6.3.9.1 (2015/11/27)
101
102                String table = null;
103                final List<String> omitNames = new ArrayList<>();
104                for( final JspConvertEntity column : resultRows ) {     // 6.3.9.1 (2015/11/27)
105                        // 非表示は、GF92の属性(Remarks)に、何もセットされていないカラムの事
106                        final String remks = column.getRemarks();
107                        final String astbl = column.getAsTableName();
108
109                        // DISP で、別名がA1以外の場合、データ登録しないので、omit カラムになる。
110                        if( "DISP".equalsIgnoreCase( remks ) && !"A1".equalsIgnoreCase( astbl ) ) {
111                                omitNames.add( column.getColumnName() );
112                        }
113
114                        // 最初の1回だけ取り込む
115                        if( table == null && "A1".equalsIgnoreCase( astbl ) ) {
116                                table = column.getTableName();
117                        }
118                }
119
120                final OGAttributes attri = ele.getOGAttributes();               // OGElementの内部オブジェクトなので、副作用あり
121                attri.setUseCR( true );
122                attri.setVal( "table" , table );
123
124                if( ! omitNames.isEmpty() ) {
125                        attri.setVal( "omitNames" , chainChar( omitNames ,",") );               // あれば更新、なければ追加
126                }
127
128                return ele.getText( 1 );
129        }
130}