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 */
016 package org.opengion.hayabusa.report;
017
018 import org.opengion.hayabusa.common.HybsSystem;
019 import org.opengion.fukurou.util.LogWriter;
020 import org.opengion.fukurou.util.StringUtil;
021 import org.opengion.fukurou.util.ApplicationInfo;
022 import org.opengion.fukurou.db.DBUtil;
023
024 /**
025 * 【DB登録】EXCEL取込機?の???ある、テンポラリ??ブルから?アプリ側の
026 * 本番??ブルへの??タ取込処??ための、PL/SQL をコールします?
027 * 実際の呼び出し?、{ call 帳票IDP.帳票ID( 結果(STATUS),?(ERR_CODE),PGID,要求番号 ) }
028 * と? PL/SQL ?Call します?
029 * 第?引数、第?引数は、OUT属?で、結果(STATUS)とエラー時??(ERR_CODE)を返します?
030 * 第?引数は、起動?PGIDです? 第?引数は、??行う要求番号です?
031 * 結果(STATUS)は、正常なら?? を返してください?
032 *
033 * @og.rev 3.8.0.0 (2005/06/07) 新規追?
034 * @og.group 帳票シス?
035 *
036 * @version 4.0
037 * @author Kazuhiko Hasegawa
038 * @since JDK5.0,
039 */
040 public class ProgramRun {
041
042 private final StringBuilder errMsg = new StringBuilder();
043 private static final String CR = HybsSystem.CR ;
044
045 private final String SYSTEM_ID ;
046 private final String YKNO ;
047 private final String LISTID ;
048 private final boolean DEBUG ; // 3.8.5.0 (2006/03/06) ??用のフラグを追?
049
050 private String sqlCmd = null;
051
052 /** コネクションにアプリケーション??を追記するかど???*/
053 public static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ;
054
055 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設?
056 private final ApplicationInfo appInfo;
057
058 /**
059 * コンストラクター
060 *
061 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設?
062 *
063 * @param system_id シス?ID
064 * @param ykno 要求番号
065 * @param listId 帳票ID
066 * @param debug ??フラグ??
067 */
068 public ProgramRun( final String system_id, final String ykno, final String listId, final boolean debug ) {
069 SYSTEM_ID = system_id;
070 YKNO = ykno;
071 LISTID = listId;
072 DEBUG = debug;
073
074 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設?
075 if( USE_DB_APPLICATION_INFO ) {
076 appInfo = new ApplicationInfo();
077 // ユーザーID,IPアドレス,ホスト名
078 appInfo.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME );
079 // 画面ID,操?プログラ?D
080 appInfo.setModuleInfo( "ProgramRun",YKNO,LISTID );
081 }
082 else {
083 appInfo = null;
084 }
085 }
086
087 /**
088 * レポ?ト?力??実行します?
089 *
090 * @return 結果 [true:正常/false:異常]
091 */
092 public boolean execute() {
093 System.out.print( "ProgramRun [" + SYSTEM_ID + "]... " );
094 boolean flag;
095
096 try {
097 flag = makeSQLCommand();
098 if( flag ) { System.out.print( " MK SQL," ); }
099
100 if( flag ) {
101 flag = programRun();
102 if( flag ) { System.out.print( " PG RUN," ); }
103 }
104 System.out.println( " End." );
105 }
106 catch( Throwable ex ) {
107 errMsg.append( "ProgramRun Execute Error! " ).append( CR ) ;
108 errMsg.append( "==============================" ).append( CR );
109 errMsg.append( StringUtil.stringStackTrace( ex ) ) ;
110 errMsg.append( CR ) ;
111 flag = false;
112 }
113
114 return flag ;
115 }
116
117 /**
118 * PLSQL の call コマンド???を作?します?
119 * { call 帳票ID+P.帳票ID( 結果(STATUS),?(ERR_CODE),PGID,要求番号 ) } に対応す?
120 * { call 帳票IDP.帳票ID( ?,?,?,? ) } ??を作?します?
121 *
122 * @return 結果 [true:正常/false:異常]
123 */
124 private boolean makeSQLCommand() {
125 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_SMALL );
126
127 buf.append( "{ call " ).append( LISTID );
128 buf.append( "P." ).append( LISTID );
129 buf.append( "( ?,?,?,? ) }" );
130
131 sqlCmd = buf.toString();
132 if( DEBUG ) {
133 System.out.println();
134 System.out.println( sqlCmd );
135 }
136
137 return true;
138 }
139
140 /**
141 * 実際のPL/SQL コール処?行います?
142 * { call 帳票IDP.帳票ID( 結果(STATUS),?(ERR_CODE),PGID,要求番号 ) }
143 * と? PL/SQL ?Call します?
144 * 第?引数、第?引数は、OUT属?で、結果(STATUS)とエラー時??(ERR_CODE)?
145 * 返してください。第?引数は、起動?PGIDです?
146 * 結果(STATUS)は、正常なら?? を返してください?
147 *
148 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設?
149 *
150 * @return 結果 [true:正常/false:異常]
151 */
152 private boolean programRun() {
153
154 String[] args = new String[] { "ProgRUN",YKNO };
155 String[] rtn = DBUtil.dbCallExecute( sqlCmd,args,appInfo ); // 3.8.7.0 (2006/12/15)
156
157 boolean flag = false;
158 if( rtn != null && rtn.length == 2 ) {
159 String rtnCode = rtn[0];
160 String rtnMsg = rtn[1];
161 if( "0".equals( rtnCode ) ) { // 正常
162 flag = true;
163 }
164 else {
165 errMsg.append( "PL/SQL=[" ).append( sqlCmd ).append( "] " );
166 errMsg.append( "YKNO=[" ).append( YKNO ).append( "] " );
167 errMsg.append( "LISTID=[" ).append( LISTID ).append( "] " );
168 errMsg.append( rtnCode ).append( ":" ).append( rtnMsg );
169 errMsg.append( CR );
170 LogWriter.log( errMsg.toString() );
171 }
172 }
173 return flag;
174 }
175
176 /**
177 * エラーが存在した場合に、エラーメ?ージを返します?
178 *
179 * @return エラーメ?ージ String
180 */
181 public String getErrMsg() {
182 return errMsg.toString();
183 }
184 }