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.hayabusa.report2;
017
018import org.opengion.fukurou.system.OgRuntimeException ;         // 6.4.2.0 (2016/01/29)
019import java.io.File;
020import java.util.Arrays;
021
022import org.opengion.fukurou.db.DBFunctionName;
023import org.opengion.fukurou.db.DBUtil;
024import org.opengion.fukurou.mail.MailTX;
025import org.opengion.fukurou.db.ApplicationInfo;
026import org.opengion.fukurou.system.DateSet;                                             // 6.4.2.0 (2016/01/29)
027import org.opengion.fukurou.system.LogWriter;
028import org.opengion.fukurou.util.StringUtil;
029import org.opengion.fukurou.util.UnicodeCorrecter;                      // 5.9.3.3 (2015/12/26) package を、mail → util に移動のため
030import org.opengion.hayabusa.common.HybsSystem;
031import org.opengion.hayabusa.db.DBTableModel;
032import org.opengion.hayabusa.db.DBTableModelUtil;
033import org.opengion.hayabusa.resource.ResourceFactory;
034import org.opengion.hayabusa.resource.ResourceManager;
035import static org.opengion.fukurou.system.HybsConst.CR ;                // 6.1.0.0 (2014/12/26)
036
037/**
038 * DBからキューを作成するためのクラスです。
039 * キューはGE5xテーブルから作成されます。
040 *
041 * キュー生成時点(処理スレッドにスタックした時点)では、帳票データのテーブルモデルは作成されません。
042 * 帳票データは、各スレッドからset()メソッドを呼び出したタイミングで生成されます。
043 *
044 * 処理開始及び、完了のステータスは、GE50の完成フラグに更新されます。
045 * また、エラー発生時のメッセージは、GE56に更新されます。
046 *
047 * @og.group 帳票システム
048 *
049 * @version  4.0
050 * @author   Hiroki.Nakamura
051 * @since    JDK1.6
052 */
053public final class QueueManager_DB implements QueueManager {
054
055        /** コネクションにアプリケーション情報を追記するかどうか指定 */
056        private static final boolean USE_DB_APPLICATION_INFO  = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ;
057
058        private static final String DBID = HybsSystem.sys( "RESOURCE_DBID" );           // 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対応
059
060        // 4.3.7.0 (2009/06/01) HSQLDB対応
061        // 5.1.4.0 (2010/03/01) データベース名 でなく、DBID名で検索するように変更します。
062        private static final String CON = DBFunctionName.getFunctionName( "CON", null );
063
064//      // 5.2.0.0 (2010/09/01) Ver4互換モード対応
065//      // 6.9.5.0 (2018/04/23) VER4_COMPATIBLE_MODE 廃止
066//      private static final String OUT_FILE = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "OUTFILE" : "OUT_FILE";
067//      private static final String OUT_DIR = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "OUTDIR" : "OUT_DIR";
068
069        // 4.3.3.6 (2008/11/15) マルチサーバ対応追加(GE12から処理対象デーモングループ取得)
070        // 4.3.7.0 (2009/06/01) HSQLDB対応
071        // 5.2.0.0 (2010/09/01) Ver4互換モード対応
072        // 5.4.2.0 (2011/12/26) PRTID,PRGDIR,PRGFILE取得
073        // 5.9.2.2 (2015/11/20) GROUPID追加
074        // 6.9.5.0 (2018/04/23) VER4_COMPATIBLE_MODE 廃止
075        // 5.10.0.0 (2018/06/08) FGNOML(メール不要フラグ)を追加
076        private static final String SQL_SELECT_GE50 =
077//              "SELECT A.SYSTEM_ID, A.YKNO, A.LISTID, A."+OUT_DIR+", A."+OUT_FILE+", A.PDF_PASSWD"
078                "SELECT A.SYSTEM_ID, A.YKNO, A.LISTID, A.OUT_DIR, A.OUT_FILE, A.PDF_PASSWD"
079                + ", B.LANG, B.FGRUN, B.DMN_GRP "
080                + ", C.MODELDIR, C.MODELFILE, D.PRTNM, C.FGLOCAL, C.FGCUT, C.BSQL, C.HSQL, C.FSQL "
081                + " ,B.PRTID, B.PRGDIR, B.PRGFILE "
082                + " ,A.GROUPID "                                                        // 5.9.2.2 (2015/11/20)
083//              + " ,C.FGNOML "                                                         // 5.10.0.0 (2018/06/08)
084                + " , '0' as FGNOML "                                           // 5.10.0.0 (2018/06/08) , 6.9.8.1 (2018/06/11) 互換性の関係で、とりあえず、'0' を設定
085                + "FROM GE50 A "
086                + "INNER JOIN GE53 B "
087                + "ON A.SYSTEM_ID = B.SYSTEM_ID AND A.JOKEN = B.JOKEN "
088                + "INNER JOIN GE54 C "
089                + "ON A.SYSTEM_ID = C.SYSTEM_ID AND A.LISTID = C.LISTID "
090                + "LEFT OUTER JOIN GE55 D "
091                + "ON B.SYSTEM_ID = D.SYSTEM_ID AND B.PRTID = D.PRTID "
092                + "WHERE A.FGKAN='1' "
093                + "AND EXISTS ( SELECT 'X' FROM GE12 E "
094                +                               "WHERE  E.FGJ                           ='1' "
095                +                               "AND            E.SYSTEM_ID     = '"
096                +                               HybsSystem.sys( "SYSTEM_ID" )
097                +                               "' "
098                +                               "AND            E.CONTXT_PATH   = '"
099                +                               HybsSystem.sys( "HOST_URL" )
100                +                               "' "
101                +                               "AND            E.PARAM_ID              LIKE 'REPORT2_HANDLE_DAEMON_%' "
102                +                               "AND            E.PARAM                 = 'RUN_'" + CON + "A.SYSTEM_ID" + CON + "'_'" + CON + "B.DMN_GRP"
103                +                       ") "
104                + "ORDER BY "
105                + HybsSystem.sys( "REPORT_DAEMON_ORDER_BY" );
106
107        // 5.1.2.0 (2010/01/01) ページ数、データ数をGE50に更新する。
108        private static final String SQL_UPDATE_GE50 =
109                "UPDATE GE50 SET FGKAN = ?, DMN_NAME = ?, DMN_HOST = ?, SUDATA = ?, SUPAGE = ?, DYUPD = ? WHERE SYSTEM_ID = ? AND YKNO = ?";
110
111        private static final String SQL_INSERT_GE56 =
112                "INSERT INTO GE56 ( FGJ, SYSTEM_ID, YKNO, ERRMSG, DYSET, DYUPD, USRSET, USRUPD, PGUPD ) "
113                + " VALUES ( '1', ?, ? ,? ,? ,? ,? ,? ,? )" ;
114
115        private static final int STATUS_COMPLETE        = 2;
116        private static final int STATUS_EXECUTE         = 3;
117        private static final int STATUS_ERROR           = 8;
118
119        private static QueueManager manager = new QueueManager_DB();
120
121        /** アプリケーション情報 */
122        private static final ApplicationInfo APP_INFO;          // 6.4.1.1 (2016/01/16) appInfo → APP_INFO refactoring
123        static {
124                if( USE_DB_APPLICATION_INFO ) {
125                        APP_INFO = new ApplicationInfo();
126                        // ユーザーID,IPアドレス,ホスト名
127                        APP_INFO.setClientInfo( "ReportDaemon", HybsSystem.HOST_ADRS, HybsSystem.HOST_NAME );
128                        // 画面ID,操作,プログラムID
129                        APP_INFO.setModuleInfo( "ReportDaemon", "QueueManager", "QueueManager" );
130                }
131                else {
132                        APP_INFO = null;
133                }
134        }
135
136        /**
137         * インスタンスの生成を禁止します。
138         */
139        private QueueManager_DB() {}
140
141        /**
142         * インスタンスを返します。
143         *
144         * @return      帳票処理キューの管理マネージャ
145         */
146        public static QueueManager getInstance() {
147                return manager;
148        }
149
150        /**
151         * 帳票処理キューを作成します。
152         *
153         * @og.rev 4.3.0.0 (2008/07/15) スレッドIDにシステムIDを付加します。
154         * @og.rev 5.1.2.0 (2010/01/01) HSQL,FSQL,BSQLのセットを廃止します。(このクラス内でデータを直接分割)
155         * @og.rev 5.4.3.0 (2011/12/26) PRTIDの取得
156         * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対策
157         * @og.rev 6.3.9.0 (2015/11/06) Use block level rather than method level synchronization.(PMD)
158         * @og.rev 5.9.2.2 (2015/11/20) GrpId,DmnGrp 追加
159         * @og.rev 5.10.0.0 (2018/06/08) FGNOML対応
160         */
161        public void create() {
162                // キューをスタックするまでの例外は、ScheduleTagでcatchされデーモンがスリープする。
163                final String[][] ge50vals = DBUtil.dbExecute( SQL_SELECT_GE50, new String[0], APP_INFO, DBID ); // 5.5.5.1 (2012/08/07)
164
165                // 6.3.9.0 (2015/11/06) 元々のsynchronizedの必要性が分からないが、帳票なのでとりあえず入れておきます。
166                synchronized( ge50vals ) {
167                        for( int i=0; i<ge50vals.length; i++ ) {
168                                final ExecQueue queue = new ExecQueue();
169                                queue.setSystemId(      ge50vals[i][0] );
170                                queue.setYkno(          ge50vals[i][1] );
171                                queue.setListId(        ge50vals[i][2] );
172                                queue.setOutputName( new File( ge50vals[i][3] ).getAbsolutePath() , ge50vals[i][4] , ge50vals[i][7] , ge50vals[i][1] ); // 4.3.0.0 (2008/07/18) 要求番号を出力ファイル名に利用
173                                queue.setPdfPasswd( ge50vals[i][5] );
174                                queue.setLang(          ge50vals[i][6] );
175                                queue.setOutputType( ge50vals[i][7] );
176                                queue.setThreadId(      ge50vals[i][0] + "_" + StringUtil.nval( ge50vals[i][8] , "_DEFALUT_" ) ); // 4.3.0.0 (2008/07/15)
177                                queue.setTemplateName( new File( ge50vals[i][9] ).getAbsolutePath() + File.separator + ge50vals[i][10] );
178                                queue.setPrinterName( ge50vals[i][11] );
179                                queue.setFglocal(       "1".equals( ge50vals[i][12] ) );
180                                queue.setFgcut(         "1".equals( ge50vals[i][13] ) );
181
182                                queue.setPrtId(         ge50vals[i][17] );              // 5.4.3.0
183                                queue.setPrgDir(        ge50vals[i][18] );              // 5.4.3.0
184                                queue.setPrgFile(       ge50vals[i][19] );              // 5.4.3.0
185
186                                queue.setGrpId(         ge50vals[i][20] );              // 5.9.2.2 (2015/11/20)
187                                queue.setDmnGrp(        ge50vals[i][8]  );              // 5.9.2.2 (2015/11/20)
188                                queue.setFgnoml(        ge50vals[i][21] );              // 5.10.0.0 (2018/06/08)
189
190                                queue.setManager( this );
191
192                                ExecThreadManager.insertQueue( queue );
193                        }
194                }
195        }
196
197        /**
198         * 帳票処理データをキューにセットします。
199         *
200         * @og.rev 5.1.2.0 (2010/01/01) HSQL,FSQL,BSQLのセットを廃止します。(このクラス内でデータを直接分割)
201         *
202         * @param       queue   ExecQueueオブジェクト
203         */
204        public void set( final ExecQueue queue ) {
205                final String systemId   = queue.getSystemId();
206                final String lang               = queue.getLang();
207                final String listId             = queue.getListId();
208                final String ykno               = queue.getYkno();
209
210                ResourceManager resource = null;
211                if( queue.isFglocal() ) {
212                        resource = ResourceFactory.newInstance( systemId, lang, false );
213                }
214                else {
215                        resource = ResourceFactory.newInstance( lang );
216                }
217
218                // ヘッダー情報の取得
219                final DBTableModel header = new DBTableModelCreator( systemId, listId, ykno, "H", resource ).getTable();
220
221                if( header != null && header.getRowCount() > 0 ) {
222                        queue.setHeader( header );
223                }
224
225                // フッター情報の取得
226                final DBTableModel footer = new DBTableModelCreator( systemId, listId, ykno, "F", resource ).getTable();
227                if( footer != null && footer.getRowCount() > 0 ) {
228                        queue.setFooter( footer );
229                }
230
231                // ボディー情報の取得
232                final DBTableModel body = new DBTableModelCreator( systemId, listId, ykno, "B", resource ).getTable();
233                // レイアウトテーブルがないと固定長を分割するSQL文が設定されず、DBTableModelがnullになる
234                if( body == null ) {
235                        queue.addMsg( "[ERROR] DBTableModel doesn't exists! maybe Layout-Table(GE52) is not configured..." + CR );
236                        queue.setError();
237                        throw new OgRuntimeException();
238                }
239                if( body.getRowCount() <= 0 ) {
240                        queue.addMsg( "[ERROR] Database Body row count is Zero." + ykno + CR );
241                        queue.setError();
242                        throw new OgRuntimeException();
243                }
244                if( body.isOverflow() ) {
245                        queue.addMsg( "[ERROR]Database is Overflow. [" + body.getRowCount() + "]" + CR );
246                        queue.addMsg( "[ERROR]Check SystemParameter Data in DB_MAX_ROW_COUNT Overflow" + CR  );
247                        queue.setError();
248                        throw new OgRuntimeException();
249                }
250                queue.setBody( body );
251        }
252
253        /**
254         * キューを実行中の状態に更新します。
255         *
256         * @param       queue   ExecQueueオブジェクト
257         */
258        public void execute( final ExecQueue queue ) {
259                status( queue, STATUS_EXECUTE );
260        }
261
262        /**
263         * キューを完了済の状態に更新します。
264         *
265         * @param       queue   ExecQueueオブジェクト
266         */
267        public void complete( final ExecQueue queue ) {
268                status( queue, STATUS_COMPLETE );
269        }
270
271        /**
272         * キューをエラーの状態に更新します。
273         *
274         * @param       queue   ExecQueueオブジェクト
275         */
276        public void error( final ExecQueue queue ) {
277                status( queue, STATUS_ERROR );
278                insertErrorMsg( queue );
279        }
280
281        /**
282         * GE50の状況Cを更新します。
283         *
284         * @og.rev 4.2.4.1 (2008/07/09) 更新日時をセット
285         * @og.rev 5.1.2.0 (2010/01/01) 行数、ページ数も更新する
286         * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対策
287         * @og.rev 6.4.2.0 (2016/01/29) DateSet.getDate( String ) を利用するように修正します。
288         *
289         * @param       queue   ExecQueueオブジェクト
290         * @param       status  状況C
291         */
292        private void status( final ExecQueue queue, final int status ) {
293
294                final String dyupd = DateSet.getDate( "yyyyMMddHHmmss" ) ;                      // 6.4.2.0 (2016/01/29)
295
296                final String[] args
297                = new String[]{ String.valueOf( status ), queue.getThreadId(), HybsSystem.sys( "HOST_NAME" )
298                                , String.valueOf( queue.getExecRowCnt() ), String.valueOf( queue.getExecPagesCnt() )
299                                , dyupd , queue.getSystemId(), queue.getYkno() };
300
301                DBUtil.dbExecute( SQL_UPDATE_GE50, args, APP_INFO, DBID );      // 5.5.5.1 (2012/08/07)
302        }
303
304        /**
305         * GE56にエラーメッセージを出力します。
306         *
307         * @og.rev 4.4.0.1 (2009/08/08) エラーメッセージ機能追加
308         * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対策
309         * @og.rev 6.4.2.0 (2016/01/29) DateSet.getDate( String ) を利用するように修正します。
310         * @og.rev 5.10.0.0 (2018/06/08) メール送信条件を追加
311         * @og.rev 6.9.8.1 (2018/06/11) 帳票エラーメールの改修(メール不要フラグ=trueで不要、falseが必要)
312         *
313         * @param       queue   ExecQueueオブジェクト
314         */
315        private void insertErrorMsg( final ExecQueue queue ) {
316                String errmsg = queue.getMsg();
317                if( errmsg.length() > 1300 ) {
318                        errmsg = errmsg.substring( errmsg.length() - 1300, errmsg.length() );
319                }
320
321                final String dyset = DateSet.getDate( "yyyyMMddHHmmss" ) ;                      // 6.4.2.0 (2016/01/29)
322
323                final String[] args
324                = new String[]{ queue.getSystemId(), queue.getYkno(), errmsg
325                                , dyset, dyset, "UNKNOWN", "UNKNOWN", "UNKNOWN" };
326
327                DBUtil.dbExecute( SQL_INSERT_GE56, args, APP_INFO, DBID );      // 5.5.5.1 (2012/08/07)
328
329//              sendMail( queue, errmsg ); // 4.4.0.1 (2009/08/08)
330                // 5.10.0.0 (2018/06/08) メール送信条件を追加
331//              if(!"1".equals(queue.getFgnoml())){
332                if( ! queue.isFgnoml() ) {              // 6.9.8.1 (2018/06/11)
333                        sendMail( queue, errmsg );      // 4.4.0.1 (2009/08/08)
334                }
335        }
336
337        /**
338         * エラー情報のメール送信を行います。
339         * エラーメールは、システムパラメータ の COMMON_MAIL_SERVER(メールサーバー)と
340         * ERROR_MAIL_FROM_USER(エラーメール発信元)と、ERROR_MAIL_TO_USERS(エラーメール受信者)
341         * がすべて設定されている場合に、送信されます。
342         *
343         * @og.rev 4.4.0.1 (2009/08/08) 追加
344         * @og.rev 5.7.0.4 (2013/11/29) listIdの絞込み
345         *
346         * @param       queue           ExecQueueオブジェクト
347         * @param       inErrMsg        エラーメッセージ
348         */
349        private void sendMail( final ExecQueue queue, final String inErrMsg ) {
350
351                final String   host = HybsSystem.sys( "COMMON_MAIL_SERVER" );
352                final String   from = HybsSystem.sys( "ERROR_MAIL_FROM_USER" );
353                final String[] to = StringUtil.csv2Array( HybsSystem.sys( "ERROR_MAIL_TO_USERS" ) );
354                final String   match_txt = HybsSystem.sys( "REPORT_ERRMAIL_REGEX" ); // 5.7.0.4 (2013/11/29) 
355                if( host != null && from != null && to.length > 0 ) {
356                        if( match_txt == null || match_txt.isEmpty() 
357                                        || queue.getListId() == null || queue.getListId().isEmpty()
358                                        || queue.getListId().matches( match_txt )){     // 5.7.0.4 (2013/11/29)
359                                // 5.7.0.4 (2013/11/29) listid追加
360                                final String subject = "SYSTEM_ID=[" + queue.getSystemId() + "] , YKNO=[" + queue.getYkno() + "] , "
361                                                           + "THREAD_ID=[" + queue.getThreadId() + "] , DMN_HOST=[" + HybsSystem.HOST_NAME + "]" 
362                                                           + "LISTID=["+ queue.getListId() + "]";
363                                try {
364                                        final MailTX tx = new MailTX( host );
365                                        tx.setFrom( from );
366                                        tx.setTo( to );
367                                        tx.setSubject( "帳票エラー:" + subject );
368                                        tx.setMessage( inErrMsg );
369                                        tx.sendmail();
370                                }
371                                catch( final Throwable ex ) {
372                                        final String errMsg = "エラー時メール送信に失敗しました。" + CR
373                                                                + " SUBJECT:" + subject                                 + CR
374                                                                + " HOST:" + host                                               + CR
375                                                                + " FROM:" + from                                               + CR
376                                                                + " TO:"   + Arrays.toString( to )              + CR
377                                                                + ex.getMessage();              // 5.1.8.0 (2010/07/01) errMsg 修正
378                                        LogWriter.log( errMsg );
379                                        LogWriter.log( ex );
380                                }
381                        }
382                }
383        }
384
385        /**
386         * 帳票明細データを帳票レイアウトテーブルに従って分割し、その結果をDBTableModelとして
387         * 生成します。
388         * データの分割は、バイト数ベースで行われるため、エンコードを正しく指定する必要があります。
389         * エンコード指定は、システムリソースのDB_ENCODEで指定します。
390         *
391         * レイアウトテーブルが存在しない場合、又は、帳票データが存在しない場合、DBTableModelは
392         * nullで返されます。
393         *
394         * @og.rev 6.9.0.2 (2018/02/13) GE51の検索順(order by)を追加します。
395         */
396        public static final class DBTableModelCreator {
397//              // 6.9.5.0 (2018/04/23) VER4_COMPATIBLE_MODE 廃止
398//              // 5.2.0.0 (2010/09/01) Ver4互換モード対応
399//              private static final String CLM = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "COLUMN_NAME" : "CLM";
400//              private static final String TEXT_DATA = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "TEXT" : "TEXT_DATA";
401
402                // 5.2.0.0 (2010/09/01) Ver4互換モード対応
403                // 5.4.4.3 (2012/02/09) FGUSE条件追加対応
404                // 6.9.5.0 (2018/04/23) VER4_COMPATIBLE_MODE 廃止
405                private static final String SQL_SELECT_GE52 =
406//                      " select " + CLM + ", START_POS, USE_LENGTH"
407                        " select CLM, START_POS, USE_LENGTH"
408                        + " from GE52"
409                        + " where SYSTEM_ID = ?"
410                        + " and LISTID = ?"
411                        + " and KBTEXT = ?"
412                        + " and FGJ = '1'"
413                        + " and FGUSE = '1'" // 5.4.4.3
414                        + " order by SEQ";
415
416                // 5.2.0.0 (2010/09/01) Ver4互換モード対応
417                // 6.9.0.2 (2018/02/13) GE51の検索順(order by)を追加します。
418                // 6.9.5.0 (2018/04/23) VER4_COMPATIBLE_MODE 廃止
419                private static final String SQL_SELECT_GE51 =
420//                      " select " + TEXT_DATA
421                        " select TEXT_DATA"
422                        + " from GE51"
423                        + " where SYSTEM_ID = ?"
424                        + " and YKNO = ?"
425                        + " and KBTEXT = ?"
426                        + " and FGJ = '1'"
427                        + " order by SYSTEM_ID,YKNO,EDNO" ;                             // 6.9.0.2 (2018/02/13)
428
429                private static final String ENCODE = HybsSystem.sys( "DB_ENCODE" );
430
431                private final String systemId;
432                private final String listId;
433                private final String ykno;
434                private final String kbtext;
435                private final ResourceManager resource;
436
437                private DBTableModel table      ;
438
439                /**
440                 * コンストラクタです。
441                 *
442                 * @param sid システムID
443                 * @param lid 帳票ID
444                 * @param yk 要求NO
445                 * @param kt テキスト区分(H:ヘッダー F:フッター B:ボディー)
446                 * @param res リソースマネージャー
447                 */
448                public DBTableModelCreator( final String sid, final String lid, final String yk, final String kt, final ResourceManager res ) {
449                        systemId        = sid;
450                        listId          = lid;
451                        ykno            = yk;
452                        kbtext          = kt;
453                        resource        = res;
454                        create();
455                }
456
457                /**
458                 * 帳票データをレイアウト定義に従い分割します。
459                 *
460                 * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付け忘れ対策
461                 * @og.rev 5.9.3.1 (2015/12/18) SJIS-UTF変換時の波ダッシュ問題対応
462                 */
463                private void create() {
464                        final String[] ge52Where = new String[] { systemId, listId, kbtext } ;
465                        final String[][] ge52Vals = DBUtil.dbExecute( SQL_SELECT_GE52, ge52Where, APP_INFO, DBID );     // 5.5.5.1 (2012/08/07)
466                        if( ge52Vals == null || ge52Vals.length == 0 ) {
467                                return;
468                        }
469
470                        final String[] ge51Where = new String[] { systemId, ykno, kbtext } ;
471                        final String[][] ge51Vals = DBUtil.dbExecute( SQL_SELECT_GE51, ge51Where, APP_INFO, DBID );     // 5.5.5.1 (2012/08/07)
472                        if( ge51Vals == null || ge51Vals.length == 0 ) {
473                                return;
474                        }
475
476                        String[] clms = new String[ge52Vals.length];
477                        for( int i=0; i<ge52Vals.length; i++ ) {
478                                clms[i] = ge52Vals[i][0];
479                        }
480
481                        String[][] vals = new String[ge51Vals.length][ge52Vals.length];
482                        for( int i=0; i<ge51Vals.length; i++ ) {
483                                final byte[] bytes = StringUtil.makeByte( UnicodeCorrecter.correctToCP932( ge51Vals[i][0], ENCODE ), ENCODE ); // 5.9.3.1 (2015/12/18)
484                                for( int j=0; j<ge52Vals.length; j++ ) {
485                                        final int strpos = Integer.parseInt( ge52Vals[j][1] ) - 1;      // 6.0.2.4 (2014/10/17) メソッド間違い
486                                        int len = Integer.parseInt( ge52Vals[j][2] );                   // 6.0.2.4 (2014/10/17) メソッド間違い
487                                        if( strpos >= bytes.length ) {
488                                                vals[i][j] = "";
489                                        }
490                                        else {
491                                                if( strpos + len > bytes.length ) {
492                                                        len = bytes.length - strpos;
493                                                }
494                                                vals[i][j] = StringUtil.rTrim( StringUtil.makeString( bytes, strpos, len, ENCODE ) );
495                                        }
496                                }
497                        }
498                        table = DBTableModelUtil.makeDBTable( clms, vals, resource );
499                }
500
501                /**
502                 * 分割後のDBTableModelを返します。
503                 *
504                 * @return 分割後のDBTableModel
505                 */
506                public DBTableModel getTable() {
507                        return table;
508                }
509        }
510}