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