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//      private static final String CR = System.getProperty("line.separator");  // 5.1.1.0 (2009/12/01) CR 定義をAbstractTableFilterで行う。
057
058//      private static final String LAST_SQL_1 =
059//              " FROM GE51 WHERE FGJ = '1'" + CR
060//              + " AND SYSTEM_ID = ? " + CR
061//              + " AND YKNO = ? " + CR
062//              + " AND KBTEXT = '";
063//
064//      private static final String LAST_SQL_2 =
065//              "'" + CR + "ORDER BY EDNO";
066
067        /**
068         * DBTableModel処理を実行します。
069         *
070         * @og.rev 4.3.7.0 (2009/06/01) 新規追加
071         * @og.rev 5.1.0.0 (2009/11/04) TEXT ⇒ TEXT_DATA , COLUMN_NAME ⇒ CLM
072         * @og.rev 5.1.2.0 (2010/01/01) データ分割のためのSQL文の生成を廃止します。(帳票クラス内で直接分割)
073         * @og.rev 5.5.2.6 (2012/05/25) protected変数を、private化したため、getterメソッドで取得するように変更
074         *
075         * @return 処理結果のDBTableModel
076         */
077        public DBTableModel execute() {
078                DBTableModel table = getDBTableModel();         // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加
079
080                int systemIdNo  = table.getColumnNo( "SYSTEM_ID" );
081                int listIdNo    = table.getColumnNo( "LISTID" );
082                int kbtextNo    = table.getColumnNo( "KBTEXT" );
083                int clmNo               = table.getColumnNo( "CLM" );           // 5.1.0.0 (2009/11/04) COLUMN_NAME ⇒ CLM
084                int seqNo               = table.getColumnNo( "SEQ" );
085                int lengthNo    = table.getColumnNo( "USE_LENGTH" );
086                int strposNo    = table.getColumnNo( "START_POS" );
087//              int sqlTypeNo   = table.getColumnNo( "SQL_TYPE" );
088//              int sqlBodyNo   = table.getColumnNo( "SQL_BODY" );
089//              String substrb  = getValue( "SUBSTRB" );
090
091                if( systemIdNo < 0 || listIdNo < 0 || kbtextNo < 0 || clmNo < 0
092                                || seqNo < 0 || lengthNo < 0 || strposNo < 0 ) {
093//                              || sqlTypeNo < 0 || sqlBodyNo < 0
094//                              || substrb == null || substrb.length() == 0 )
095                        return table;
096                }
097
098                int seq = 0;
099                int strpos = 1;
100                String[] data = null;
101//              String[] pre = null;
102
103                String resetKey = null;
104                String preKey = null;
105//              StringBuilder sql = new StringBuilder();
106//              sql.append( "SELECT" ).append( CR ).append( " " );
107                int[] rowNo = getParameterRows();                                       // 5.5.2.6 (2012/05/25) インターフェースにgetterメソッド追加
108                for( int row = 0; row < rowNo.length; row ++ ) {
109                        data = table.getValues( rowNo[row] );
110                        resetKey = data[systemIdNo] + "__" + data[listIdNo] + "__" + data[kbtextNo];
111
112//                      if( pre != null && !(preKey.equals( resetKey ) ) ) {
113                        if( preKey != null && !(preKey.equals( resetKey ) ) ) {
114                                seq = 0;
115                                strpos = 1;
116//                              pre[sqlTypeNo] = pre[kbtextNo];
117//                              pre[sqlBodyNo] = sql.append( LAST_SQL_1 ).append( pre[sqlTypeNo] ).append(  LAST_SQL_2 ).toString();
118
119//                              sql = new StringBuilder();
120//                              sql.append( "SELECT" ).append( CR ).append( " " );
121                        }
122
123//                      if( seq > 0 ) {
124//                              sql.append( "," );
125//                      }
126
127                        seq += 10;
128                        data[seqNo] = String.valueOf( seq );
129                        data[strposNo] = String.valueOf( strpos );
130
131//                      // 5.1.0.0 (2009/11/04) TEXT ⇒ TEXT_DATA
132//                      sql.append( "RTRIM(" ).append( substrb ).append( "(TEXT_DATA," ).append( data[strposNo] )
133//                      .append( "," ).append( data[lengthNo] ).append( ")) " ).append(  data[clmNo] ).append( CR );
134
135                        strpos += Integer.valueOf( data[lengthNo] );
136
137                        preKey = resetKey;
138//                      pre = data;
139                }
140
141//              data[sqlTypeNo] = data[kbtextNo];
142//              data[sqlBodyNo] = sql.append( LAST_SQL_1 ).append( data[kbtextNo] ).append(  LAST_SQL_2 ).toString();
143
144                return table;
145        }
146}