• R/O
  • SSH

JdbcAcsess2: Commit

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


Commit MetaInfo

Revision559ab95dfad4a57f6feea5b9db509baeb0fcd017 (tree)
Time2012-02-12 13:53:02
Authorshimakazuro
Commitershimakazuro

Log Message

SQL実行の細かな修正

Change Summary

Incremental Difference

diff -r 7854aea28140 -r 559ab95dfad4 src/jdbcacsess2/main/Config.java
--- a/src/jdbcacsess2/main/Config.java Sat Feb 11 14:11:20 2012 +0900
+++ b/src/jdbcacsess2/main/Config.java Sun Feb 12 13:53:02 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 */
@@ -43,16 +43,16 @@
4343 public class Config {
4444
4545 private static final String CONFIG_DIR = System.getProperty("user.home") + System.getProperty("file.separator")
46- + ".jdbcacsess2";
46+ + ".jdbcacsess2";
4747
4848 private static final String CONFIG_DB = "config.derby";
4949 private static final String CONFIG_JDBCURL = "jdbc:derby:" + CONFIG_DIR + System.getProperty("file.separator")
50- + CONFIG_DB + ";create=true";
50+ + CONFIG_DB + ";create=true";
5151 private static final String CONFIG_JDBCCLASS = "org.apache.derby.jdbc.EmbeddedDriver";
5252 private static final String USER = "";
5353 private static final String PASS = "";
5454
55- private EntityManager entityManager;
55+ private final EntityManager entityManager;
5656
5757 /**
5858 * コンストラクタ
@@ -119,7 +119,7 @@
119119
120120 this.entityManager = new EntityManager(CONFIG_JDBCURL, USER, PASS);
121121 Jdbcacsess2.loggerActiveObjects.setLevel(Level.WARNING);
122- Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE);
122+ // Jdbcacsess2.loggerActiveObjects.setLevel(Level.FINE);
123123
124124 migrate();
125125 setUpConfigDbms();
@@ -129,8 +129,8 @@
129129
130130 @SuppressWarnings("unchecked")
131131 private Enumeration<String> extracted(Properties prop) {
132- return (Enumeration<String>) prop.propertyNames();
133- }
132+ return (Enumeration<String>) prop.propertyNames();
133+ }
134134
135135 /**
136136 * ActiveObjects の migrate を呼ぶ。SuppressWarningsでワーニングを抑止する為にメソッド抽出。
@@ -174,18 +174,18 @@
174174 */
175175 public ConfigConnect getConfigConnectRow(String connectName) throws SQLException {
176176 ConfigConnect[] configConnects = getEntityManager().find(ConfigConnect.class, Query.select().where(ConfigConnect.CONNECTNAME + "=?", connectName));
177-
177+
178178 ConfigConnect rtn;
179179 if (configConnects.length==0l){
180180 rtn = getEntityManager().create(ConfigConnect.class,
181- new DBParam(ConfigConnect.CONNECTNAME,
182- connectName));
181+ new DBParam(ConfigConnect.CONNECTNAME,
182+ connectName));
183183 }else{
184184 rtn = configConnects[0];
185185 }
186186 return rtn;
187187 }
188-
188+
189189 /**
190190 * component属性を保管するテーブル検索し、先頭1件だけに絞る。
191191 *
@@ -211,44 +211,44 @@
211211 */
212212 private void setUpConfigDbms() throws SQLException {
213213 String[] colnames = { ConfigDbms.DBMSNAME, ConfigDbms.SUBPROTOCOL, ConfigDbms.SUBNAME, ConfigDbms.DRIVERCLASS,
214- ConfigDbms.URLOPTION };
214+ ConfigDbms.URLOPTION };
215215 String[][] rows = {
216216 { "PostgreSQL", "postgresql", "//%HostName%%PortNumber%/%DataBaseName%",
217- "org.postgresql.Driver", "" },
218- { "MySQL", "mysql", "//%HostName%%PortNumber%/%DataBaseName%", "org.gjt.mm.mysql.Driver", "" },
219- { "MySQL(com)", "mysql", "//%HostName%%PortNumber%/%DataBaseName%", "com.mysql.jdbc.Driver",
220- "" },
221- { "HSQL", "hsqldb:hsql", "//%HostName%%PortNumber%/%DataBaseName%", "org.hsqldb.jdbcDriver",
222- "" },
223- { "Oracle(TYPE4:Pure Java)", "oracle:thin", "@%HostName%%PortNumber%:%DataBaseName%",
224- "oracle.jdbc.driver.OracleDriver", "" },
225- { "Oracle(TYPE2:NET)", "oracle:oci", "@%DataBaseName%", "oracle.jdbc.driver.OracleDriver",
226- "" },
227- { "Oracle(TYPE2:NET8)", "oracle:oci8", "@%DataBaseName%", "oracle.jdbc.driver.OracleDriver",
228- "" },
229- { "DB2(TYPE4:Universal)", "db2", "//%HostName%%PortNumber%/%DataBaseName%",
230- "com.ibm.db2.jcc.DB2Driver", "" },
231- { "DB2(TYPE2:Universal)", "db2", "%DataBaseName%", "com.ibm.db2.jcc.DB2Driver", "" },
232- { "DB2(TYPE2:App)", "db2", "%DataBaseName%", "COM.ibm.db2.jdbc.app.DB2Driver", "" },
233- { "DB2(TYPE3:Net)", "db2", "//%HostName%%PortNumber%/%DataBaseName%",
234- "COM.ibm.db2.jdbc.net.DB2Driver", "" },
235- { "SQL Server", "sqlserver",
236- "//%HostName%%PortNumber%;databaseName=%DataBaseName%",
237- "com.microsoft.sqlserver.jdbc.SQLServerDriver", "" },
238- { "SQL Server(2000)", "microsoft:sqlserver",
239- "//%HostName%%PortNumber%;databaseName=%DataBaseName%",
240- "com.microsoft.jdbc.sqlserver.SQLServerDriver", "" },
241- { "Derby(Embedded)", "derby", "%DataBaseName%", "org.apache.derby.jdbc.EmbeddedDriver", "" },
242- { "Derby(Client)", "derby", "%DataBaseName%", "org.apache.derby.jdbc.ClientDriver", "" },
243- { "SQLite", "sqlite", "/%DataBaseName%", "org.sqlite.JDBC", "" },
244- { "Firebird", "firebirdsql", "//%HostName%%PortNumber%/%DataBaseName%",
245- "org.firebirdsql.jdbc.FBDriver", "" },
246- { "Symfoware", "symford", "//%HostName%%PortNumber%/%DataBaseName%",
247- "com.fujitsu.symfoware.jdbc.SYMDriver", "" },
248- { "HiRDB", "hitachi:hirdb", "//DBID=%PortNumberRAW%,DBHOST=%HostName%",
249- "JP.co.Hitachi.soft.HiRDB.JDBC.HiRDBDriver", "" },
250- { "ODBC(TYPE1)", "odbc", "%DataBaseName%", "sun.jdbc.odbc.JdbcOdbcDriver", "" },
251- { "free format", "", "", "", "" } };
217+ "org.postgresql.Driver", "" },
218+ { "MySQL", "mysql", "//%HostName%%PortNumber%/%DataBaseName%", "org.gjt.mm.mysql.Driver", "" },
219+ { "MySQL(com)", "mysql", "//%HostName%%PortNumber%/%DataBaseName%", "com.mysql.jdbc.Driver",
220+ "" },
221+ { "HSQL", "hsqldb:hsql", "//%HostName%%PortNumber%/%DataBaseName%", "org.hsqldb.jdbcDriver",
222+ "" },
223+ { "Oracle(TYPE4:Pure Java)", "oracle:thin", "@%HostName%%PortNumber%:%DataBaseName%",
224+ "oracle.jdbc.driver.OracleDriver", "" },
225+ { "Oracle(TYPE2:NET)", "oracle:oci", "@%DataBaseName%", "oracle.jdbc.driver.OracleDriver",
226+ "" },
227+ { "Oracle(TYPE2:NET8)", "oracle:oci8", "@%DataBaseName%", "oracle.jdbc.driver.OracleDriver",
228+ "" },
229+ { "DB2(TYPE4:Universal)", "db2", "//%HostName%%PortNumber%/%DataBaseName%",
230+ "com.ibm.db2.jcc.DB2Driver", "" },
231+ { "DB2(TYPE2:Universal)", "db2", "%DataBaseName%", "com.ibm.db2.jcc.DB2Driver", "" },
232+ { "DB2(TYPE2:App)", "db2", "%DataBaseName%", "COM.ibm.db2.jdbc.app.DB2Driver", "" },
233+ { "DB2(TYPE3:Net)", "db2", "//%HostName%%PortNumber%/%DataBaseName%",
234+ "COM.ibm.db2.jdbc.net.DB2Driver", "" },
235+ { "SQL Server", "sqlserver",
236+ "//%HostName%%PortNumber%;databaseName=%DataBaseName%",
237+ "com.microsoft.sqlserver.jdbc.SQLServerDriver", "" },
238+ { "SQL Server(2000)", "microsoft:sqlserver",
239+ "//%HostName%%PortNumber%;databaseName=%DataBaseName%",
240+ "com.microsoft.jdbc.sqlserver.SQLServerDriver", "" },
241+ { "Derby(Embedded)", "derby", "%DataBaseName%", "org.apache.derby.jdbc.EmbeddedDriver", "" },
242+ { "Derby(Client)", "derby", "%DataBaseName%", "org.apache.derby.jdbc.ClientDriver", "" },
243+ { "SQLite", "sqlite", "/%DataBaseName%", "org.sqlite.JDBC", "" },
244+ { "Firebird", "firebirdsql", "//%HostName%%PortNumber%/%DataBaseName%",
245+ "org.firebirdsql.jdbc.FBDriver", "" },
246+ { "Symfoware", "symford", "//%HostName%%PortNumber%/%DataBaseName%",
247+ "com.fujitsu.symfoware.jdbc.SYMDriver", "" },
248+ { "HiRDB", "hitachi:hirdb", "//DBID=%PortNumberRAW%,DBHOST=%HostName%",
249+ "JP.co.Hitachi.soft.HiRDB.JDBC.HiRDBDriver", "" },
250+ { "ODBC(TYPE1)", "odbc", "%DataBaseName%", "sun.jdbc.odbc.JdbcOdbcDriver", "" },
251+ { "free format", "", "", "", "" } };
252252
253253 for (int i = 0; i < rows.length; i++) {
254254 ConfigDbms[] dbms = getEntityManager().find(ConfigDbms.class,
diff -r 7854aea28140 -r 559ab95dfad4 src/jdbcacsess2/main/JPanelHIstory.java
--- a/src/jdbcacsess2/main/JPanelHIstory.java Sat Feb 11 14:11:20 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelHIstory.java Sun Feb 12 13:53:02 2012 +0900
@@ -44,7 +44,6 @@
4444 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
4545 scrollPane.setViewportView(table);
4646
47-
4847 JToolBar toolBar = new JToolBar();
4948 add(toolBar, BorderLayout.NORTH);
5049
diff -r 7854aea28140 -r 559ab95dfad4 src/jdbcacsess2/main/JPanelSql.java
--- a/src/jdbcacsess2/main/JPanelSql.java Sat Feb 11 14:11:20 2012 +0900
+++ b/src/jdbcacsess2/main/JPanelSql.java Sun Feb 12 13:53:02 2012 +0900
@@ -57,7 +57,7 @@
5757 import org.fife.ui.rtextarea.RTextScrollPane;
5858
5959 public class JPanelSql extends JPanel implements SqlExecutedListener, DataBaseConnectionListener,
60- DataBaseTransactionListener {
60+DataBaseTransactionListener {
6161
6262 // -------------------------------------------------------------------------
6363 // -------------------------------------------------------------------------
@@ -111,12 +111,17 @@
111111 */
112112 @Override
113113 public void dataBaseConnectionClosing(DataBaseConnection dataBaseConnection) {
114- getJToggleButtonExecution().setEnabled(false);
115- getJButtonContinue().setEnabled(false);
116- getJCheckBoxAutoCommit().setEnabled(false);
117- getJButtonCommit().setEnabled(false);
118- getJButtonRollback().setEnabled(false);
119- getJToggleButtonConnection().setSelected(false);
114+ SwingUtilities.invokeLater(new Runnable() {
115+ @Override
116+ public void run() {
117+ getJToggleButtonExecution().setEnabled(false);
118+ getJButtonContinue().setEnabled(false);
119+ getJCheckBoxAutoCommit().setEnabled(false);
120+ getJButtonCommit().setEnabled(false);
121+ getJButtonRollback().setEnabled(false);
122+ getJToggleButtonConnection().setSelected(false);
123+ }
124+ });
120125 }
121126
122127 /*
@@ -128,7 +133,12 @@
128133 */
129134 @Override
130135 public void dataBaseConnectionClosed(DataBaseConnection dataBaseConnection) {
131- writeGuiLog("connection closed");
136+ SwingUtilities.invokeLater(new Runnable() {
137+ @Override
138+ public void run() {
139+ writeGuiLog("connection closed");
140+ }
141+ });
132142 }
133143
134144 /**
@@ -146,8 +156,13 @@
146156 * )
147157 */
148158 @Override
149- public void autoCommitChange(DataBaseConnection dataBaseConnection, boolean autoCommit) {
150- writeGuiLog("autocommit[" + autoCommit + "]");
159+ public void autoCommitChange(DataBaseConnection dataBaseConnection, final boolean autoCommit) {
160+ SwingUtilities.invokeLater(new Runnable() {
161+ @Override
162+ public void run() {
163+ writeGuiLog("autocommit[" + autoCommit + "]");
164+ }
165+ });
151166 }
152167
153168 /*
@@ -157,8 +172,13 @@
157172 */
158173 @Override
159174 public void commitEnd(DataBaseConnection dataBaseConnection) {
160- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
161- writeGuiLog("commit end");
175+ SwingUtilities.invokeLater(new Runnable() {
176+ @Override
177+ public void run() {
178+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
179+ writeGuiLog("commit end");
180+ }
181+ });
162182 }
163183
164184 /*
@@ -168,8 +188,13 @@
168188 */
169189 @Override
170190 public void rollbackEnd(DataBaseConnection dataBaseConnection) {
171- getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
172- writeGuiLog("rollback end");
191+ SwingUtilities.invokeLater(new Runnable() {
192+ @Override
193+ public void run() {
194+ getJTabbedPaneResult().setSelectedIndex(TABBEDPANEL_INDEX_LOG);
195+ writeGuiLog("rollback end");
196+ }
197+ });
173198 }
174199
175200 /**
@@ -204,8 +229,8 @@
204229 return;
205230 }
206231 rSyntaxTextAreaSql.replaceRange(addIndent(str),
207- rSyntaxTextAreaSql.getSelectionStart(),
208- rSyntaxTextAreaSql.getSelectionEnd());
232+ rSyntaxTextAreaSql.getSelectionStart(),
233+ rSyntaxTextAreaSql.getSelectionEnd());
209234
210235 rSyntaxTextAreaSql.requestFocus();
211236 }
@@ -368,13 +393,13 @@
368393 public void run() {
369394 Object[] options = { "はい、後続のSQL実行を中断", "いいえ、以降の全エラーを無視" };
370395 int n = JOptionPane.showOptionDialog(null,
371- "残りのSQL実行は中断しますか?",
372- "まだ実行予定のSQLが残ってます",
373- JOptionPane.YES_NO_OPTION,
374- JOptionPane.QUESTION_MESSAGE,
375- null,
376- options,
377- options[0]);
396+ "残りのSQL実行は中断しますか?",
397+ "まだ実行予定のSQLが残ってます",
398+ JOptionPane.YES_NO_OPTION,
399+ JOptionPane.QUESTION_MESSAGE,
400+ null,
401+ options,
402+ options[0]);
378403 if (n == JOptionPane.NO_OPTION) {
379404 exceptionContinue = true;
380405 } else {
diff -r 7854aea28140 -r 559ab95dfad4 src/jdbcacsess2/sqlService/history/HistryTableModel.java
--- a/src/jdbcacsess2/sqlService/history/HistryTableModel.java Sat Feb 11 14:11:20 2012 +0900
+++ b/src/jdbcacsess2/sqlService/history/HistryTableModel.java Sun Feb 12 13:53:02 2012 +0900
@@ -18,10 +18,11 @@
1818
1919 import java.sql.SQLException;
2020 import java.text.SimpleDateFormat;
21+import java.util.ArrayList;
2122 import java.util.Date;
23+import java.util.List;
2224 import java.util.TimeZone;
2325
24-import javax.swing.SwingUtilities;
2526 import javax.swing.table.AbstractTableModel;
2627
2728 import jdbcacsess2.main.Config;
@@ -41,42 +42,37 @@
4142
4243 private final EntityManager entityManager;
4344
44- transient private ExecHistory[] history = new ExecHistory[0];
45+ private final List<ExecHistory> historyList = new ArrayList<ExecHistory>();
46+ private final List<String> startDate = new ArrayList<String>();
4547
4648 private final SimpleDateFormat timeFormat;
4749 private final SimpleDateFormat dateFormat;
4850
4951 public HistryTableModel(Config config) {
52+ dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
53+ timeFormat = new SimpleDateFormat("m:ss.SSS");
54+ timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
5055 entityManager = config.getEntityManager();
56+
5157 try {
52- history = entityManager.find(ExecHistory.class, Query.select().order(ExecHistory.STARTDATE));
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+ }
5362 } catch (SQLException e) {
5463 ShowDialog.errorMessage(e);
5564 }
56- dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
57- timeFormat = new SimpleDateFormat("m:ss.SSS");
58- timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
5965 }
6066
61- public void chnageData() {
62- final ExecHistory[] newhistory;
63- try {
64- newhistory = entityManager.find(ExecHistory.class, Query.select().order(ExecHistory.STARTDATE));
65- } catch (SQLException e) {
66- ShowDialog.errorMessage(e);
67- return;
68- }
69- SwingUtilities.invokeLater(new Runnable() {
70- @Override
71- public void run() {
72- history = newhistory;
73- fireTableDataChanged();
74- }
75- });
67+ synchronized public int add(ExecHistory execHistory) {
68+ historyList.add(execHistory);
69+ startDate.add(dateFormat.format(execHistory.getStartDate()));
70+ return historyList.size() - 1;
7671 }
72+
7773 @Override
7874 public int getRowCount() {
79- return history.length;
75+ return historyList.size();
8076 }
8177
8278 private final String header[] = { "start", "elaps", "command", "status", "cnt", "text", "connect" };
@@ -93,10 +89,10 @@
9389
9490 @Override
9591 public Object getValueAt(int rowIndex, int columnIndex) {
96- ExecHistory eh = history[rowIndex];
92+ ExecHistory eh = historyList.get(rowIndex);
9793 switch (columnIndex) {
9894 case 0:
99- return dateFormat.format(eh.getStartDate());
95+ return startDate.get(rowIndex);
10096 case 1:
10197 if (eh.getEndDate() == null) {
10298 return null;
diff -r 7854aea28140 -r 559ab95dfad4 src/jdbcacsess2/sqlService/history/Record.java
--- a/src/jdbcacsess2/sqlService/history/Record.java Sat Feb 11 14:11:20 2012 +0900
+++ b/src/jdbcacsess2/sqlService/history/Record.java Sun Feb 12 13:53:02 2012 +0900
@@ -39,7 +39,8 @@
3939 public class Record implements SqlExecutedListener {
4040 private final EntityManager entityManager;
4141
42- private ExecHistory execHistory = null;
42+ private ExecHistory execHistory;
43+ private int execHistoryIndex = -1;
4344 private final String connectName;
4445 private final String url;
4546 private final String user;
@@ -55,6 +56,36 @@
5556 this.histryTableModel = histryTableModel;
5657 }
5758
59+ enum FireType {
60+ INSERT, UPDATE, DELETE
61+ }
62+
63+ private class Fire implements Runnable {
64+ private final int index;
65+ private final FireType type;
66+
67+ public Fire(int index, FireType type) {
68+ this.index = index;
69+ this.type = type;
70+ }
71+
72+ @Override
73+ public void run() {
74+ switch (type) {
75+ case INSERT:
76+ histryTableModel.fireTableRowsInserted(index, index);
77+ break;
78+ case UPDATE:
79+ histryTableModel.fireTableRowsUpdated(index, index);
80+ break;
81+
82+ default:
83+ break;
84+ }
85+ }
86+
87+ }
88+
5889 /*
5990 * (非 Javadoc)
6091 *
@@ -85,7 +116,9 @@
85116 execHistory.setSqlText(sqlExecuteSentence.getSqlSentence());
86117 execHistory.setResultStatus(ResultStatus.ACCEPT);
87118 execHistory.save();
88- fire();
119+ execHistoryIndex = histryTableModel.add(execHistory);
120+
121+ SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.INSERT));
89122 } catch (SQLException e) {
90123 ShowDialog.errorMessage(e);
91124 }
@@ -106,7 +139,7 @@
106139 }
107140 execHistory.setResultStatus(ResultStatus.NORMALEND);
108141 execHistory.save();
109- fire();
142+ SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
110143 }
111144
112145 /* (非 Javadoc)
@@ -130,7 +163,7 @@
130163 }
131164 execHistory.setResultStatus(ResultStatus.ABNORMALEND);
132165 execHistory.save();
133- fire();
166+ SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
134167 }
135168
136169 /* (非 Javadoc)
@@ -151,7 +184,7 @@
151184
152185 execHistory.setEndDate(new Date());
153186 execHistory.save();
154- fire();
187+ SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
155188 }
156189
157190 /* (非 Javadoc)
@@ -169,15 +202,6 @@
169202 }
170203 execHistory.setResultStatus(ResultStatus.EXECUTING);
171204 execHistory.save();
172- fire();
173- }
174-
175- private void fire() {
176- SwingUtilities.invokeLater(new Runnable() {
177- @Override
178- public void run() {
179- histryTableModel.chnageData();
180- }
181- });
205+ SwingUtilities.invokeLater(new Fire(execHistoryIndex, FireType.UPDATE));
182206 }
183207 }
Show on old repository browser