001// package org.opengion.fukurou.util;
002package org.opengion.fukurou.business;
003
004// import org.opengion.fukurou.business.BizLogicHelper;
005import org.opengion.fukurou.util.HybsLoader;
006import org.opengion.fukurou.util.HybsLoaderFactory;
007import org.opengion.fukurou.util.HybsLoaderConfig;
008import org.opengion.fukurou.db.TransactionImpl;
009
010/**
011 * bizLogicファイル共通クラス
012 * bizLogicファイルを処理するための、
013 * 共通クラスです。
014 *
015 * @og.rev 5.10.15.2 (2019/09/20) 新規作成
016 * 
017 * @version 5
018 * @author oota
019 * @since JDK7
020 */
021public final class BizUtil {
022        
023        /**
024         * private コンスタクター
025         * インスタンスは生成せずに、利用します。
026         */
027        private BizUtil() {     }
028        
029        /**
030         * bizLogicファイルの実行 bizLogicファイルをホットデプロイして、
031         * 処理を実行します。
032         * 
033         * @og.rev 7.0.6.4 (2019/11/29) setTransaction メソッド内で、dbid を使っているので、先に設定します。
034         * 
035         * @param srcDir ソースディレクトリ
036         * @param classDir クラスディレクトリ
037         * @param isAutoCompile オートコンプリートフラグ
038         * @param isHotDeploy ホットデプロイフラグ
039         * @param classPath クラスパス
040         * @param systemId システムID
041         * @param logicName ロジック名
042         * @param keys キーリスト
043         * @param vals 値リスト
044         * @throws Throwable エラー情報
045         */
046        public static void actBizLogic(final String srcDir, final String classDir, final boolean isAutoCompile, final boolean isHotDeploy, final String classPath,
047                        final String systemId, final String logicName, final String[] keys, final String[] vals) throws Throwable {
048
049                // bizクラスファイルのホットデプロイ
050                final HybsLoader ldr = HybsLoaderFactory
051                                .getLoader(new HybsLoaderConfig(srcDir, classDir, isAutoCompile, isHotDeploy, classPath));
052
053                final BizLogicHelper helper = new BizLogicHelper(logicName, ldr);
054
055                // 7.0.6.4 (2019/11/29) try-with-resources文
056                final TransactionImpl tran = new TransactionImpl(null);
057//              helper.setTransaction(tran);
058//              helper.setTransaction(tran);
059//              helper.setKeys(keys);
060//              helper.setVals(vals);
061
062                try {
063                        helper.setDbid(systemId);                               // 7.0.6.4 (2019/11/29) setTransaction メソッド内で、dbid を使っているので、先に設定します。
064                        helper.setTransaction(tran);
065                        helper.setKeys(keys);
066                        helper.setVals(vals);
067
068                        // bizLogic実行
069                        helper.exec();
070                        
071                        // 正常に実行された場合
072                        tran.commit();
073                        tran.finish();
074//              }catch(Throwable e) {
075                } catch( final Throwable ex ) {
076                        // エラー発生時
077                        tran.rollback();
078//                      throw  e;
079                        throw  ex;
080                } finally {
081                        if (tran != null) {
082                                tran.close();
083//                              tran.realClose();
084                        }
085                }
086        }
087}