• R/O
  • SSH
  • HTTPS

wolf-desktop: コミット


コミットメタ情報

リビジョン382 (tree)
日時2016-11-01 15:20:11
作者l_v_yonsama

ログメッセージ

DDL取得失敗対応

変更サマリ

差分

--- Libraries/WolfSQLParser/engine/src/hiro/yoshioka/sql/MySQL.java (revision 381)
+++ Libraries/WolfSQLParser/engine/src/hiro/yoshioka/sql/MySQL.java (revision 382)
@@ -1,18 +1,5 @@
11 package hiro.yoshioka.sql;
22
3-import hiro.yoshioka.ast.sql.oracle.WolfSQLParserConstants;
4-import hiro.yoshioka.sdh.ResultSetDataHolder;
5-import hiro.yoshioka.sdh2.ResultSetDataHolder2;
6-import hiro.yoshioka.sql.engine.GettingResourceRequest;
7-import hiro.yoshioka.sql.engine.Request;
8-import hiro.yoshioka.sql.engine.SQLOperationType;
9-import hiro.yoshioka.sql.resource.DBTable;
10-import hiro.yoshioka.sql.resource.IDBSchema;
11-import hiro.yoshioka.sql.resource.IDBTable;
12-import hiro.yoshioka.sql.resource.ProcedureType;
13-import hiro.yoshioka.sql.resource.TableType;
14-import hiro.yoshioka.util.StringUtil;
15-
163 import java.sql.Driver;
174 import java.sql.PreparedStatement;
185 import java.sql.ResultSet;
@@ -28,507 +15,503 @@
2815 import java.util.regex.Matcher;
2916 import java.util.regex.Pattern;
3017
18+import hiro.yoshioka.ast.sql.oracle.WolfSQLParserConstants;
19+import hiro.yoshioka.sdh.ResultSetDataHolder;
20+import hiro.yoshioka.sdh2.ResultSetDataHolder2;
21+import hiro.yoshioka.sql.engine.GettingResourceRequest;
22+import hiro.yoshioka.sql.engine.Request;
23+import hiro.yoshioka.sql.engine.SQLOperationType;
24+import hiro.yoshioka.sql.resource.DBTable;
25+import hiro.yoshioka.sql.resource.IDBSchema;
26+import hiro.yoshioka.sql.resource.IDBTable;
27+import hiro.yoshioka.sql.resource.ProcedureType;
28+import hiro.yoshioka.sql.resource.TableType;
29+import hiro.yoshioka.util.StringUtil;
30+
3131 public class MySQL extends AbsTransactionSQL implements IMYSQLDBConst {
32- Pattern COMMENT_PATTERN = Pattern.compile("COMMENT=\'(.*)\'");
33- static Pattern DATABASE_PATTERN = Pattern
34- .compile("jdbc:mysql://([^/]+)/([^?]+)");
32+ Pattern COMMENT_PATTERN = Pattern.compile("COMMENT=\'(.*)\'");
33+ static Pattern DATABASE_PATTERN = Pattern.compile("jdbc:mysql://([^/]+)/([^?]+)");
3534
36- public static String getSuggestURL() {
37- return JDBC_URL_EXAMPLE;
38- }
35+ public static String getSuggestURL() {
36+ return JDBC_URL_EXAMPLE;
37+ }
3938
40- protected MySQL(Driver ds) {
41- super(ds);
42- }
39+ protected MySQL(Driver ds) {
40+ super(ds);
41+ }
4342
44- protected String getSupportToken() {
45- StringBuffer buf = new StringBuffer();
46- Pattern p = Pattern.compile("\"(\\w+)\"");
47- String[] str = WolfSQLParserConstants.tokenImage;
48- for (int i = 0; i < str.length; i++) {
49- Matcher m = p.matcher(str[i]);
50- if (m.matches()) {
51- buf.append(m.group(1)).append(",");
52- }
53- }
54- if (buf.length() > 0) {
55- buf.setLength(buf.length() - 1);
56- }
57- return buf.toString();
58- }
43+ @Override
44+ protected String getSupportToken() {
45+ StringBuffer buf = new StringBuffer();
46+ Pattern p = Pattern.compile("\"(\\w+)\"");
47+ String[] str = WolfSQLParserConstants.tokenImage;
48+ for (int i = 0; i < str.length; i++) {
49+ Matcher m = p.matcher(str[i]);
50+ if (m.matches()) {
51+ buf.append(m.group(1)).append(",");
52+ }
53+ }
54+ if (buf.length() > 0) {
55+ buf.setLength(buf.length() - 1);
56+ }
57+ return buf.toString();
58+ }
5959
60- public boolean doOperation(SQLOperationType operation, Request request)
61- throws SQLException {
62- boolean retCode = true;
63- switch (operation) {
64- case SELECT_SESSION:
65- request.setRDH(getSessionInfo());
66- break;
67- default:
68- retCode = super.doOperation(operation, request);
69- break;
70- }
71- return retCode;
72- }
60+ @Override
61+ public boolean doOperation(SQLOperationType operation, Request request) throws SQLException {
62+ boolean retCode = true;
63+ switch (operation) {
64+ case SELECT_SESSION:
65+ request.setRDH(getSessionInfo());
66+ break;
67+ default:
68+ retCode = super.doOperation(operation, request);
69+ break;
70+ }
71+ return retCode;
72+ }
7373
74- /**
75- * @param operationCode
76- * @return
77- */
78- public boolean canDoOperation(SQLOperationType operation) {
79- switch (operation) {
80- case CREATE_DATABASE:
81- case DROP_DATABASE:
82- return _info.isConnected();
83- case SELECT_SESSION:
84- return connected();
85- case SELECT_LOCK:
86- return false;
87- default:
88- return super.canDoOperation(operation);
89- }
90- }
74+ /**
75+ * @param operationCode
76+ * @return
77+ */
78+ @Override
79+ public boolean canDoOperation(SQLOperationType operation) {
80+ switch (operation) {
81+ case CREATE_DATABASE:
82+ case DROP_DATABASE:
83+ return _info.isConnected();
84+ case SELECT_SESSION:
85+ return connected();
86+ case SELECT_LOCK:
87+ return false;
88+ default:
89+ return super.canDoOperation(operation);
90+ }
91+ }
9192
92- public static void main(String[] args) {
93- System.out
94- .println(getDatabaseName("jdbc:mysql://localhost/mysql_s?zeroDateTimeBehavior=convertToNull"));
95- System.out
96- .println(getDatabaseName("jdbc:mysql://localhost/mysql_ssss"));
97- }
93+ public static void main(String[] args) {
94+ System.out.println(getDatabaseName(
95+ "jdbc:mysql://localhost/mysql_s?zeroDateTimeBehavior=convertToNull"));
96+ System.out.println(getDatabaseName("jdbc:mysql://localhost/mysql_ssss"));
97+ }
9898
99- public static String getDatabaseName(String urlString) {
100- Matcher m = DATABASE_PATTERN.matcher(urlString);
101- if (m.find()) {
102- return m.group(2);
103- }
104- return null;
105- }
99+ public static String getDatabaseName(String urlString) {
100+ Matcher m = DATABASE_PATTERN.matcher(urlString);
101+ if (m.find()) {
102+ return m.group(2);
103+ }
104+ return null;
105+ }
106106
107- public static String getHostString(String urlString) {
108- Matcher m = DATABASE_PATTERN.matcher(urlString);
109- if (m.find()) {
110- return m.group(1);
111- }
112- return null;
113- }
107+ public static String getHostString(String urlString) {
108+ Matcher m = DATABASE_PATTERN.matcher(urlString);
109+ if (m.find()) {
110+ return m.group(1);
111+ }
112+ return null;
113+ }
114114
115- protected void setComments(GettingResourceRequest request)
116- throws SQLException {
117- ResultSetDataHolder rsC = null;
118- int row = DEFAULT_ROW_NUM;
115+ @Override
116+ protected void setComments(GettingResourceRequest request) throws SQLException {
117+ ResultSetDataHolder rsC = null;
118+ int row = DEFAULT_ROW_NUM;
119119
120- request.beginTask("Grab Remarks", row);
120+ request.beginTask("Grab Remarks", row);
121121
122- IDBSchema schema = getRoot().getCurrentSchema();
123- IDBTable[] tables = schema.getTableOrViews();
124- for (int i = 0; i < tables.length; i++) {
125- if (!tables[i].isTable()) {
126- continue;
127- }
128- rsC = executePrepareQuery(SHOW_CREATE_TABLE + tables[i].getName(),
129- new String[0]);
130- String comment = rsC.getStringData()[0][2];
131- Matcher m = COMMENT_PATTERN.matcher(comment);
132- if (m.find()) {
133- comment = m.group(1);
134- } else {
135- comment = "";
136- }
137- tables[i].setComment(comment);
138- request.subTask(comment);
139- request.worked(1);
140- }
122+ IDBSchema schema = getRoot().getCurrentSchema();
123+ IDBTable[] tables = schema.getTableOrViews();
124+ for (int i = 0; i < tables.length; i++) {
125+ if (!tables[i].isTable()) {
126+ continue;
127+ }
128+ rsC = executePrepareQuery(SHOW_CREATE_TABLE + tables[i].getName(), new String[0]);
129+ String comment = rsC.getStringData()[0][2];
130+ Matcher m = COMMENT_PATTERN.matcher(comment);
131+ if (m.find()) {
132+ comment = m.group(1);
133+ } else {
134+ comment = "";
135+ }
136+ tables[i].setComment(comment);
137+ request.subTask(comment);
138+ request.worked(1);
139+ }
141140
142- }
141+ }
143142
144- @Override
145- public boolean createDatabase(String name, Properties properties)
146- throws SQLException {
147- return this.createSchema(name, null);
148- }
143+ @Override
144+ public boolean createDatabase(String name, Properties properties) throws SQLException {
145+ return this.createSchema(name, null);
146+ }
149147
150- @Override
151- public boolean dropDatabase(String name) throws SQLException {
152- return this.dropSchema(name, true);
153- }
148+ @Override
149+ public boolean dropDatabase(String name) throws SQLException {
150+ return this.dropSchema(name, true);
151+ }
154152
155- @Override
156- protected boolean createSchema(String schemaName, Properties properties)
157- throws SQLException {
158- String st = String.format("CREATE DATABASE %s ", schemaName);
159- return execute(st);
160- }
153+ @Override
154+ protected boolean createSchema(String schemaName, Properties properties) throws SQLException {
155+ String st = String.format("CREATE DATABASE %s ", schemaName);
156+ return execute(st);
157+ }
161158
162- @Override
163- protected boolean dropSchema(String schemaName, boolean cascade)
164- throws SQLException {
165- String st = String.format("DROP DATABASE IF EXISTS %s", schemaName);
166- return execute(st);
167- }
159+ @Override
160+ protected boolean dropSchema(String schemaName, boolean cascade) throws SQLException {
161+ String st = String.format("DROP DATABASE IF EXISTS %s", schemaName);
162+ return execute(st);
163+ }
168164
169- @Override
170- public boolean existsTable(String schemaName, String tableName)
171- throws SQLException {
165+ @Override
166+ public boolean existsTable(String schemaName, String tableName) throws SQLException {
172167
173- String st = "SELECT COUNT(*) AS CNT FROM information_schema.TABLES WHERE UPPER(TABLE_SCHEMA)=? AND UPPER(TABLE_NAME)=? ";
174- ResultSetDataHolder rdh = executePrepareQuery(st, new String[] {
175- schemaName.toUpperCase(), tableName.toUpperCase() });
176- boolean ret = rdh.getIntDataDefaultZero(0, "CNT") > 0;
177- fLogger.info(String.format(" schemaName[%s] tableName[%s] result[%b]",
178- schemaName, tableName, ret));
179- return ret;
180- }
168+ String st =
169+ "SELECT COUNT(*) AS CNT FROM information_schema.TABLES WHERE UPPER(TABLE_SCHEMA)=? AND UPPER(TABLE_NAME)=? ";
170+ ResultSetDataHolder rdh = executePrepareQuery(st,
171+ new String[] {schemaName.toUpperCase(), tableName.toUpperCase()});
172+ boolean ret = rdh.getIntDataDefaultZero(0, "CNT") > 0;
173+ fLogger.info(String.format(" schemaName[%s] tableName[%s] result[%b]", schemaName,
174+ tableName, ret));
175+ return ret;
176+ }
181177
182- @Override
183- public void setMaxRowNum(int max) {
184- if (max > 50000000) {
185- fLogger.warn("setMaxRows() out of range. " + max + " > 50000000");
186- super.setMaxRowNum(50000000);
187- return;
188- }
189- super.setMaxRowNum(max);
190- }
178+ @Override
179+ public void setMaxRowNum(int max) {
180+ if (max > 50000000) {
181+ fLogger.warn("setMaxRows() out of range. " + max + " > 50000000");
182+ super.setMaxRowNum(50000000);
183+ return;
184+ }
185+ super.setMaxRowNum(max);
186+ }
191187
192- public boolean createUser(String user, String password,
193- String targetDatabaseName) throws SQLException {
194- String sql_statement = String.format(
195- "create user '%s' identified by '%s'", user, password);
196- boolean ret = execute(sql_statement);
197- if (!StringUtil.isEmpty(targetDatabaseName)) {
198- sql_statement = String
199- .format("GRANT ALL ON testdb.* TO '%s'", user);
200- ret = execute(sql_statement);
201- }
188+ public boolean createUser(String user, String password, String targetDatabaseName)
189+ throws SQLException {
190+ String sql_statement = String.format("create user '%s' identified by '%s'", user, password);
191+ boolean ret = execute(sql_statement);
192+ if (!StringUtil.isEmpty(targetDatabaseName)) {
193+ sql_statement = String.format("GRANT ALL ON testdb.* TO '%s'", user);
194+ ret = execute(sql_statement);
195+ }
202196
203- return ret;
204- }
197+ return ret;
198+ }
205199
206- // --
207- public ResultSetDataHolder2 getSessionInfo() throws SQLException {
208- return executePrepareQuery(this.getOrCreateExtraConnection(), SELECT_SESSION_INFO,
209- (String[]) null);
210- }
200+ // --
201+ @Override
202+ public ResultSetDataHolder2 getSessionInfo() throws SQLException {
203+ return executePrepareQuery(this.getOrCreateExtraConnection(), SELECT_SESSION_INFO,
204+ (String[]) null);
205+ }
211206
212- public ResultSetDataHolder2 getLockInfo() throws SQLException {
213- return null;
214- }
207+ @Override
208+ public ResultSetDataHolder2 getLockInfo() throws SQLException {
209+ return null;
210+ }
215211
216- @Override
217- public List<String> getTablePrimaryKeys(String catalog, String schema,
218- String table) throws SQLException {
212+ @Override
213+ public List<String> getTablePrimaryKeys(String catalog, String schema, String table)
214+ throws SQLException {
219215
220- List<String> items = new ArrayList<String>();
221- ResultSetDataHolder2 rdh = executePrepareQuery(SELECT_PRIMARY_KEY,
222- new String[] { schema.toUpperCase(), table.toUpperCase() });
223- for (int i = 0; i < rdh.getRowCount(); i++) {
224- items.add(rdh.getStringRecordRow(i)[1].getString());
225- }
226- return items;
227- }
216+ List<String> items = new ArrayList<String>();
217+ ResultSetDataHolder2 rdh = executePrepareQuery(SELECT_PRIMARY_KEY,
218+ new String[] {schema.toUpperCase(), table.toUpperCase()});
219+ for (int i = 0; i < rdh.getRowCount(); i++) {
220+ items.add(rdh.getStringRecordRow(i)[1].getString());
221+ }
222+ return items;
223+ }
228224
229- @Override
230- public String getDefaultSchemaName() {
231- return getDatabaseName(_info.getURLString());
232- }
225+ @Override
226+ public String getDefaultSchemaName() {
227+ return getDatabaseName(_info.getURLString());
228+ }
233229
234- @Override
235- public Set<String> getSchemas() {
236- ResultSet rs = null;
237- Statement st = null;
238- Set<String> retSet = new LinkedHashSet<String>();
239- try {
240- st = this.getOrCreateExtraConnection().createStatement();
241- rs = st.executeQuery("SELECT DISTINCT SCHEMA_NAME FROM information_schema.SCHEMATA");
242- while (rs.next()) {
243- retSet.add(rs.getString(1));
244- }
245- } catch (Exception e) {
246- fLogger.error(StringUtil.EMPTY_STRING, e);
247- return Collections.EMPTY_SET;
248- } finally {
249- if (rs != null) {
250- try {
251- rs.close();
252- } catch (SQLException e) {
253- }
254- }
255- if (st != null) {
256- try {
257- st.close();
258- } catch (SQLException e) {
259- }
260- }
261- fLogger.info("end [" + retSet + "]");
262- capturing = false;
263- }
264- return retSet;
265- }
230+ @Override
231+ public Set<String> getSchemas() {
232+ ResultSet rs = null;
233+ Statement st = null;
234+ Set<String> retSet = new LinkedHashSet<String>();
235+ try {
236+ st = this.getOrCreateExtraConnection().createStatement();
237+ rs = st.executeQuery("SELECT DISTINCT SCHEMA_NAME FROM information_schema.SCHEMATA");
238+ while (rs.next()) {
239+ retSet.add(rs.getString(1));
240+ }
241+ } catch (Exception e) {
242+ fLogger.error(StringUtil.EMPTY_STRING, e);
243+ return Collections.EMPTY_SET;
244+ } finally {
245+ if (rs != null) {
246+ try {
247+ rs.close();
248+ } catch (SQLException e) {
249+ }
250+ }
251+ if (st != null) {
252+ try {
253+ st.close();
254+ } catch (SQLException e) {
255+ }
256+ }
257+ fLogger.info("end [" + retSet + "]");
258+ capturing = false;
259+ }
260+ return retSet;
261+ }
266262
267- protected void createDBTableDef(GettingResourceRequest request)
268- throws SQLException {
263+ @Override
264+ protected void createDBTableDef(GettingResourceRequest request) throws SQLException {
269265
270- request.beginTask("Grab table defenitions",
271- getRoot().getSchemas().length);
272- if (request.targetType.isOnlySchema()) {
273- IDBSchema target_schema = (IDBSchema) request.selectionResource;
274- createTableResouceSub(request, target_schema);
275- request.worked(1);
276- } else {
277- for (IDBSchema mschema : getRoot().getSchemas()) {
278- createTableResouceSub(request, mschema);
279- request.worked(1);
280- }
281- }
282- }
266+ request.beginTask("Grab table defenitions", getRoot().getSchemas().length);
267+ if (request.targetType.isOnlySchema()) {
268+ IDBSchema target_schema = (IDBSchema) request.selectionResource;
269+ createTableResouceSub(request, target_schema);
270+ request.worked(1);
271+ } else {
272+ for (IDBSchema mschema : getRoot().getSchemas()) {
273+ createTableResouceSub(request, mschema);
274+ request.worked(1);
275+ }
276+ }
277+ }
283278
284- private boolean createTableResouceSub(GettingResourceRequest request,
285- IDBSchema mschema) throws SQLException {
286- ResultSetDataHolder rdh = executePrepareQuery(this.getOrCreateExtraConnection(),
287- SELECT_TABLE_LIST, new String[] { mschema.getName() });
288- for (int i = 0; i < rdh.getRowCount(); i++) {
289- String tableName = rdh.getStringData(i, "TABLE_NAME");
290- String type = rdh.getStringData(i, "TABLE_TYPE").toUpperCase();
291- // TODO: add grab condition
279+ private boolean createTableResouceSub(GettingResourceRequest request, IDBSchema mschema)
280+ throws SQLException {
281+ ResultSetDataHolder rdh = executePrepareQuery(this.getOrCreateExtraConnection(),
282+ SELECT_TABLE_LIST, new String[] {mschema.getName()});
283+ for (int i = 0; i < rdh.getRowCount(); i++) {
284+ String tableName = rdh.getStringData(i, "TABLE_NAME");
285+ String type = rdh.getStringData(i, "TABLE_TYPE").toUpperCase();
286+ // TODO: add grab condition
292287
293- DBTable dbTable = new DBTable(mschema);
294- dbTable.setName(tableName);
295- request.subTask(dbTable.getNameWithAsComment());
296- dbTable.setTableType(type);
297- if (doCaptureColumn(dbTable, request)) {
298- setTableColumns(mschema.getName(), dbTable);
299- }
300- mschema.putTable(dbTable);
288+ DBTable dbTable = new DBTable(mschema);
289+ dbTable.setName(tableName);
290+ request.subTask(dbTable.getNameWithAsComment());
291+ dbTable.setTableType(type);
292+ if (doCaptureColumn(dbTable, request)) {
293+ setTableColumns(mschema.getName(), dbTable);
294+ }
295+ mschema.putTable(dbTable);
301296
302- setResourceProperties(dbTable, i, rdh);
303- if (request.canceld()) {
304- return false;
305- }
306- }
307- return true;
308- }
297+ setResourceProperties(dbTable, i, rdh);
298+ if (request.canceld()) {
299+ return false;
300+ }
301+ }
302+ return true;
303+ }
309304
310- @Override
311- protected void createDBProcedureDef(GettingResourceRequest request)
312- throws SQLException {
313- if (request.targetType.isOnlySchema()) {
314- IDBSchema mschema = (IDBSchema) request.selectionResource;
315- if (createProcedureResouceSub(request, mschema)) {
305+ @Override
306+ protected void createDBProcedureDef(GettingResourceRequest request) throws SQLException {
307+ if (request.targetType.isOnlySchema()) {
308+ IDBSchema mschema = (IDBSchema) request.selectionResource;
309+ if (createProcedureResouceSub(request, mschema)) {
316310
317- }
318- } else {
319- IDBSchema[] schemas = getRoot().getSchemas();
320- request.beginTask("DatabaseMetaData#getProcedures", schemas.length);
321- for (IDBSchema mschema : schemas) {
322- request.worked(1);
323- String sn = mschema.getName();
324- if (isSkipSchemaAtGetAllMetaData(sn)) {
325- continue;
326- }
311+ }
312+ } else {
313+ IDBSchema[] schemas = getRoot().getSchemas();
314+ request.beginTask("DatabaseMetaData#getProcedures", schemas.length);
315+ for (IDBSchema mschema : schemas) {
316+ request.worked(1);
317+ String sn = mschema.getName();
318+ if (isSkipSchemaAtGetAllMetaData(sn)) {
319+ continue;
320+ }
327321
328- createProcedureResouceSub(request, mschema);
322+ createProcedureResouceSub(request, mschema);
329323
330- if (request.canceld()) {
331- break;
332- }
333- }
334- }
335- }
324+ if (request.canceld()) {
325+ break;
326+ }
327+ }
328+ }
329+ }
336330
337- protected boolean createProcedureResouceSub(GettingResourceRequest request,
338- IDBSchema mschema) throws SQLException {
339- ResultSetDataHolder rdh = executePrepareQuery(this.getOrCreateExtraConnection(),
340- SELECT_SCHEMAS_PROCEDURE_LIST,
341- new String[] { mschema.getUName() });
331+ @Override
332+ protected boolean createProcedureResouceSub(GettingResourceRequest request, IDBSchema mschema)
333+ throws SQLException {
334+ ResultSetDataHolder rdh = executePrepareQuery(this.getOrCreateExtraConnection(),
335+ SELECT_SCHEMAS_PROCEDURE_LIST, new String[] {mschema.getUName()});
342336
343- System.out.println(rdh);
337+ System.out.println(rdh);
344338
345- for (int i = 0; i < rdh.getRowCount(); i++) {
346- String tableName = rdh.getStringData(i, "ROUTINE_NAME");
347- String type = rdh.getStringData(i, "ROUTINE_TYPE").toUpperCase();
348- String comment = rdh.getStringData(i, "ROUTINE_COMMENT");
349- String ddl = rdh.getStringData(i, "ROUTINE_DEFINITION");
339+ for (int i = 0; i < rdh.getRowCount(); i++) {
340+ String tableName = rdh.getStringData(i, "ROUTINE_NAME");
341+ String type = rdh.getStringData(i, "ROUTINE_TYPE").toUpperCase();
342+ String comment = rdh.getStringData(i, "ROUTINE_COMMENT");
343+ String ddl = rdh.getStringData(i, "ROUTINE_DEFINITION");
350344
351- if (tableName.indexOf("/") >= 0 || tableName.indexOf("\\") >= 0
352- || tableName.indexOf("BIN$") >= 0) {
345+ if (tableName.indexOf("/") >= 0 || tableName.indexOf("\\") >= 0
346+ || tableName.indexOf("BIN$") >= 0) {
353347
354- continue;
355- }
356- DBTable dbProcudure = new DBTable(mschema);
357- dbProcudure.setName(tableName);
358- dbProcudure.setComment(comment);
359- dbProcudure.setProcedureType(ProcedureType.parse(type));
360- if (dbProcudure.getProcedureType().isProcedureOrUnknown()) {
361- dbProcudure.setTableType(TableType.PROCEDURE);
362- } else {
363- dbProcudure.setTableType(TableType.FUNCTION);
364- }
348+ continue;
349+ }
350+ DBTable dbProcudure = new DBTable(mschema);
351+ dbProcudure.setName(tableName);
352+ dbProcudure.setComment(comment);
353+ dbProcudure.setProcedureType(ProcedureType.parse(type));
354+ if (dbProcudure.getProcedureType().isProcedureOrUnknown()) {
355+ dbProcudure.setTableType(TableType.PROCEDURE);
356+ } else {
357+ dbProcudure.setTableType(TableType.FUNCTION);
358+ }
365359
366- dbProcudure.setText(ddl);
367- if (!request.targetType.isOnlySchema()) {
368- dbProcudure.setResources(getProcedureColumns(mschema.getName(),
369- dbProcudure));
370- }
371- mschema.putProcedure(dbProcudure);
360+ dbProcudure.setText(ddl);
361+ if (!request.targetType.isOnlySchema()) {
362+ dbProcudure.setResources(getProcedureColumns(mschema.getName(), dbProcudure));
363+ }
364+ mschema.putProcedure(dbProcudure);
372365
373- setResourceProperties(dbProcudure, i, rdh);
366+ setResourceProperties(dbProcudure, i, rdh);
374367
375- request.subTask(dbProcudure.toString());
376- if (request.canceld()) {
377- return false;
378- }
379- }
380- return true;
381- }
368+ request.subTask(dbProcudure.toString());
369+ if (request.canceld()) {
370+ return false;
371+ }
372+ }
373+ return true;
374+ }
382375
383- @Override
384- public Set<String> getTables(String schema) {
385- PreparedStatement pre = null;
386- ResultSet rsC = null;
387- try {
388- notifyExecute(this.getOrCreateExtraConnection(), SQLExecutionStatus.GET_META_TABLE);
389- capturing = true;
390- pre = this.getOrCreateExtraConnection()
391- .prepareStatement(
392- "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_TYPE='BASE TABLE'",
393- ResultSet.TYPE_FORWARD_ONLY,
394- ResultSet.CONCUR_READ_ONLY);
395- pre.setString(1, schema);
396- rsC = pre.executeQuery();
397- Set<String> retSet = new TreeSet<String>();
398- while (rsC.next()) {
399- retSet.add(rsC.getString("TABLE_NAME"));
400- }
401- return retSet;
402- } catch (Exception e) {
403- fLogger.error(StringUtil.EMPTY_STRING, e);
404- return Collections.EMPTY_SET;
405- } finally {
406- fLogger.info("end"); //$NON-NLS-1$
407- capturing = false;
408- try {
409- if (rsC != null) {
410- rsC.close();
411- }
412- if (pre != null) {
413- pre.close();
414- }
415- } catch (SQLException e) {
416- }
417- }
418- }
376+ @Override
377+ public Set<String> getTables(String schema) {
378+ PreparedStatement pre = null;
379+ ResultSet rsC = null;
380+ try {
381+ notifyExecute(this.getOrCreateExtraConnection(), SQLExecutionStatus.GET_META_TABLE);
382+ capturing = true;
383+ pre = this.getOrCreateExtraConnection().prepareStatement(
384+ "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_TYPE='BASE TABLE'",
385+ ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
386+ pre.setString(1, schema);
387+ rsC = pre.executeQuery();
388+ Set<String> retSet = new TreeSet<String>();
389+ while (rsC.next()) {
390+ retSet.add(rsC.getString("TABLE_NAME"));
391+ }
392+ return retSet;
393+ } catch (Exception e) {
394+ fLogger.error(StringUtil.EMPTY_STRING, e);
395+ return Collections.EMPTY_SET;
396+ } finally {
397+ fLogger.info("end"); //$NON-NLS-1$
398+ capturing = false;
399+ try {
400+ if (rsC != null) {
401+ rsC.close();
402+ }
403+ if (pre != null) {
404+ pre.close();
405+ }
406+ } catch (SQLException e) {
407+ }
408+ }
409+ }
419410
420- @Override
421- protected boolean setTableText(GettingResourceRequest request)
422- throws SQLException {
423- boolean retCode = true;
424- ResultSetDataHolder rdh = null;
411+ @Override
412+ protected boolean setTableText(GettingResourceRequest request) throws SQLException {
413+ boolean retCode = true;
414+ ResultSetDataHolder rdh = null;
425415
426- String show_query = null;
427- if (request.targetType.isOnlySelectedResouce()) {
428- request.beginTask(String.format("SCHEMA[%s] GET_DDL ",
429- request.selectionResource.getName()), 3);
430- if (request.selectionResource instanceof IDBTable) {
431- IDBTable tbl = (IDBTable) request.selectionResource;
416+ String show_query = null;
417+ if (request.targetType.isOnlySelectedResouce()) {
418+ request.beginTask(
419+ String.format("SCHEMA[%s] GET_DDL ", request.selectionResource.getName()), 3);
420+ if (request.selectionResource instanceof IDBTable) {
421+ IDBTable tbl = (IDBTable) request.selectionResource;
432422
433- if (tbl.isTable()) {
434- show_query = String.format("show create table %s", tbl
435- .getParent().getNameWithParentName());
436- } else {
437- show_query = String.format("show create view %s", tbl
438- .getParent().getNameWithParentName());
439- }
440- rdh = executePrepareQuery(this.getOrCreateExtraConnection(), show_query,
441- StringUtil.EMPTY_STRING_ARRAY);
442- if (rdh.getRowCount() > 0) {
443- tbl.setText(rdh.getStringRecordRow(0)[2].getString());
444- } else {
445- retCode = false;
446- }
447- }
448- return retCode;
449- }
450- IDBSchema[] schemas = getRoot().getSchemas();
423+ if (tbl.isTable()) {
424+ show_query = String.format("show create table %s", tbl.getNameWithParentName());
425+ } else {
426+ show_query = String.format("show create view %s", tbl.getNameWithParentName());
427+ }
428+ rdh = executePrepareQuery(this.getOrCreateExtraConnection(), show_query,
429+ StringUtil.EMPTY_STRING_ARRAY);
430+ if (rdh.getRowCount() > 0) {
431+ tbl.setText(rdh.getStringRecordRow(0)[2].getString());
432+ } else {
433+ retCode = false;
434+ }
435+ }
436+ return retCode;
437+ }
438+ IDBSchema[] schemas = getRoot().getSchemas();
451439
452- for (int i = 0; i < schemas.length; i++) {
453- List<IDBTable> tableSet = schemas[i]
454- .getTablesList(TableType.TABLE_OR_VIEW_OR_PROCEDURE_OR_FUNCTION_SET);
440+ for (int i = 0; i < schemas.length; i++) {
441+ List<IDBTable> tableSet =
442+ schemas[i].getTablesList(TableType.TABLE_OR_VIEW_OR_PROCEDURE_OR_FUNCTION_SET);
455443
456- IDBTable[] prs = schemas[i].getTableOrSystemTables();
457- request.beginTask(
458- String.format("SCHEMA[%s] GET_DDL ", schemas[i].getName()),
459- tableSet.size());
460- for (IDBTable tbl : prs) {
461- request.subTask(String.format("%s[%s]", tbl.getTableType(),
462- tbl.getName()));
463- setDDLToTable(schemas[i], tbl);
464- request.worked(1);
465- }
466- // IDBTrigger[] trg = schemas[i].getTriggers();
467- // request.beginTask(
468- // String.format("SCHEMA[%s] GET_DDL TRIGGERS ",
469- // schemas[i].getName()), trg.length);
470- // for (int j = 0; j < trg.length; j++) {
471- // request.subTask(String.format("TRIGGER[%s]", trg[j].getName()));
472- // rdh = executePrepareQuery(
473- // this.getOrCreateExtraConnection(),
474- // SELECT_GET_DDL,
475- // new String[] { "TRIGGER", trg[j].getUName(),
476- // schemas[i].getUName() });
477- // if (rdh.getRowCount() > 0) {
478- // trg[j].setText(rdh.getStringData(0, "TEXT"));
479- // }
480- // request.worked(1);
481- // }
482- }
483- return retCode;
484- }
444+ IDBTable[] prs = schemas[i].getTableOrSystemTables();
445+ request.beginTask(String.format("SCHEMA[%s] GET_DDL ", schemas[i].getName()),
446+ tableSet.size());
447+ for (IDBTable tbl : prs) {
448+ request.subTask(String.format("%s[%s]", tbl.getTableType(), tbl.getName()));
449+ setDDLToTable(schemas[i], tbl);
450+ request.worked(1);
451+ }
452+ // IDBTrigger[] trg = schemas[i].getTriggers();
453+ // request.beginTask(
454+ // String.format("SCHEMA[%s] GET_DDL TRIGGERS ",
455+ // schemas[i].getName()), trg.length);
456+ // for (int j = 0; j < trg.length; j++) {
457+ // request.subTask(String.format("TRIGGER[%s]", trg[j].getName()));
458+ // rdh = executePrepareQuery(
459+ // this.getOrCreateExtraConnection(),
460+ // SELECT_GET_DDL,
461+ // new String[] { "TRIGGER", trg[j].getUName(),
462+ // schemas[i].getUName() });
463+ // if (rdh.getRowCount() > 0) {
464+ // trg[j].setText(rdh.getStringData(0, "TEXT"));
465+ // }
466+ // request.worked(1);
467+ // }
468+ }
469+ return retCode;
470+ }
485471
486- private boolean setDDLToTable(IDBSchema schema, IDBTable tbl)
487- throws SQLException {
488- String show_query = null;
489- switch (tbl.getTableType()) {
490- case TABLE:
491- case SYSTEM_TABLE:
492- show_query = String.format("show create table %s.%s",
493- schema.getName(), tbl.getName());
494- break;
495- case VIEW:
496- show_query = String.format("show create view %s.%s",
497- schema.getName(), tbl.getName());
498- break;
499- case FUNCTION:
500- show_query = String.format("show create function %s.%s",
501- schema.getName(), tbl.getName());
502- break;
503- case PROCEDURE:
504- show_query = String.format("show create procedure %s.%s",
505- schema.getName(), tbl.getName());
506- break;
507- }
508- ResultSetDataHolder2 rdh = executePrepareQuery(this.getOrCreateExtraConnection(), show_query,
509- StringUtil.EMPTY_STRING_ARRAY);
510- if (rdh.getRowCount() > 0) {
511- tbl.setText(rdh.getStringRecordRow(0)[2].getString());
512- return true;
513- }
514- return false;
515- }
472+ private boolean setDDLToTable(IDBSchema schema, IDBTable tbl) throws SQLException {
473+ String show_query = null;
474+ switch (tbl.getTableType()) {
475+ case TABLE:
476+ case SYSTEM_TABLE:
477+ show_query =
478+ String.format("show create table %s.%s", schema.getName(), tbl.getName());
479+ break;
480+ case VIEW:
481+ show_query =
482+ String.format("show create view %s.%s", schema.getName(), tbl.getName());
483+ break;
484+ case FUNCTION:
485+ show_query = String.format("show create function %s.%s", schema.getName(),
486+ tbl.getName());
487+ break;
488+ case PROCEDURE:
489+ show_query = String.format("show create procedure %s.%s", schema.getName(),
490+ tbl.getName());
491+ break;
492+ }
493+ ResultSetDataHolder2 rdh = executePrepareQuery(this.getOrCreateExtraConnection(),
494+ show_query, StringUtil.EMPTY_STRING_ARRAY);
495+ if (rdh.getRowCount() > 0) {
496+ tbl.setText(rdh.getStringRecordRow(0)[2].getString());
497+ return true;
498+ }
499+ return false;
500+ }
516501
517- @Override
518- protected void getTrigger(GettingResourceRequest request)
519- throws SQLException {
520- fLogger.fatal("Not support yet...");
521- }
502+ @Override
503+ protected void getTrigger(GettingResourceRequest request) throws SQLException {
504+ fLogger.fatal("Not support yet...");
505+ }
522506
523- public static String getLimitString() {
524- return "LIMIT 0, 30";
525- }
507+ public static String getLimitString() {
508+ return "LIMIT 0, 30";
509+ }
526510
527- @Override
528- protected void getSequence(GettingResourceRequest request)
529- throws SQLException {
530- fLogger.fatal("Not support yet...");
511+ @Override
512+ protected void getSequence(GettingResourceRequest request) throws SQLException {
513+ fLogger.fatal("Not support yet...");
531514
532- }
515+ }
533516
534-}
\ No newline at end of file
517+}
旧リポジトリブラウザで表示