全てを再実装したJdbcAcsessです。
Revision | 27d3e75b898ed4d0cf1d33efbda767b6240652ac (tree) |
---|---|
Time | 2012-02-18 20:11:31 |
Author | shimakazuro |
Commiter | shimakazuro |
SQLキャンセルをフラグ使用からInterrupt使用へ変更
historyテーブルロードをスレッド化
@@ -411,7 +411,7 @@ | ||
411 | 411 | ShowDialog.errorMessage(e); |
412 | 412 | e.printStackTrace(); |
413 | 413 | } catch (InterruptedException e) { |
414 | - ShowDialog.errorMessage(e); | |
414 | + Thread.currentThread().interrupt(); | |
415 | 415 | } |
416 | 416 | } |
417 | 417 | } |
@@ -212,7 +212,6 @@ | ||
212 | 212 | */ |
213 | 213 | private void stop(JPanelSql jPanelSql) { |
214 | 214 | jPanelSql.taskCancel(); |
215 | - jPanelSql.taskWakuUp(); | |
216 | 215 | } |
217 | 216 | }; |
218 | 217 |
@@ -1,15 +1,15 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright 2011 Kazuhiro Shimada |
3 | 3 | * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | - * you may not use this file except in compliance with the License. | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | 6 | * You may obtain a copy of the License at |
7 | 7 | * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | 9 | * |
10 | - * Unless required by applicable law or agreed to in writing, software | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
@@ -38,6 +38,7 @@ | ||
38 | 38 | * 例外 |
39 | 39 | */ |
40 | 40 | public static void errorMessage(final Throwable t) { |
41 | + t.printStackTrace(); | |
41 | 42 | try { |
42 | 43 | SQLException nextSqlException = null; |
43 | 44 | if (t instanceof SQLException) { |
@@ -194,10 +194,6 @@ | ||
194 | 194 | */ |
195 | 195 | private int rowCnt; |
196 | 196 | /** |
197 | - * 実行中止受付フラグ | |
198 | - */ | |
199 | - private boolean calcelFlg = false; | |
200 | - /** | |
201 | 197 | * wait状態で想定外の再開が発生した場合に再度waitする為のwait状態フラグ |
202 | 198 | */ |
203 | 199 | private boolean available = false; |
@@ -223,7 +219,6 @@ | ||
223 | 219 | @Override |
224 | 220 | public void dataBaseConnectionClosing(DataBaseConnection dataBaseConnection) { |
225 | 221 | taskCancel(); |
226 | - taskWakeUp(); | |
227 | 222 | taskJoin(DataBaseConnection.TIMEOUT_SECONDS); |
228 | 223 | } |
229 | 224 |
@@ -250,11 +245,9 @@ | ||
250 | 245 | dataBaseConnection.addConnectionListener(changeConnection); |
251 | 246 | |
252 | 247 | for (SqlExecuteSentence sentence : sqlExecuteSentenceList) { |
253 | - synchronized (this) { | |
254 | - if (calcelFlg) { | |
255 | - Jdbcacsess2.logger.info(" (task)canceled."); | |
256 | - break; | |
257 | - } | |
248 | + if (Thread.interrupted()) { | |
249 | + Jdbcacsess2.logger.info(" (task)canceled."); | |
250 | + break; | |
258 | 251 | } |
259 | 252 | sqlExec(sentence); |
260 | 253 | } |
@@ -297,11 +290,9 @@ | ||
297 | 290 | SqlInputParameter sqlInputParameter = sqlExecuteSentence.getSqlInputParameter(); |
298 | 291 | |
299 | 292 | while (sqlInputParameter.getSqlExecuteParmeter().hasNext()) { |
300 | - synchronized (this) { | |
301 | - if (calcelFlg) { | |
302 | - Jdbcacsess2.logger.info(" (task)canceled."); | |
303 | - break; | |
304 | - } | |
293 | + if (Thread.interrupted()) { | |
294 | + Jdbcacsess2.logger.info(" (task)canceled."); | |
295 | + break; | |
305 | 296 | } |
306 | 297 | |
307 | 298 | // パラメータ設定を呼び出す |
@@ -407,7 +398,7 @@ | ||
407 | 398 | try { |
408 | 399 | while (resultSet.next()) { |
409 | 400 | synchronized (this) { |
410 | - if (calcelFlg) { | |
401 | + if (Thread.interrupted()) { | |
411 | 402 | Jdbcacsess2.logger.info(" (task)canceled."); |
412 | 403 | break; |
413 | 404 | } |
@@ -439,8 +430,11 @@ | ||
439 | 430 | try { |
440 | 431 | wait(); |
441 | 432 | } catch (InterruptedException e) { |
442 | - e.printStackTrace(); | |
443 | - Jdbcacsess2.logger.fine(" (task)wait retry."); | |
433 | + Jdbcacsess2.logger.fine(" (task)interrupted."); | |
434 | + // wait() により割り込みフラグがクリアされたので、 | |
435 | + // 自身にもう一度割り込みをかける。ループ脱出をを検知させる為。 | |
436 | + Thread.currentThread().interrupt(); | |
437 | + break; | |
444 | 438 | } |
445 | 439 | } |
446 | 440 | Jdbcacsess2.logger.info(" (task)wake up."); |
@@ -471,9 +465,7 @@ | ||
471 | 465 | */ |
472 | 466 | @Override |
473 | 467 | public void taskCancel() { |
474 | - synchronized (this) { | |
475 | - calcelFlg = true; | |
476 | - } | |
468 | + thread.interrupt(); | |
477 | 469 | } |
478 | 470 | |
479 | 471 | /** |
@@ -23,9 +23,11 @@ | ||
23 | 23 | import java.util.List; |
24 | 24 | import java.util.TimeZone; |
25 | 25 | |
26 | +import javax.swing.SwingUtilities; | |
26 | 27 | import javax.swing.table.AbstractTableModel; |
27 | 28 | |
28 | 29 | import jdbcacsess2.main.Config; |
30 | +import jdbcacsess2.main.Jdbcacsess2; | |
29 | 31 | import jdbcacsess2.main.ShowDialog; |
30 | 32 | import net.java.ao.EntityManager; |
31 | 33 | import net.java.ao.Query; |
@@ -54,16 +56,34 @@ | ||
54 | 56 | timeFormat.setTimeZone(TimeZone.getTimeZone("UTC")); |
55 | 57 | entityManager = config.getEntityManager(); |
56 | 58 | |
57 | - try { | |
58 | - for (ExecHistory o : entityManager.find(ExecHistory.class, Query.select().order(ExecHistory.STARTDATE))) { | |
59 | - historyList.add(o); | |
60 | - startDate.add(dateFormat.format(o.getStartDate())); | |
61 | - } | |
62 | - } catch (SQLException e) { | |
63 | - ShowDialog.errorMessage(e); | |
64 | - } | |
59 | + initialize(); | |
65 | 60 | } |
66 | 61 | |
62 | + synchronized private void initialize() { | |
63 | + new Thread() { | |
64 | + @Override | |
65 | + public void run() { | |
66 | + try { | |
67 | + for (ExecHistory o : entityManager.find(ExecHistory.class, | |
68 | + Query.select().order(ExecHistory.STARTDATE))) { | |
69 | + historyList.add(o); | |
70 | + startDate.add(dateFormat.format(o.getStartDate())); | |
71 | + } | |
72 | + | |
73 | + SwingUtilities.invokeLater(new Runnable() { | |
74 | + @Override | |
75 | + public void run() { | |
76 | + fireTableDataChanged(); | |
77 | + } | |
78 | + }); | |
79 | + Jdbcacsess2.logger.info("history load end"); | |
80 | + } catch (SQLException e) { | |
81 | + ShowDialog.errorMessage(e); | |
82 | + } | |
83 | + } | |
84 | + }.start(); | |
85 | + | |
86 | + } | |
67 | 87 | synchronized public int add(ExecHistory execHistory) { |
68 | 88 | historyList.add(execHistory); |
69 | 89 | startDate.add(dateFormat.format(execHistory.getStartDate())); |
@@ -115,8 +115,8 @@ | ||
115 | 115 | execHistory.setSqlCommand(sqlExecuteSentence.getSqlCommand()); |
116 | 116 | execHistory.setSqlText(sqlExecuteSentence.getSqlSentence()); |
117 | 117 | execHistory.setResultStatus(ResultStatus.ACCEPT); |
118 | - execHistory.save(); | |
119 | 118 | execHistoryIndex = histryTableModel.add(execHistory); |
119 | + saveLater(execHistory); | |
120 | 120 | |
121 | 121 | SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.INSERT)); |
122 | 122 | } catch (SQLException e) { |
@@ -138,7 +138,7 @@ | ||
138 | 138 | execHistory.setEndDate(new Date()); |
139 | 139 | } |
140 | 140 | execHistory.setResultStatus(ResultStatus.NORMALEND); |
141 | - execHistory.save(); | |
141 | + saveLater(execHistory); | |
142 | 142 | SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE)); |
143 | 143 | } |
144 | 144 |
@@ -162,7 +162,7 @@ | ||
162 | 162 | execHistory.setEndDate(new Date()); |
163 | 163 | } |
164 | 164 | execHistory.setResultStatus(ResultStatus.ABNORMALEND); |
165 | - execHistory.save(); | |
165 | + saveLater(execHistory); | |
166 | 166 | SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE)); |
167 | 167 | } |
168 | 168 |
@@ -183,7 +183,7 @@ | ||
183 | 183 | } |
184 | 184 | |
185 | 185 | execHistory.setEndDate(new Date()); |
186 | - execHistory.save(); | |
186 | + saveLater(execHistory); | |
187 | 187 | SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE)); |
188 | 188 | } |
189 | 189 |
@@ -201,7 +201,17 @@ | ||
201 | 201 | execHistory.setEndDate(new Date()); |
202 | 202 | } |
203 | 203 | execHistory.setResultStatus(ResultStatus.EXECUTING); |
204 | - execHistory.save(); | |
204 | + saveLater(execHistory); | |
205 | 205 | SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE)); |
206 | 206 | } |
207 | + | |
208 | + private void saveLater(final ExecHistory execHistory) { | |
209 | + Thread thread = new Thread() { | |
210 | + @Override | |
211 | + public void run() { | |
212 | + execHistory.save(); | |
213 | + } | |
214 | + }; | |
215 | + thread.start(); | |
216 | + } | |
207 | 217 | } |