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.table;
017
018import org.opengion.hayabusa.db.AbstractTableFilter;
019import org.opengion.hayabusa.db.DBTableModel;
020
021/**
022 * TableFilter_REPORTLAYOUT は、TableFilter インターフェースを継承した、DBTableModel 処理用の
023 * 実装クラスです。
024 *
025 * ここでは、GE52(帳票レイアウトテーブル)の変更時に、
026 *  GE52のSEQ,開始位置
027 *  (GE54のSQLの再定義) 廃止
028 * を行うための情報を生成しています。
029 *
030 * この処理を実行するには、DBTableModelのカラムとして、
031 *  SYSTEM_ID,LISTID,KBTEXT,CLM,SEQ,USE_LENGTH,START_POS
032 * が必要です。
033 *
034 * パラメータは、tableFilterタグの keys, vals にそれぞれ記述するか、BODY 部にCSS形式で記述します。
035 * 【パラメータ】
036 *  {
037 *       なし
038 *  }
039 *
040 * @og.formSample
041 * ●形式:
042 *      select SYSTEM_ID,LISTID,KBTEXT,CLM,SEQ,USE_LENGTH,START_POS from GE52
043 * 
044 *      ① <og:tableFilter classId="REPORTLAYOUT " />
045 *
046 * @og.rev 4.3.7.0 (2009/06/01) 新規作成
047 *
048 * @version  0.9.0  2000/10/17
049 * @author   Hiroki Nakamura
050 * @since    JDK1.1,
051 */
052public class TableFilter_REPORTLAYOUT extends AbstractTableFilter {
053        //* このプログラムのVERSION文字列を設定します。   {@value} */
054        private static final String VERSION = "5.5.2.6 (2012/05/25)" ;
055
056        /**
057         * DBTableModel処理を実行します。
058         *
059         * @og.rev 4.3.7.0 (2009/06/01) 新規追加
060         * @og.rev 5.1.0.0 (2009/11/04) TEXT ⇒ TEXT_DATA , COLUMN_NAME ⇒ CLM
061         * @og.rev 5.1.2.0 (2010/01/01) データ分割のためのSQL文の生成を廃止します。(帳票クラス内で直接分割)
062         * @og.rev 5.5.2.6 (2012/05/25) protected変数を、private化したため、getterメソッドで取得するように変更
063         *
064         * @return 処理結果のDBTableModel
065         */
066        public DBTableModel execute() {
067                DBTableModel table = getDBTableModel();         // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加
068
069                int systemIdNo  = table.getColumnNo( "SYSTEM_ID" );
070                int listIdNo    = table.getColumnNo( "LISTID" );
071                int kbtextNo    = table.getColumnNo( "KBTEXT" );
072                int clmNo               = table.getColumnNo( "CLM" );           // 5.1.0.0 (2009/11/04) COLUMN_NAME ⇒ CLM
073                int seqNo               = table.getColumnNo( "SEQ" );
074                int lengthNo    = table.getColumnNo( "USE_LENGTH" );
075                int strposNo    = table.getColumnNo( "START_POS" );
076 //             int sqlTypeNo   = table.getColumnNo( "SQL_TYPE" );
077 //             int sqlBodyNo   = table.getColumnNo( "SQL_BODY" );
078 //             String substrb  = getValue( "SUBSTRB" );
079
080                if( systemIdNo < 0 || listIdNo < 0 || kbtextNo < 0 || clmNo < 0
081                                || seqNo < 0 || lengthNo < 0 || strposNo < 0 ) {
082                        return table;
083                }
084
085                int seq = 0;
086                int strpos = 1;
087                String[] data = null;
088
089                String resetKey = null;
090                String preKey = null;
091                int[] rowNo = getParameterRows();                                       // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加
092                for( int row = 0; row < rowNo.length; row ++ ) {
093                        data = table.getValues( rowNo[row] );
094                        resetKey = data[systemIdNo] + "__" + data[listIdNo] + "__" + data[kbtextNo];
095
096                        if( preKey != null && !(preKey.equals( resetKey ) ) ) {
097                                seq = 0;
098                                strpos = 1;
099                        }
100
101                        seq += 10;
102                        data[seqNo] = String.valueOf( seq );
103                        data[strposNo] = String.valueOf( strpos );
104
105                        // 5.1.0.0 (2009/11/04) TEXT ⇒ TEXT_DATA
106                        strpos += Integer.valueOf( data[lengthNo] );
107
108                        preKey = resetKey;
109                }
110
111                return table;
112        }
113}