• R/O
  • SSH

JdbcAcsess2: Commit

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


Commit MetaInfo

Revision1e05c669aed38d1fa8b5664bdcb3dc6ff5314390 (tree)
Time2012-04-07 10:11:57
Authorshimakazuro
Commitershimakazuro

Log Message

タイムアウトと検索行数限界のパラメータ化

Change Summary

Incremental Difference

diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/connect/ConnectController.java
--- a/src/jdbcacsess2/connect/ConnectController.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/connect/ConnectController.java Sat Apr 07 10:11:57 2012 +0900
@@ -301,12 +301,16 @@
301301 @Override
302302 public void actionPerformed(ActionEvent e) {
303303 try {
304- DataBaseConnection dbc = new DataBaseConnection(view.getJTextAreaURL().getText(),
305- view.getJTextFieldUser().getText(),
306- new String(view.getJPasswordFieldPassword().getPassword()),
307- view.getJTextFieldClassName().getText(),
308- DataBaseConnection.splitPath(view.getJTextAreaDriverFile().getText()),
309- view.getJTextFieldConnectName().getText());
304+ DataBaseConnection dbc =
305+ new DataBaseConnection(
306+ view.getJTextAreaURL().getText(),
307+ view.getJTextFieldUser().getText(),
308+ new String(view.getJPasswordFieldPassword().getPassword()),
309+ view.getJTextFieldClassName().getText(),
310+ DataBaseConnection.splitPath(view.getJTextAreaDriverFile().getText()),
311+ view.getJTextFieldConnectName().getText(),
312+ config.optionValues
313+ );
310314 new DbOpen(dbc).execute();
311315 } catch (Exception e1) {
312316 ShowDialog.errorMessage(e1);
@@ -418,12 +422,15 @@
418422 @Override
419423 public void actionPerformed(ActionEvent e) {
420424 try {
421- DataBaseConnection dbc = new DataBaseConnection(view.getJTextAreaURL().getText(),
422- view.getJTextFieldUser().getText(),
423- new String(view.getJPasswordFieldPassword().getPassword()),
424- view.getJTextFieldClassName().getText(),
425- DataBaseConnection.splitPath(view.getJTextAreaDriverFile().getText()),
426- view.getJTextFieldConnectName().getText());
425+ DataBaseConnection dbc =
426+ new DataBaseConnection(
427+ view.getJTextAreaURL().getText(),
428+ view.getJTextFieldUser().getText(),
429+ new String(view.getJPasswordFieldPassword().getPassword()),
430+ view.getJTextFieldClassName().getText(),
431+ DataBaseConnection.splitPath(view.getJTextAreaDriverFile().getText()),
432+ view.getJTextFieldConnectName().getText(),
433+ config.optionValues);
427434 new DbTestOpen(dbc).execute();
428435
429436 } catch (Exception ex) {
diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/main/Config.java
--- a/src/jdbcacsess2/main/Config.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/main/Config.java Sat Apr 07 10:11:57 2012 +0900
@@ -117,8 +117,8 @@
117117 Class.forName(CONFIG_JDBCCLASS);
118118
119119 this.entityManager = new EntityManager(CONFIG_JDBCURL, USER, PASS);
120- // Jdbcacsess2.loggerActiveObjects.setLevel(Level.WARNING);
121- Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE);
120+ Jdbcacsess2.loggerActiveObjects.setLevel(Level.WARNING);
121+ // Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE);
122122
123123 migrate();
124124 Jdbcacsess2.logger.info("Migrate end");
diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/main/MainController.java
--- a/src/jdbcacsess2/main/MainController.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/main/MainController.java Sat Apr 07 10:11:57 2012 +0900
@@ -176,7 +176,8 @@
176176 SqlAsyncExecute sqlAsyncExecute =
177177 new SqlAsyncExecute(sql,
178178 ((SentenceSeparator) jPanelSql.getJComboBoxSentenceSeparator()
179- .getSelectedItem()).getRegVal());
179+ .getSelectedItem()).getRegVal(),
180+ config.optionValues);
180181 if (sqlAsyncExecute.isDuplxSelect()) {
181182 ShowDialog.warningMessage("複数のSELECT文は実行出来ません", "複数のSELECT文");
182183 jPanelSql.getJToggleButtonExecution().setSelected(false);
diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/main/OptionValues.java
--- a/src/jdbcacsess2/main/OptionValues.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/main/OptionValues.java Sat Apr 07 10:11:57 2012 +0900
@@ -26,9 +26,11 @@
2626 public class OptionValues {
2727 private final EntityManager entityManager;
2828
29- public Prop<String> propString = new Prop<String>("STRING", "STR");
30- public Prop<Integer> propInteger = new Prop<Integer>("INTEGER", 100);
31- public Prop<Boolean> propBoolean = new Prop<Boolean>("BOOLEAN", true);
29+ public Prop<Integer> propTimeOutSeconds = new Prop<Integer>("TIMEOUT_SECONDS", 5);
30+ /**
31+ * 1回あたりの検索結果最大取得行数
32+ */
33+ public Prop<Integer> propResultrowsLimitCnt = new Prop<Integer>("RESULTROWS_LIMITCNT", 5000);
3234
3335 OptionValues(EntityManager entityManager) {
3436 this.entityManager = entityManager;
@@ -45,38 +47,43 @@
4547 this.defaultValue = defaultValue;
4648 }
4749
48- public T getValue() throws SQLException {
49- ConfigProperty[] e = entityManager.find(ConfigProperty.class, Query.select().where("NAME=?", name));
50- if (e.length != 0) {
51- switch (e[0].getType()) {
52- case STRING:
53- return (T) e[0].getValue();
54- case NUMBER:
55- try {
56- return (T) c.getConstructor(String.class).newInstance(e[0].getValue());
57- } catch (Exception ex) {
58- ShowDialog.errorMessage(ex);
50+ public T getValue() {
51+ ConfigProperty[] e;
52+ try {
53+ e = entityManager.find(ConfigProperty.class, Query.select().where("NAME=?", name));
54+ if (e.length != 0) {
55+ switch (e[0].getType()) {
56+ case STRING:
57+ return (T) e[0].getValue();
58+ case NUMBER:
59+ try {
60+ return (T) c.getConstructor(String.class).newInstance(e[0].getValue());
61+ } catch (Exception ex) {
62+ ShowDialog.errorMessage(ex);
63+ break;
64+ }
65+ case BOOLEAN:
66+ return (T) Boolean.valueOf(e[0].getValue());
67+ default:
5968 break;
6069 }
61- case BOOLEAN:
62- return (T) Boolean.valueOf(e[0].getValue());
63- default:
64- break;
70+ return null;
6571 }
66- return null;
72+ Type type = Type.NUMBER;
73+ if (c == String.class) {
74+ type = Type.STRING;
75+ }
76+ if (c == Boolean.class) {
77+ type = Type.BOOLEAN;
78+ }
79+ ConfigProperty rtn =
80+ entityManager.create(ConfigProperty.class,
81+ new DBParam("NAME", name),
82+ new DBParam("TYPE", type),
83+ new DBParam("VALUE", defaultValue));
84+ } catch (SQLException e1) {
85+ ShowDialog.errorMessage(e1);
6786 }
68- Type type = Type.NUMBER;
69- if (c == String.class) {
70- type = Type.STRING;
71- }
72- if (c == Boolean.class) {
73- type = Type.BOOLEAN;
74- }
75- ConfigProperty rtn =
76- entityManager.create(ConfigProperty.class,
77- new DBParam("NAME", name),
78- new DBParam("TYPE", type),
79- new DBParam("VALUE", defaultValue));
8087 return defaultValue;
8188 }
8289
diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/sqlService/DataBaseConnection.java
--- a/src/jdbcacsess2/sqlService/DataBaseConnection.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/sqlService/DataBaseConnection.java Sat Apr 07 10:11:57 2012 +0900
@@ -49,6 +49,7 @@
4949 import javax.swing.event.EventListenerList;
5050
5151 import jdbcacsess2.main.Jdbcacsess2;
52+import jdbcacsess2.main.OptionValues;
5253 import jdbcacsess2.sqlService.exception.DbConnectAlreadyException;
5354 import jdbcacsess2.sqlService.exception.DbConnectDriverLoadException;
5455 import jdbcacsess2.sqlService.exception.DbConnectIllgalStateException;
@@ -65,8 +66,6 @@
6566 */
6667 public class DataBaseConnection {
6768
68- static final int TIMEOUT_SECONDS = 3;
69-
7069 private Connection connection;
7170
7271 private final String url;
@@ -74,13 +73,9 @@
7473 private final String password;
7574 private final String driverClassName;
7675 private final URL[] driverUrlPaths;
77-
7876 private Driver driver;
79-
80- /**
81- * この接続につけた名前
82- */
8377 private String connectName;
78+ private final OptionValues optionValues;
8479
8580 /**
8681 * Connection の open/close等のコネクション状態変更またはトランザクションの開始、AutoCommitの状態変更
@@ -172,7 +167,7 @@
172167 }
173168
174169 /**
175- * コンストラクタ。ドライバjarファイル指定。
170+ * コンストラクタ。
176171 *
177172 * @param url
178173 * @param user
@@ -185,7 +180,8 @@
185180 * @throws FileNotFoundException
186181 */
187182 public DataBaseConnection(String url, String user, String password, String driverClassName, URL[] driverUrlPaths,
188- String connectName) throws DbConnectDriverLoadException, FileNotFoundException {
183+ String connectName, OptionValues optionValues) throws DbConnectDriverLoadException, FileNotFoundException {
184+ this.optionValues = optionValues;
189185 this.url = url;
190186 this.user = user;
191187 this.password = password;
@@ -215,6 +211,7 @@
215211 this.driverClassName = dataBaseConnection.getDriverClassName();
216212 this.driverUrlPaths = dataBaseConnection.driverUrlPaths;
217213 this.connectName = dataBaseConnection.connectName;
214+ this.optionValues = dataBaseConnection.optionValues;
218215 loadDriver();
219216 }
220217
@@ -354,7 +351,7 @@
354351 connection.close();
355352 return null;
356353 }
357- }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
354+ }).get(getTimeoutSeconds(), TimeUnit.SECONDS);
358355
359356 // CLOSEが成功したときだけ通知する。
360357 for (DataBaseConnectionListener listener : listeners.getListeners(DataBaseConnectionListener.class)) {
@@ -413,7 +410,7 @@
413410 connection.commit();
414411 return null;
415412 }
416- }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
413+ }).get(getTimeoutSeconds(), TimeUnit.SECONDS);
417414
418415 // 成功したときだけ通知する。
419416 for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) {
@@ -440,7 +437,7 @@
440437 connection.rollback();
441438 return null;
442439 }
443- }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
440+ }).get(getTimeoutSeconds(), TimeUnit.SECONDS);
444441
445442 // 成功したときだけ通知する。
446443 for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) {
@@ -482,7 +479,7 @@
482479 connection.setAutoCommit(autoCommit);
483480 return null;
484481 }
485- }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
482+ }).get(getTimeoutSeconds(), TimeUnit.SECONDS);
486483
487484 // 成功したときだけ通知する。
488485 for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) {
@@ -609,4 +606,11 @@
609606 return executorService;
610607 }
611608
609+ /**
610+ * @return tIMEOUT_SECONDS
611+ */
612+ public int getTimeoutSeconds() {
613+ return optionValues.propTimeOutSeconds.getValue();
614+ }
615+
612616 }
diff -r 3564c6cff517 -r 1e05c669aed3 src/jdbcacsess2/sqlService/SqlAsyncExecute.java
--- a/src/jdbcacsess2/sqlService/SqlAsyncExecute.java Sat Mar 31 15:19:10 2012 +0900
+++ b/src/jdbcacsess2/sqlService/SqlAsyncExecute.java Sat Apr 07 10:11:57 2012 +0900
@@ -30,6 +30,7 @@
3030 import javax.swing.event.EventListenerList;
3131
3232 import jdbcacsess2.main.Jdbcacsess2;
33+import jdbcacsess2.main.OptionValues;
3334 import jdbcacsess2.main.ShowDialog;
3435 import jdbcacsess2.sqlService.SqlExecuteParmeter.Parameter;
3536 import jdbcacsess2.sqlService.exception.DbConnectIllgalStateException;
@@ -45,10 +46,7 @@
4546 */
4647 public class SqlAsyncExecute {
4748
48- /**
49- * 1回あたりの検索結果最大取得行数
50- */
51- private volatile int resultRowLimitCnt = 5000;
49+ // private volatile int resultRowLimitCnt = 5000;
5250 /**
5351 * SQL文の解析結果
5452 */
@@ -62,6 +60,7 @@
6260 */
6361 private Thread thread;
6462
63+ private final OptionValues optionValues;
6564 /**
6665 * コンストラクタ
6766 *
@@ -69,11 +68,13 @@
6968 * @param sqlSentence
7069 * 実行したいSQL文
7170 */
72- public SqlAsyncExecute(String sqlSentence, String sentenceSeparator) {
71+ public SqlAsyncExecute(String sqlSentence, String sentenceSeparator, OptionValues optionValues) {
7372
7473 sqlExecutedListeners = new EventListenerList();
7574
7675 sqlExecuteSentenceList = new SqlExecuteSentencies(sqlSentence, sentenceSeparator).getSqlExecuteSentenceList();
76+
77+ this.optionValues = optionValues;
7778 }
7879
7980 /**
@@ -104,25 +105,6 @@
104105 }
105106
106107 /**
107- * 大量検索時の最大検索行数を返却。指定した行数になるとSQL実行スレッドがwaitする
108- *
109- * @return 大量検索時の最大検索行数
110- */
111- public int getResultRowLimitCnt() {
112- return resultRowLimitCnt;
113- }
114-
115- /**
116- * 大量検索時の最大検索行数を設定。指定した行数になるとSQL実行スレッドがwaitする
117- *
118- * @param resultRowLimitCnt
119- * 大量検索時の最大検索行数
120- */
121- public void setResultRowLimitCnt(int resultRowLimitCnt) {
122- this.resultRowLimitCnt = resultRowLimitCnt;
123- }
124-
125- /**
126108 * 結果受け取りリスナーの登録
127109 *
128110 * @param listener
@@ -153,7 +135,7 @@
153135 */
154136 public SqlExecuteTask executeAsync(DataBaseConnection dataBaseConnection) throws DbConnectIllgalStateException {
155137 dataBaseConnection.lockConnection(sqlExecuteSentenceList.size() == 0 ? ""
156- : sqlExecuteSentenceList.get(0).getSqlCommand());
138+ : sqlExecuteSentenceList.get(0).getSqlCommand());
157139
158140 SqlTask sqlTask = new SqlTask(dataBaseConnection);
159141 thread = new Thread(sqlTask);
@@ -214,7 +196,7 @@
214196 }
215197 }
216198 taskCancel();
217- taskJoin(DataBaseConnection.TIMEOUT_SECONDS);
199+ taskJoin(dataBaseConnection.getTimeoutSeconds());
218200 }
219201
220202 @Override
@@ -408,7 +390,7 @@
408390 }
409391 Jdbcacsess2.logger.finest(" (task)results notified.");
410392
411- if (rowCnt % resultRowLimitCnt == 0) {
393+ if (rowCnt % optionValues.propResultrowsLimitCnt.getValue() == 0) {
412394
413395 available = true;
414396 new Thread() {
Show on old repository browser