全てを再実装したJdbcAcsessです。
修订版 | 1e05c669aed38d1fa8b5664bdcb3dc6ff5314390 (tree) |
---|---|
时间 | 2012-04-07 10:11:57 |
作者 | shimakazuro |
Commiter | shimakazuro |
タイムアウトと検索行数限界のパラメータ化
@@ -301,12 +301,16 @@ | ||
301 | 301 | @Override |
302 | 302 | public void actionPerformed(ActionEvent e) { |
303 | 303 | 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 | + ); | |
310 | 314 | new DbOpen(dbc).execute(); |
311 | 315 | } catch (Exception e1) { |
312 | 316 | ShowDialog.errorMessage(e1); |
@@ -418,12 +422,15 @@ | ||
418 | 422 | @Override |
419 | 423 | public void actionPerformed(ActionEvent e) { |
420 | 424 | 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); | |
427 | 434 | new DbTestOpen(dbc).execute(); |
428 | 435 | |
429 | 436 | } catch (Exception ex) { |
@@ -117,8 +117,8 @@ | ||
117 | 117 | Class.forName(CONFIG_JDBCCLASS); |
118 | 118 | |
119 | 119 | 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); | |
122 | 122 | |
123 | 123 | migrate(); |
124 | 124 | Jdbcacsess2.logger.info("Migrate end"); |
@@ -176,7 +176,8 @@ | ||
176 | 176 | SqlAsyncExecute sqlAsyncExecute = |
177 | 177 | new SqlAsyncExecute(sql, |
178 | 178 | ((SentenceSeparator) jPanelSql.getJComboBoxSentenceSeparator() |
179 | - .getSelectedItem()).getRegVal()); | |
179 | + .getSelectedItem()).getRegVal(), | |
180 | + config.optionValues); | |
180 | 181 | if (sqlAsyncExecute.isDuplxSelect()) { |
181 | 182 | ShowDialog.warningMessage("複数のSELECT文は実行出来ません", "複数のSELECT文"); |
182 | 183 | jPanelSql.getJToggleButtonExecution().setSelected(false); |
@@ -26,9 +26,11 @@ | ||
26 | 26 | public class OptionValues { |
27 | 27 | private final EntityManager entityManager; |
28 | 28 | |
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); | |
32 | 34 | |
33 | 35 | OptionValues(EntityManager entityManager) { |
34 | 36 | this.entityManager = entityManager; |
@@ -45,38 +47,43 @@ | ||
45 | 47 | this.defaultValue = defaultValue; |
46 | 48 | } |
47 | 49 | |
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: | |
59 | 68 | break; |
60 | 69 | } |
61 | - case BOOLEAN: | |
62 | - return (T) Boolean.valueOf(e[0].getValue()); | |
63 | - default: | |
64 | - break; | |
70 | + return null; | |
65 | 71 | } |
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); | |
67 | 86 | } |
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)); | |
80 | 87 | return defaultValue; |
81 | 88 | } |
82 | 89 |
@@ -49,6 +49,7 @@ | ||
49 | 49 | import javax.swing.event.EventListenerList; |
50 | 50 | |
51 | 51 | import jdbcacsess2.main.Jdbcacsess2; |
52 | +import jdbcacsess2.main.OptionValues; | |
52 | 53 | import jdbcacsess2.sqlService.exception.DbConnectAlreadyException; |
53 | 54 | import jdbcacsess2.sqlService.exception.DbConnectDriverLoadException; |
54 | 55 | import jdbcacsess2.sqlService.exception.DbConnectIllgalStateException; |
@@ -65,8 +66,6 @@ | ||
65 | 66 | */ |
66 | 67 | public class DataBaseConnection { |
67 | 68 | |
68 | - static final int TIMEOUT_SECONDS = 3; | |
69 | - | |
70 | 69 | private Connection connection; |
71 | 70 | |
72 | 71 | private final String url; |
@@ -74,13 +73,9 @@ | ||
74 | 73 | private final String password; |
75 | 74 | private final String driverClassName; |
76 | 75 | private final URL[] driverUrlPaths; |
77 | - | |
78 | 76 | private Driver driver; |
79 | - | |
80 | - /** | |
81 | - * この接続につけた名前 | |
82 | - */ | |
83 | 77 | private String connectName; |
78 | + private final OptionValues optionValues; | |
84 | 79 | |
85 | 80 | /** |
86 | 81 | * Connection の open/close等のコネクション状態変更またはトランザクションの開始、AutoCommitの状態変更 |
@@ -172,7 +167,7 @@ | ||
172 | 167 | } |
173 | 168 | |
174 | 169 | /** |
175 | - * コンストラクタ。ドライバjarファイル指定。 | |
170 | + * コンストラクタ。 | |
176 | 171 | * |
177 | 172 | * @param url |
178 | 173 | * @param user |
@@ -185,7 +180,8 @@ | ||
185 | 180 | * @throws FileNotFoundException |
186 | 181 | */ |
187 | 182 | 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; | |
189 | 185 | this.url = url; |
190 | 186 | this.user = user; |
191 | 187 | this.password = password; |
@@ -215,6 +211,7 @@ | ||
215 | 211 | this.driverClassName = dataBaseConnection.getDriverClassName(); |
216 | 212 | this.driverUrlPaths = dataBaseConnection.driverUrlPaths; |
217 | 213 | this.connectName = dataBaseConnection.connectName; |
214 | + this.optionValues = dataBaseConnection.optionValues; | |
218 | 215 | loadDriver(); |
219 | 216 | } |
220 | 217 |
@@ -354,7 +351,7 @@ | ||
354 | 351 | connection.close(); |
355 | 352 | return null; |
356 | 353 | } |
357 | - }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | |
354 | + }).get(getTimeoutSeconds(), TimeUnit.SECONDS); | |
358 | 355 | |
359 | 356 | // CLOSEが成功したときだけ通知する。 |
360 | 357 | for (DataBaseConnectionListener listener : listeners.getListeners(DataBaseConnectionListener.class)) { |
@@ -413,7 +410,7 @@ | ||
413 | 410 | connection.commit(); |
414 | 411 | return null; |
415 | 412 | } |
416 | - }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | |
413 | + }).get(getTimeoutSeconds(), TimeUnit.SECONDS); | |
417 | 414 | |
418 | 415 | // 成功したときだけ通知する。 |
419 | 416 | for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) { |
@@ -440,7 +437,7 @@ | ||
440 | 437 | connection.rollback(); |
441 | 438 | return null; |
442 | 439 | } |
443 | - }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | |
440 | + }).get(getTimeoutSeconds(), TimeUnit.SECONDS); | |
444 | 441 | |
445 | 442 | // 成功したときだけ通知する。 |
446 | 443 | for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) { |
@@ -482,7 +479,7 @@ | ||
482 | 479 | connection.setAutoCommit(autoCommit); |
483 | 480 | return null; |
484 | 481 | } |
485 | - }).get(TIMEOUT_SECONDS, TimeUnit.SECONDS); | |
482 | + }).get(getTimeoutSeconds(), TimeUnit.SECONDS); | |
486 | 483 | |
487 | 484 | // 成功したときだけ通知する。 |
488 | 485 | for (DataBaseTransactionListener listener : listeners.getListeners(DataBaseTransactionListener.class)) { |
@@ -609,4 +606,11 @@ | ||
609 | 606 | return executorService; |
610 | 607 | } |
611 | 608 | |
609 | + /** | |
610 | + * @return tIMEOUT_SECONDS | |
611 | + */ | |
612 | + public int getTimeoutSeconds() { | |
613 | + return optionValues.propTimeOutSeconds.getValue(); | |
614 | + } | |
615 | + | |
612 | 616 | } |
@@ -30,6 +30,7 @@ | ||
30 | 30 | import javax.swing.event.EventListenerList; |
31 | 31 | |
32 | 32 | import jdbcacsess2.main.Jdbcacsess2; |
33 | +import jdbcacsess2.main.OptionValues; | |
33 | 34 | import jdbcacsess2.main.ShowDialog; |
34 | 35 | import jdbcacsess2.sqlService.SqlExecuteParmeter.Parameter; |
35 | 36 | import jdbcacsess2.sqlService.exception.DbConnectIllgalStateException; |
@@ -45,10 +46,7 @@ | ||
45 | 46 | */ |
46 | 47 | public class SqlAsyncExecute { |
47 | 48 | |
48 | - /** | |
49 | - * 1回あたりの検索結果最大取得行数 | |
50 | - */ | |
51 | - private volatile int resultRowLimitCnt = 5000; | |
49 | + // private volatile int resultRowLimitCnt = 5000; | |
52 | 50 | /** |
53 | 51 | * SQL文の解析結果 |
54 | 52 | */ |
@@ -62,6 +60,7 @@ | ||
62 | 60 | */ |
63 | 61 | private Thread thread; |
64 | 62 | |
63 | + private final OptionValues optionValues; | |
65 | 64 | /** |
66 | 65 | * コンストラクタ |
67 | 66 | * |
@@ -69,11 +68,13 @@ | ||
69 | 68 | * @param sqlSentence |
70 | 69 | * 実行したいSQL文 |
71 | 70 | */ |
72 | - public SqlAsyncExecute(String sqlSentence, String sentenceSeparator) { | |
71 | + public SqlAsyncExecute(String sqlSentence, String sentenceSeparator, OptionValues optionValues) { | |
73 | 72 | |
74 | 73 | sqlExecutedListeners = new EventListenerList(); |
75 | 74 | |
76 | 75 | sqlExecuteSentenceList = new SqlExecuteSentencies(sqlSentence, sentenceSeparator).getSqlExecuteSentenceList(); |
76 | + | |
77 | + this.optionValues = optionValues; | |
77 | 78 | } |
78 | 79 | |
79 | 80 | /** |
@@ -104,25 +105,6 @@ | ||
104 | 105 | } |
105 | 106 | |
106 | 107 | /** |
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 | - /** | |
126 | 108 | * 結果受け取りリスナーの登録 |
127 | 109 | * |
128 | 110 | * @param listener |
@@ -153,7 +135,7 @@ | ||
153 | 135 | */ |
154 | 136 | public SqlExecuteTask executeAsync(DataBaseConnection dataBaseConnection) throws DbConnectIllgalStateException { |
155 | 137 | dataBaseConnection.lockConnection(sqlExecuteSentenceList.size() == 0 ? "" |
156 | - : sqlExecuteSentenceList.get(0).getSqlCommand()); | |
138 | + : sqlExecuteSentenceList.get(0).getSqlCommand()); | |
157 | 139 | |
158 | 140 | SqlTask sqlTask = new SqlTask(dataBaseConnection); |
159 | 141 | thread = new Thread(sqlTask); |
@@ -214,7 +196,7 @@ | ||
214 | 196 | } |
215 | 197 | } |
216 | 198 | taskCancel(); |
217 | - taskJoin(DataBaseConnection.TIMEOUT_SECONDS); | |
199 | + taskJoin(dataBaseConnection.getTimeoutSeconds()); | |
218 | 200 | } |
219 | 201 | |
220 | 202 | @Override |
@@ -408,7 +390,7 @@ | ||
408 | 390 | } |
409 | 391 | Jdbcacsess2.logger.finest(" (task)results notified."); |
410 | 392 | |
411 | - if (rowCnt % resultRowLimitCnt == 0) { | |
393 | + if (rowCnt % optionValues.propResultrowsLimitCnt.getValue() == 0) { | |
412 | 394 | |
413 | 395 | available = true; |
414 | 396 | new Thread() { |