| Revision | 2483 (tree) |
|---|---|
| Time | 2022-11-07 19:30:15 |
| Author | t_nakayama1971 |
(empty log message)
| @@ -52,8 +52,7 @@ | ||
| 52 | 52 | * @return DAOオブジェクト |
| 53 | 53 | */ |
| 54 | 54 | public static Dao getDao() { |
| 55 | - final var df = Factory.create(DaoSession.class); | |
| 56 | - return df.getDao(DEFAULT_NAME.get()); | |
| 55 | + return getDao(DEFAULT_NAME.get()); | |
| 57 | 56 | } |
| 58 | 57 | |
| 59 | 58 | /** |
| @@ -115,8 +114,7 @@ | ||
| 115 | 114 | * @return エンコーディング文字列 |
| 116 | 115 | */ |
| 117 | 116 | public static Charset getCharset() { |
| 118 | - final var cf = Factory.create(JdbcSession.class); | |
| 119 | - return cf.getCharset(DEFAULT_NAME.get()); | |
| 117 | + return getCharset(DEFAULT_NAME.get()); | |
| 120 | 118 | } |
| 121 | 119 | |
| 122 | 120 | /** |
| @@ -142,6 +140,17 @@ | ||
| 142 | 140 | } |
| 143 | 141 | |
| 144 | 142 | /** |
| 143 | + * 最終リリース処理 | |
| 144 | + */ | |
| 145 | + public static void shutdown() { | |
| 146 | + try { | |
| 147 | + Factory.create(DaoSession.class).shutdown(); | |
| 148 | + } finally { | |
| 149 | + deregister(JdbcSource.class.getClassLoader()); | |
| 150 | + } | |
| 151 | + } | |
| 152 | + | |
| 153 | + /** | |
| 145 | 154 | * ドライバ抹消 |
| 146 | 155 | * |
| 147 | 156 | * @param cl ドライバ読込クラスローダ |
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * @author Tadashi Nakayama |
| 7 | 7 | */ |
| 8 | 8 | public interface DaoSession { |
| 9 | + | |
| 9 | 10 | /** |
| 10 | 11 | * DAO取得 |
| 11 | 12 | * |
| @@ -13,4 +14,9 @@ | ||
| 13 | 14 | * @return コネクション |
| 14 | 15 | */ |
| 15 | 16 | Dao getDao(String cname); |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 最終リリース | |
| 20 | + */ | |
| 21 | + void shutdown(); | |
| 16 | 22 | } |
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | */ |
| 19 | 19 | @Override |
| 20 | 20 | public void contextDestroyed(final ServletContextEvent arg0) { |
| 21 | - JdbcSource.deregister(getClass().getClassLoader()); | |
| 21 | + JdbcSource.shutdown(); | |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| @@ -63,7 +63,11 @@ | ||
| 63 | 63 | * @return 処理結果 |
| 64 | 64 | */ |
| 65 | 65 | public static int start(final Class<? extends ProjectBatch> cls, final String... args) { |
| 66 | - return new ProjectPerform<>(cls).execute(args); | |
| 66 | + try { | |
| 67 | + return new ProjectPerform<>(cls).execute(args); | |
| 68 | + } finally { | |
| 69 | + JdbcSource.shutdown(); | |
| 70 | + } | |
| 67 | 71 | } |
| 68 | 72 | |
| 69 | 73 | /** |
| @@ -53,6 +53,20 @@ | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | + * 最終リリース | |
| 57 | + */ | |
| 58 | + @Override | |
| 59 | + public void shutdown() { | |
| 60 | + for (final Config cfg : this.config.values()) { | |
| 61 | + try { | |
| 62 | + cfg.getSessionFactory().close(); | |
| 63 | + } catch (final HibernateException e) { | |
| 64 | + ThrowableUtil.warn(e); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + /** | |
| 56 | 70 | * DAO作成 |
| 57 | 71 | * |
| 58 | 72 | * @param cname 設定名 |
| @@ -61,7 +75,7 @@ | ||
| 61 | 75 | @Override |
| 62 | 76 | public Dao getDao(final String cname) { |
| 63 | 77 | try { |
| 64 | - BaseDao bd = null; | |
| 78 | + Dao bd = null; | |
| 65 | 79 | final var cfg = getConfig(cname); |
| 66 | 80 | final var prop = cfg.getConfiguration().getProperties(); |
| 67 | 81 | if (prop != null) { |
| @@ -91,9 +105,7 @@ | ||
| 91 | 105 | * @return 設定 |
| 92 | 106 | */ |
| 93 | 107 | private Config getConfig(final String cname) { |
| 94 | - return this.config.computeIfAbsent(toConfigName(cname), key -> | |
| 95 | - new Config(new Configuration().configure(key)) | |
| 96 | - ); | |
| 108 | + return this.config.computeIfAbsent(toConfigName(cname), key -> new Config(new Configuration().configure(key))); | |
| 97 | 109 | } |
| 98 | 110 | |
| 99 | 111 | /** |
| @@ -90,14 +90,11 @@ | ||
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * セションクローズ |
| 93 | - * | |
| 94 | 93 | */ |
| 95 | 94 | @Override |
| 96 | 95 | public void close() { |
| 97 | 96 | try (var session = new NoCloseSession(getSession())) { |
| 98 | - if (0 < session.getStatistics().getEntityCount()) { | |
| 99 | - session.clear(); | |
| 100 | - } | |
| 97 | + session.clear(); | |
| 101 | 98 | } |
| 102 | 99 | } |
| 103 | 100 |