• R/O
  • SSH

JdbcAcsess2: Commit

全てを再実装したJdbcAcsessです。


Commit MetaInfo

Revision27d3e75b898ed4d0cf1d33efbda767b6240652ac (tree)
Time2012-02-18 20:11:31
Authorshimakazuro
Commitershimakazuro

Log Message

SQLキャンセルをフラグ使用からInterrupt使用へ変更
historyテーブルロードをスレッド化

Change Summary

Incremental Difference

diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/main/JPanelSql.java
--- a/src/jdbcacsess2/main/JPanelSql.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelSql.java Sat Feb 18 20:11:31 2012 +0900
@@ -411,7 +411,7 @@
411411 ShowDialog.errorMessage(e);
412412 e.printStackTrace();
413413 } catch (InterruptedException e) {
414- ShowDialog.errorMessage(e);
414+ Thread.currentThread().interrupt();
415415 }
416416 }
417417 }
diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/main/MainController.java
--- a/src/jdbcacsess2/main/MainController.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/main/MainController.java Sat Feb 18 20:11:31 2012 +0900
@@ -212,7 +212,6 @@
212212 */
213213 private void stop(JPanelSql jPanelSql) {
214214 jPanelSql.taskCancel();
215- jPanelSql.taskWakuUp();
216215 }
217216 };
218217
diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/main/ShowDialog.java
--- a/src/jdbcacsess2/main/ShowDialog.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/main/ShowDialog.java Sat Feb 18 20:11:31 2012 +0900
@@ -1,15 +1,15 @@
11 /*
22 * Copyright 2011 Kazuhiro Shimada
33 *
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.
66 * You may obtain a copy of the License at
77 *
8- * http://www.apache.org/licenses/LICENSE-2.0
8+ * http://www.apache.org/licenses/LICENSE-2.0
99 *
10- * Unless required by applicable law or agreed to in writing, software
10+ * Unless required by applicable law or agreed to in writing, software
1111 * 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.
1313 * See the License for the specific language governing permissions and
1414 * limitations under the License.
1515 */
@@ -38,6 +38,7 @@
3838 * 例外
3939 */
4040 public static void errorMessage(final Throwable t) {
41+ t.printStackTrace();
4142 try {
4243 SQLException nextSqlException = null;
4344 if (t instanceof SQLException) {
diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/sqlService/SqlAsyncExecute.java
--- a/src/jdbcacsess2/sqlService/SqlAsyncExecute.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/sqlService/SqlAsyncExecute.java Sat Feb 18 20:11:31 2012 +0900
@@ -194,10 +194,6 @@
194194 */
195195 private int rowCnt;
196196 /**
197- * 実行中止受付フラグ
198- */
199- private boolean calcelFlg = false;
200- /**
201197 * wait状態で想定外の再開が発生した場合に再度waitする為のwait状態フラグ
202198 */
203199 private boolean available = false;
@@ -223,7 +219,6 @@
223219 @Override
224220 public void dataBaseConnectionClosing(DataBaseConnection dataBaseConnection) {
225221 taskCancel();
226- taskWakeUp();
227222 taskJoin(DataBaseConnection.TIMEOUT_SECONDS);
228223 }
229224
@@ -250,11 +245,9 @@
250245 dataBaseConnection.addConnectionListener(changeConnection);
251246
252247 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;
258251 }
259252 sqlExec(sentence);
260253 }
@@ -297,11 +290,9 @@
297290 SqlInputParameter sqlInputParameter = sqlExecuteSentence.getSqlInputParameter();
298291
299292 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;
305296 }
306297
307298 // パラメータ設定を呼び出す
@@ -407,7 +398,7 @@
407398 try {
408399 while (resultSet.next()) {
409400 synchronized (this) {
410- if (calcelFlg) {
401+ if (Thread.interrupted()) {
411402 Jdbcacsess2.logger.info(" (task)canceled.");
412403 break;
413404 }
@@ -439,8 +430,11 @@
439430 try {
440431 wait();
441432 } 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;
444438 }
445439 }
446440 Jdbcacsess2.logger.info(" (task)wake up.");
@@ -471,9 +465,7 @@
471465 */
472466 @Override
473467 public void taskCancel() {
474- synchronized (this) {
475- calcelFlg = true;
476- }
468+ thread.interrupt();
477469 }
478470
479471 /**
diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/sqlService/history/HistryTableModel.java
--- a/src/jdbcacsess2/sqlService/history/HistryTableModel.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/sqlService/history/HistryTableModel.java Sat Feb 18 20:11:31 2012 +0900
@@ -23,9 +23,11 @@
2323 import java.util.List;
2424 import java.util.TimeZone;
2525
26+import javax.swing.SwingUtilities;
2627 import javax.swing.table.AbstractTableModel;
2728
2829 import jdbcacsess2.main.Config;
30+import jdbcacsess2.main.Jdbcacsess2;
2931 import jdbcacsess2.main.ShowDialog;
3032 import net.java.ao.EntityManager;
3133 import net.java.ao.Query;
@@ -54,16 +56,34 @@
5456 timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
5557 entityManager = config.getEntityManager();
5658
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();
6560 }
6661
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+ }
6787 synchronized public int add(ExecHistory execHistory) {
6888 historyList.add(execHistory);
6989 startDate.add(dateFormat.format(execHistory.getStartDate()));
diff -r 1f299e0d3d20 -r 27d3e75b898e src/jdbcacsess2/sqlService/history/Record.java
--- a/src/jdbcacsess2/sqlService/history/Record.java Thu Feb 16 23:15:34 2012 +0900
+++ b/src/jdbcacsess2/sqlService/history/Record.java Sat Feb 18 20:11:31 2012 +0900
@@ -115,8 +115,8 @@
115115 execHistory.setSqlCommand(sqlExecuteSentence.getSqlCommand());
116116 execHistory.setSqlText(sqlExecuteSentence.getSqlSentence());
117117 execHistory.setResultStatus(ResultStatus.ACCEPT);
118- execHistory.save();
119118 execHistoryIndex = histryTableModel.add(execHistory);
119+ saveLater(execHistory);
120120
121121 SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.INSERT));
122122 } catch (SQLException e) {
@@ -138,7 +138,7 @@
138138 execHistory.setEndDate(new Date());
139139 }
140140 execHistory.setResultStatus(ResultStatus.NORMALEND);
141- execHistory.save();
141+ saveLater(execHistory);
142142 SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
143143 }
144144
@@ -162,7 +162,7 @@
162162 execHistory.setEndDate(new Date());
163163 }
164164 execHistory.setResultStatus(ResultStatus.ABNORMALEND);
165- execHistory.save();
165+ saveLater(execHistory);
166166 SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
167167 }
168168
@@ -183,7 +183,7 @@
183183 }
184184
185185 execHistory.setEndDate(new Date());
186- execHistory.save();
186+ saveLater(execHistory);
187187 SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
188188 }
189189
@@ -201,7 +201,17 @@
201201 execHistory.setEndDate(new Date());
202202 }
203203 execHistory.setResultStatus(ResultStatus.EXECUTING);
204- execHistory.save();
204+ saveLater(execHistory);
205205 SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
206206 }
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+ }
207217 }
Show on old repository browser