全てを再実装したJdbcAcsessです。
Revision | 28c38ec4338b06dff5fe1aa3d56b0e94289aaa58 (tree) |
---|---|
Zeit | 2012-05-04 00:21:18 |
Autor | shimakazuro |
Commiter | shimakazuro |
いろいろ
@@ -124,7 +124,7 @@ | ||
124 | 124 | |
125 | 125 | this.entityManager = new EntityManager(CONFIG_JDBCURL, USER, PASS); |
126 | 126 | Jdbcacsess2.loggerActiveObjects.setLevel(Level.WARNING); |
127 | - // Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE); | |
127 | + Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE); | |
128 | 128 | |
129 | 129 | migrate(); |
130 | 130 | Jdbcacsess2.logger.info("Migrate end"); |
@@ -16,6 +16,8 @@ | ||
16 | 16 | package jdbcacsess2.main; |
17 | 17 | |
18 | 18 | import java.awt.BorderLayout; |
19 | +import java.awt.Color; | |
20 | +import java.awt.Component; | |
19 | 21 | import java.awt.Dimension; |
20 | 22 | import java.awt.Font; |
21 | 23 | import java.awt.event.ItemEvent; |
@@ -26,6 +28,7 @@ | ||
26 | 28 | import javax.swing.JButton; |
27 | 29 | import javax.swing.JCheckBox; |
28 | 30 | import javax.swing.JComboBox; |
31 | +import javax.swing.JLabel; | |
29 | 32 | import javax.swing.JOptionPane; |
30 | 33 | import javax.swing.JPanel; |
31 | 34 | import javax.swing.JScrollPane; |
@@ -40,6 +43,7 @@ | ||
40 | 43 | import javax.swing.SwingUtilities; |
41 | 44 | import javax.swing.event.ChangeEvent; |
42 | 45 | import javax.swing.event.ChangeListener; |
46 | +import javax.swing.table.DefaultTableCellRenderer; | |
43 | 47 | |
44 | 48 | import jdbcacsess2.main.icon.IconImage; |
45 | 49 | import jdbcacsess2.sqlService.ColumnAttributeResult; |
@@ -47,6 +51,7 @@ | ||
47 | 51 | import jdbcacsess2.sqlService.DataBaseConnectionListener; |
48 | 52 | import jdbcacsess2.sqlService.DataBaseTransactionListener; |
49 | 53 | import jdbcacsess2.sqlService.PropertyResultSetTableModel; |
54 | +import jdbcacsess2.sqlService.Result; | |
50 | 55 | import jdbcacsess2.sqlService.ResultsTableModel; |
51 | 56 | import jdbcacsess2.sqlService.SqlExecuteTask; |
52 | 57 | import jdbcacsess2.sqlService.SqlExecutedListener; |
@@ -381,7 +386,7 @@ | ||
381 | 386 | @Override |
382 | 387 | public void run() { |
383 | 388 | Object[] options = { |
384 | - "はい、後続のSQL実行を中断", "いいえ、以降の全エラーを無視" | |
389 | + "はい、後続のSQL実行を中断", "いいえ、以降の全エラーを無視" | |
385 | 390 | }; |
386 | 391 | int n = JOptionPane.showOptionDialog(null, |
387 | 392 | "残りのSQL実行は中断しますか?", |
@@ -433,7 +438,7 @@ | ||
433 | 438 | * @see jdbcacsess2.sqlService.SqlExecutedListener#resultDetail(int, java.util.List) |
434 | 439 | */ |
435 | 440 | @Override |
436 | - public void resultDetail(int seq, List<Object> detail) { | |
441 | + public void resultDetail(int seq, List<Result> detail) { | |
437 | 442 | } |
438 | 443 | |
439 | 444 | /* |
@@ -471,6 +476,33 @@ | ||
471 | 476 | }); |
472 | 477 | } |
473 | 478 | |
479 | + class TableRenderer extends DefaultTableCellRenderer { | |
480 | + | |
481 | + @Override | |
482 | + public Component getTableCellRendererComponent(JTable table, Object value, | |
483 | + boolean isSelected, boolean hasFocus, | |
484 | + int row, int column) { | |
485 | + Result r = (Result) value; | |
486 | + if (r.nulldata && !hasFocus) { | |
487 | + setBackground(Color.ORANGE); | |
488 | + } else { | |
489 | + setBackground(null); | |
490 | + } | |
491 | + if (r.error && !hasFocus) { | |
492 | + setBackground(Color.PINK); | |
493 | + } | |
494 | + | |
495 | + if (r.num) { | |
496 | + setHorizontalAlignment(JLabel.RIGHT); | |
497 | + } else { | |
498 | + setHorizontalAlignment(JLabel.LEFT); | |
499 | + } | |
500 | + | |
501 | + super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); | |
502 | + return this; | |
503 | + } | |
504 | + } | |
505 | + | |
474 | 506 | // ------------------------------------------------------------------------- |
475 | 507 | // ------------------------------------------------------------------------- |
476 | 508 | // ------------------------------------------------------------------------- |
@@ -608,6 +640,8 @@ | ||
608 | 640 | FontZoom.setMouseWheel(jTable); |
609 | 641 | resultsTableColumnFit = new TableColumnFit(jTable); |
610 | 642 | jTable.setModel(new ResultsTableModel()); |
643 | + | |
644 | + jTable.setDefaultRenderer(Object.class, new TableRenderer()); | |
611 | 645 | } |
612 | 646 | return jTable; |
613 | 647 | } |
@@ -176,8 +176,8 @@ | ||
176 | 176 | SqlAsyncExecute sqlAsyncExecute = |
177 | 177 | new SqlAsyncExecute(sql, |
178 | 178 | ((SentenceSeparator) jPanelSql.getJComboBoxSentenceSeparator() |
179 | - .getSelectedItem()).getRegVal(), | |
180 | - config.optionValues); | |
179 | + .getSelectedItem()).getRegVal(), | |
180 | + config.optionValues); | |
181 | 181 | if (sqlAsyncExecute.isDuplxSelect()) { |
182 | 182 | ShowDialog.warningMessage("複数のSELECT文は実行出来ません", "複数のSELECT文"); |
183 | 183 | jPanelSql.getJToggleButtonExecution().setSelected(false); |
@@ -794,6 +794,7 @@ | ||
794 | 794 | this.config = config; |
795 | 795 | |
796 | 796 | view = new MainView(); |
797 | + ShowDialog.setJFrame(view); | |
797 | 798 | |
798 | 799 | histryTableModel = new HistryTableModel(config); |
799 | 800 |
@@ -19,6 +19,7 @@ | ||
19 | 19 | import java.sql.SQLException; |
20 | 20 | import java.util.logging.Level; |
21 | 21 | |
22 | +import javax.swing.JFrame; | |
22 | 23 | import javax.swing.JOptionPane; |
23 | 24 | import javax.swing.SwingUtilities; |
24 | 25 |
@@ -30,6 +31,11 @@ | ||
30 | 31 | */ |
31 | 32 | public class ShowDialog { |
32 | 33 | |
34 | + private static JFrame appjframe; | |
35 | + | |
36 | + public static void setJFrame(JFrame jframe) { | |
37 | + appjframe = jframe; | |
38 | + } | |
33 | 39 | /** |
34 | 40 | * 例外発生時のメッセージ出力。画面表示とログ出力を行います。画面表示は、SwingUtilities. invokeLaterを使用しEDTで実行されます。 |
35 | 41 | * |
@@ -51,7 +57,7 @@ | ||
51 | 57 | // EDT以外で呼ばれる事も想定し、EDTで実行する。 |
52 | 58 | SwingUtilities.invokeLater(new Runnable() { |
53 | 59 | public void run() { |
54 | - JOptionPane.showMessageDialog(null, msg, "ERRORが発生しました", JOptionPane.ERROR_MESSAGE); | |
60 | + JOptionPane.showMessageDialog(appjframe, msg, "ERRORが発生しました", JOptionPane.ERROR_MESSAGE); | |
55 | 61 | } |
56 | 62 | }); |
57 | 63 | } catch (Throwable e) { |
@@ -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 | */ |
@@ -19,6 +19,9 @@ | ||
19 | 19 | import java.sql.SQLException; |
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.List; |
22 | +import java.util.logging.Level; | |
23 | + | |
24 | +import jdbcacsess2.main.Jdbcacsess2; | |
22 | 25 | |
23 | 26 | /** |
24 | 27 | * java.sql.ResultSetMetaData の主要項目を、取り扱いやすいようにインスタンス変数で管理します。 |
@@ -38,7 +41,7 @@ | ||
38 | 41 | * @throws ClassNotFoundException |
39 | 42 | */ |
40 | 43 | static public List<ColumnAttributeResult> convColumnAttributeResult(ResultSetMetaData rsmd) throws SQLException, |
41 | - ClassNotFoundException { | |
44 | + ClassNotFoundException { | |
42 | 45 | |
43 | 46 | int cnt = rsmd.getColumnCount(); |
44 | 47 |
@@ -63,12 +66,6 @@ | ||
63 | 66 | |
64 | 67 | columnClassName = rsmd.getColumnClassName(column); |
65 | 68 | |
66 | - try { | |
67 | - columnClass = Class.forName(columnClassName, true, rsmd.getClass().getClassLoader()); | |
68 | - } catch (Exception e) { | |
69 | - // TODO ここで、いろいろなデータ型に対応するCLASSを決定する | |
70 | - } | |
71 | - | |
72 | 69 | columnDisplaySize = rsmd.getColumnDisplaySize(column); |
73 | 70 | |
74 | 71 | columnLabel = rsmd.getColumnLabel(column); |
@@ -97,31 +94,42 @@ | ||
97 | 94 | readOnly = rsmd.isReadOnly(column); |
98 | 95 | searchable = rsmd.isSearchable(column); |
99 | 96 | writable = rsmd.isWritable(column); |
97 | + | |
98 | + try { | |
99 | + columnClass = Class.forName(columnClassName, true, rsmd.getClass().getClassLoader()); | |
100 | + } catch (Exception e) { | |
101 | + // TODO ここで、いろいろなデータ型に対応するCLASSを決定する | |
102 | + Jdbcacsess2.logger.log(Level.SEVERE, | |
103 | + "未対応クラス:" + columnClassName + " " + columnName + "は、Objectで処理続行します", | |
104 | + e); | |
105 | + columnClass = Object.class; | |
106 | + } | |
107 | + | |
100 | 108 | } |
101 | 109 | |
102 | 110 | private Class<?> columnClass; |
103 | - private String columnClassName; | |
104 | - private int columnDisplaySize; | |
105 | - private String columnLabel; | |
106 | - private String columnName; | |
107 | - private ConstSqlTypes columnType; | |
111 | + private final String columnClassName; | |
112 | + private final int columnDisplaySize; | |
113 | + private final String columnLabel; | |
114 | + private final String columnName; | |
115 | + private final ConstSqlTypes columnType; | |
108 | 116 | private String columnTypeName; |
109 | - private int precision; | |
110 | - private int scale; | |
117 | + private final int precision; | |
118 | + private final int scale; | |
111 | 119 | private boolean signed; |
112 | 120 | |
113 | - private String catalogName; | |
114 | - private String schemaName; | |
115 | - private String tableName; | |
121 | + private final String catalogName; | |
122 | + private final String schemaName; | |
123 | + private final String tableName; | |
116 | 124 | |
117 | - private boolean autoIncrement; | |
118 | - private boolean caseSensitive; | |
119 | - private boolean currency; | |
120 | - private boolean definitelyWritable; | |
121 | - private int nullable; | |
122 | - private boolean readOnly; | |
123 | - private boolean searchable; | |
124 | - private boolean writable; | |
125 | + private final boolean autoIncrement; | |
126 | + private final boolean caseSensitive; | |
127 | + private final boolean currency; | |
128 | + private final boolean definitelyWritable; | |
129 | + private final int nullable; | |
130 | + private final boolean readOnly; | |
131 | + private final boolean searchable; | |
132 | + private final boolean writable; | |
125 | 133 | /** |
126 | 134 | * Java クラスの完全指定されたクラスを返します。JDBCのgetColumnClassNameをclass化したものです。 |
127 | 135 | * |
@@ -0,0 +1,88 @@ | ||
1 | +/* | |
2 | + * Copyright 2012 Kazuhiro Shimada | |
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. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | + | |
17 | +package jdbcacsess2.sqlService; | |
18 | + | |
19 | +import java.sql.Clob; | |
20 | +import java.sql.SQLException; | |
21 | + | |
22 | + | |
23 | +/** | |
24 | + * 検索結果 | |
25 | + * | |
26 | + * @author sima | |
27 | + * | |
28 | + */ | |
29 | +public class Result { | |
30 | + | |
31 | + private final Object data; | |
32 | + private final Class<?> cls; | |
33 | + private String cache; | |
34 | + | |
35 | + public boolean num; | |
36 | + public boolean error; | |
37 | + public final boolean nulldata; | |
38 | + | |
39 | + | |
40 | + public Result(ColumnAttributeResult columnAttributeResult,Object data) { | |
41 | + this.data = data; | |
42 | + nulldata = (data == null); | |
43 | + cls = columnAttributeResult.getColumnClass(); | |
44 | + | |
45 | + if (nulldata) { | |
46 | + cache = "#null#"; | |
47 | + return; | |
48 | + } | |
49 | + | |
50 | + if (java.lang.String.class.isAssignableFrom(cls)) { | |
51 | + cache = data.toString(); | |
52 | + return; | |
53 | + } | |
54 | + if (java.util.Date.class.isAssignableFrom(cls)) { | |
55 | + cache = data.toString(); | |
56 | + return; | |
57 | + } | |
58 | + if (java.lang.Number.class.isAssignableFrom(cls)) { | |
59 | + num = true; | |
60 | + cache = data.toString(); | |
61 | + return; | |
62 | + } | |
63 | + if (Clob.class.isAssignableFrom(cls)) { | |
64 | + try { | |
65 | + cache = ((Clob) data).getSubString(0, (int) ((Clob) data).length()); | |
66 | + } catch (SQLException e) { | |
67 | + error = true; | |
68 | + cache = ""; | |
69 | + } | |
70 | + return; | |
71 | + } | |
72 | + cache = "#unknown#"; | |
73 | + return; | |
74 | + } | |
75 | + | |
76 | + @Override | |
77 | + public String toString() { | |
78 | + return cache; | |
79 | + } | |
80 | + | |
81 | + public String toQoteString() { | |
82 | + if (num) { | |
83 | + return cache; | |
84 | + } | |
85 | + return '"' + cache + '"'; | |
86 | + } | |
87 | + | |
88 | +} |
@@ -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 | */ |
@@ -35,8 +35,8 @@ | ||
35 | 35 | |
36 | 36 | private static final long serialVersionUID = -4605343361563115844L; |
37 | 37 | |
38 | - private List<ColumnAttributeResult> headerList = Collections.synchronizedList(new ArrayList<ColumnAttributeResult>()); | |
39 | - private List<List<Object>> detailList = Collections.synchronizedList(new ArrayList<List<Object>>()); | |
38 | + private final List<ColumnAttributeResult> headerList = Collections.synchronizedList(new ArrayList<ColumnAttributeResult>()); | |
39 | + private final List<List<Result>> detailList = Collections.synchronizedList(new ArrayList<List<Result>>()); | |
40 | 40 | |
41 | 41 | volatile private boolean tableEditable = false; |
42 | 42 |
@@ -108,7 +108,7 @@ | ||
108 | 108 | * @see jdbcacsess.sql2.SqlExecutedListener#result(int, java.util.ArrayList) |
109 | 109 | */ |
110 | 110 | @Override |
111 | - public void resultDetail(final int seq, final List<Object> results) { | |
111 | + public void resultDetail(final int seq, final List<Result> results) { | |
112 | 112 | SwingUtilities.invokeLater(new Runnable() { |
113 | 113 | public void run() { |
114 | 114 | detailList.add(results); |
@@ -379,9 +379,9 @@ | ||
379 | 379 | Jdbcacsess2.logger.info(" (task)canceled."); |
380 | 380 | break; |
381 | 381 | } |
382 | - ArrayList<Object> results = new ArrayList<Object>(columnCnt); | |
382 | + ArrayList<Result> results = new ArrayList<Result>(columnCnt); | |
383 | 383 | for (int i = 1; i <= columnCnt; i++) { |
384 | - results.add(resultSet.getObject(i)); | |
384 | + results.add(new Result(list.get(i - 1), resultSet.getObject(i))); | |
385 | 385 | } |
386 | 386 | |
387 | 387 | rowCnt++; |
@@ -61,7 +61,7 @@ | ||
61 | 61 | * @param detail |
62 | 62 | * 検索結果リスト |
63 | 63 | */ |
64 | - public void resultDetail(int seq, List<Object> detail); | |
64 | + public void resultDetail(int seq, List<Result> detail); | |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * 結果取得件数が大量になった為、結果の取得が中断した事を通知します。 |
@@ -1,25 +1,27 @@ | ||
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 | */ |
16 | 16 | package jdbcacsess2.sqlService.history; |
17 | 17 | |
18 | +import java.sql.Types; | |
18 | 19 | import java.util.Date; |
19 | 20 | |
20 | 21 | import net.java.ao.Entity; |
21 | 22 | import net.java.ao.Preload; |
22 | 23 | import net.java.ao.schema.NotNull; |
24 | +import net.java.ao.schema.SQLType; | |
23 | 25 | |
24 | 26 | @Preload |
25 | 27 | public interface ExecHistory extends Entity { |
@@ -55,6 +57,7 @@ | ||
55 | 57 | |
56 | 58 | void setSqlCommand(String sqlCommand); |
57 | 59 | |
60 | + @SQLType(value = Types.CLOB) | |
58 | 61 | String getSqlText(); |
59 | 62 | |
60 | 63 | void setSqlText(String sqlText); |
@@ -25,6 +25,7 @@ | ||
25 | 25 | import jdbcacsess2.main.Config; |
26 | 26 | import jdbcacsess2.main.ShowDialog; |
27 | 27 | import jdbcacsess2.sqlService.ColumnAttributeResult; |
28 | +import jdbcacsess2.sqlService.Result; | |
28 | 29 | import jdbcacsess2.sqlService.SqlExecuteTask; |
29 | 30 | import jdbcacsess2.sqlService.SqlExecutedListener; |
30 | 31 | import jdbcacsess2.sqlService.history.ExecHistory.ResultStatus; |
@@ -170,7 +171,7 @@ | ||
170 | 171 | * @see jdbcacsess2.sqlService.SqlExecutedListener#resultDetail(int, java.util.List) |
171 | 172 | */ |
172 | 173 | @Override |
173 | - public void resultDetail(int seq, List<Object> detail) { | |
174 | + public void resultDetail(int seq, List<Result> detail) { | |
174 | 175 | } |
175 | 176 | |
176 | 177 | /* (非 Javadoc) |