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