クラス org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole

org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsoleに対する継承グラフ

Inheritance graph
[凡例]
org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsoleのコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

説明

C-JDBC Controller Virtual Database Console module.

作者:
Emmanuel Cecchet

Mathieu Peltier

Nicolas Modrzyk

バージョン:
1.0

VirtualDatabaseConsole.java52 行で定義されています。

Public メソッド

 VirtualDatabaseConsole (Console console)
Connection getConnection (String url, String login, String password) throws ConsoleException
void displayResultSet (ResultSet rs) throws SQLException
synchronized void callStoredProcedure (String proc, boolean displayResult)
synchronized void execSQL (String request, boolean displayResult)
void showtables ()
void load (String fileName)
void help ()
void handlePrompt ()
String getDescriptionString ()
String getPromptString ()
void login (String[] params) throws Exception
void quit ()

Protected メソッド

void loadCommands ()

Private メソッド

void displaySeparatorLine (int columnCount, ResultSetMetaData meta) throws SQLException
void displayPad (String text, int size)

Private 変数

Connection connection = null
int timeout = 60
int fetchsize = 0
int maxrows = 0
String login
String url

Static Private 変数

final int MAX_COLUMN_DISPLAY_WIDTH = 25


コンストラクタとデストラクタ

org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.VirtualDatabaseConsole Console  console  ) 
 

Creates a new VirtualDatabaseAdmin instance. Loads the driver

引数:
console console console
VirtualDatabaseConsole.java75 行で定義されています。

参照先 org.objectweb.cjdbc.console.text.Console.printError(), と org.objectweb.cjdbc.console.text.Console.println().

00076 { 00077 super(console); 00078 try 00079 { 00080 Class.forName("org.objectweb.cjdbc.driver.Driver"); 00081 } 00082 catch (Exception e) 00083 { 00084 console.printError(ConsoleTranslate 00085 .get("sql.login.cannot.load.driver", e), e); 00086 Runtime.getRuntime().exit(1); 00087 } 00088 console.println(ConsoleTranslate.get("sql.login.loaded.driver", 00089 Constants.VERSION)); 00090 }


メソッド

synchronized void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.callStoredProcedure String  proc,
boolean  displayResult
 

Call a store procedure.

引数:
proc the stored procedure to call
displayResult true if the result must be printed on the standard output
VirtualDatabaseConsole.java236 行で定義されています。
00238 { 00239 CallableStatement cs = null; 00240 try 00241 { 00242 cs = connection.prepareCall(proc); 00243 cs.setQueryTimeout(timeout); 00244 00245 long start = System.currentTimeMillis(); 00246 long end; 00247 ResultSet rs = cs.executeQuery(); 00248 end = System.currentTimeMillis(); 00249 if (displayResult) 00250 displayResultSet(rs); 00251 console.println(ConsoleTranslate.get("sql.display.query.time", 00252 new Long[]{new Long((end - start) / 1000), 00253 new Long((end - start) % 1000)})); 00254 } 00255 catch (Exception e) 00256 { 00257 console.printError(ConsoleTranslate.get( 00258 "sql.command.storeProcedure.error", e), e); 00259 } 00260 finally 00261 { 00262 try 00263 { 00264 cs.close(); 00265 } 00266 catch (Exception ignore) 00267 { 00268 } 00269 } 00270 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.displayPad String  text,
int  size
[private]
 

VirtualDatabaseConsole.java133 行で定義されています。

00134 { 00135 if (size > MAX_COLUMN_DISPLAY_WIDTH) 00136 size = MAX_COLUMN_DISPLAY_WIDTH; 00137 if (size < text.length()) 00138 { 00139 console.print(text.substring(0, size - 1) + "~"); 00140 return; 00141 } 00142 StringBuffer toPad = new StringBuffer(size); 00143 toPad.insert(0, text); 00144 while (toPad.length() < size) 00145 toPad.append(' '); 00146 console.print(toPad.toString()); 00147 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.displayResultSet ResultSet  rs  )  throws SQLException
 

Display the given ResultSet.

引数:
rs the ResultSet to display
例外:
SQLException if an error occurs
VirtualDatabaseConsole.java155 行で定義されています。
00156 { 00157 // Get the metadata 00158 ResultSetMetaData meta = rs.getMetaData(); 00159 int columnCount = meta.getColumnCount(); 00160 00161 displaySeparatorLine(columnCount, meta); 00162 00163 // Print the column names 00164 console.print("|"); 00165 for (int i = 1; i <= columnCount; i++) 00166 { 00167 console.print(" "); 00168 // Pad the column name and print it 00169 int size = meta.getColumnDisplaySize(i); 00170 String columnName = meta.getColumnName(i); 00171 if (size <= 0) 00172 { 00173 if (columnName != null) 00174 size = columnName.length(); 00175 else 00176 size = 0; 00177 } 00178 displayPad(columnName, size); 00179 console.print(" |"); 00180 } 00181 console.println(); 00182 00183 displaySeparatorLine(columnCount, meta); 00184 00185 // Display the results 00186 Object object; 00187 int line = 0; 00188 while (rs.next()) 00189 { 00190 console.print("|"); 00191 for (int i = 1; i <= columnCount; i++) 00192 { 00193 console.print(" "); 00194 object = rs.getObject(i); 00195 String value = (object != null) ? rs.getObject(i).toString() : ""; 00196 // Pad the value and print it 00197 int size = meta.getColumnDisplaySize(i); 00198 if (size <= 0) 00199 { 00200 if (value != null) 00201 size = value.length(); 00202 else 00203 size = 0; 00204 } 00205 displayPad(value, size); 00206 console.print(" |"); 00207 } 00208 console.println(""); 00209 line++; 00210 if (fetchsize != 0) 00211 { 00212 if (line % fetchsize == 0) 00213 { 00214 try 00215 { 00216 console.readLine(ConsoleTranslate.get("sql.display.next.rows", 00217 new Integer[]{new Integer(fetchsize), new Integer(line)})); 00218 } 00219 catch (ConsoleException ignore) 00220 { 00221 } 00222 } 00223 } 00224 } 00225 00226 displaySeparatorLine(columnCount, meta); 00227 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.displaySeparatorLine int  columnCount,
ResultSetMetaData  meta
throws SQLException [private]
 

VirtualDatabaseConsole.java115 行で定義されています。

00117 { 00118 00119 console.print("+"); 00120 for (int i = 1; i <= columnCount; i++) 00121 { 00122 int size = meta.getColumnDisplaySize(i); 00123 if (size > MAX_COLUMN_DISPLAY_WIDTH) 00124 size = MAX_COLUMN_DISPLAY_WIDTH; 00125 console.print("-"); 00126 for (int j = 0; j < size; j++) 00127 console.print("-"); 00128 console.print("-+"); 00129 } 00130 console.println(); 00131 }

synchronized void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.execSQL String  request,
boolean  displayResult
 

Executes a SQL statement.

引数:
request the SQL request to execute
displayResult true if the result must be printed on the standard output
VirtualDatabaseConsole.java279 行で定義されています。
00280 { 00281 PreparedStatement stmt = null; 00282 try 00283 { 00284 stmt = connection.prepareStatement(request); 00285 stmt.setQueryTimeout(timeout); 00286 if (fetchsize != 0) 00287 stmt.setFetchSize(fetchsize); 00288 if (maxrows != 0) 00289 stmt.setMaxRows(maxrows); 00290 00291 long start = System.currentTimeMillis(); 00292 long end; 00293 if (request.regionMatches(true, 0, "select ", 0, 7)) 00294 { 00295 ResultSet rs = stmt.executeQuery(); 00296 end = System.currentTimeMillis(); 00297 if (displayResult) 00298 displayResultSet(rs); 00299 } 00300 else 00301 { 00302 int result = stmt.executeUpdate(); 00303 end = System.currentTimeMillis(); 00304 if (displayResult) 00305 console.println(ConsoleTranslate.get("sql.display.affected.rows", 00306 result)); 00307 } 00308 console.println(ConsoleTranslate.get("sql.display.query.time", 00309 new Long[]{new Long((end - start) / 1000), new Long((end - start) % 1000)})); 00310 } 00311 catch (Exception e) 00312 { 00313 console.printError(ConsoleTranslate.get("sql.command.sqlquery.error", e), 00314 e); 00315 } 00316 finally 00317 { 00318 try 00319 { 00320 stmt.close(); 00321 } 00322 catch (Exception ignore) 00323 { 00324 } 00325 } 00326 }

Connection org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.getConnection String  url,
String  login,
String  password
throws ConsoleException
 

Gets a new connection from the driver.

引数:
url the C-JDBC url
login the login to use to open the connection
password the password to use to open the connection
戻り値:
a new connection
例外:
ConsoleException if login failed
VirtualDatabaseConsole.java101 行で定義されています。

参照先 org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.login, と org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.url.

00103 { 00104 try 00105 { 00106 return DriverManager.getConnection(url, login, password); 00107 } 00108 catch (Exception e) 00109 { 00110 throw new ConsoleException(ConsoleTranslate.get("sql.login.connection.failed", 00111 new String[]{url, e.getMessage()})); 00112 } 00113 }

String org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.getDescriptionString  )  [virtual]
 

参照:
org.objectweb.cjdbc.console.text.module.AbstractConsoleModule.getDescriptionString()

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを実装しています.

VirtualDatabaseConsole.java556 行で定義されています。

00557 { 00558 return "SQL Console"; 00559 }

String org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.getPromptString  )  [virtual]
 

参照:
org.objectweb.cjdbc.console.text.module.AbstractConsoleModule.getPromptString()

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを実装しています.

VirtualDatabaseConsole.java564 行で定義されています。

00565 { 00566 int ind1 = url.lastIndexOf('?'); 00567 int ind2 = url.lastIndexOf(';'); 00568 if (ind1 != -1 || ind2 != -1) 00569 { 00570 String prompt; 00571 prompt = (ind1 != -1) ? url.substring(0, ind1) : url; 00572 prompt = (ind2 != -1) ? url.substring(0, ind2) : url; 00573 return prompt + " (" + login + ")"; 00574 } 00575 else 00576 return url + " (" + login + ")"; 00577 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.handlePrompt  ) 
 

Connects to a virtual database.

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを再定義しています。

VirtualDatabaseConsole.java442 行で定義されています。

00443 { 00444 boolean quit = false; 00445 while (!quit) 00446 { 00447 try 00448 { 00449 String cmd = console.readLine(this.getPromptString()); 00450 if (cmd == null) 00451 cmd = "quit"; 00452 00453 if (cmd.length() == 0) 00454 continue; 00455 00456 if (cmd.equalsIgnoreCase("begin")) 00457 { 00458 connection.setAutoCommit(false); 00459 console.println(ConsoleTranslate 00460 .get("sql.display.transaction.started")); 00461 } 00462 else if (cmd.equalsIgnoreCase("commit")) 00463 { 00464 connection.commit(); 00465 connection.setAutoCommit(true); 00466 } 00467 else if (cmd.equalsIgnoreCase("rollback")) 00468 { 00469 connection.rollback(); 00470 connection.setAutoCommit(true); 00471 } 00472 else if (cmd.equalsIgnoreCase("showtables")) 00473 { 00474 showtables(); 00475 } 00476 else if (cmd.toLowerCase().startsWith("{call")) 00477 { 00478 callStoredProcedure(cmd, true); 00479 } 00480 else if (cmd.toLowerCase().startsWith("load")) 00481 { 00482 cmd = cmd.substring(4).trim(); 00483 load(cmd); 00484 } 00485 else if (cmd.toLowerCase().startsWith("fetchsize")) 00486 { 00487 cmd = cmd.substring(9).trim(); 00488 try 00489 { 00490 fetchsize = new Integer(cmd).intValue(); 00491 console.println(ConsoleTranslate.get("sql.display.new.fetchsize", 00492 fetchsize)); 00493 } 00494 catch (NumberFormatException e) 00495 { 00496 console.printError(ConsoleTranslate.get( 00497 "sql.display.new.fetchsize.failed", e), e); 00498 } 00499 } 00500 else if (cmd.toLowerCase().startsWith("maxrows")) 00501 { 00502 cmd = cmd.substring(7).trim(); 00503 try 00504 { 00505 maxrows = new Integer(cmd).intValue(); 00506 console.println(ConsoleTranslate.get("sql.display.new.maxrows", 00507 maxrows)); 00508 } 00509 catch (NumberFormatException e) 00510 { 00511 console.printError(ConsoleTranslate.get( 00512 "sql.display.new.maxrows.failed", e), e); 00513 } 00514 } 00515 else if (cmd.toLowerCase().startsWith("timeout")) 00516 { 00517 cmd = cmd.substring(7).trim(); 00518 try 00519 { 00520 timeout = new Integer(cmd).intValue(); 00521 console.println(ConsoleTranslate.get("sql.display.new.timeout", 00522 timeout)); 00523 } 00524 catch (NumberFormatException e) 00525 { 00526 console.printError(ConsoleTranslate.get( 00527 "sql.display.new.timeout.failed", e), e); 00528 } 00529 } 00530 else if (cmd.equalsIgnoreCase("help")) 00531 help(); 00532 else if (cmd.equalsIgnoreCase("quit")) 00533 { 00534 quit = true; 00535 if (connection != null) 00536 connection.close(); 00537 } 00538 else 00539 // Consider it is an SQL statement 00540 execSQL(cmd, true); 00541 } 00542 catch (Exception e) 00543 { 00544 console.printError(ConsoleTranslate.get("sql.login.exception", e), e); 00545 if (e instanceof RuntimeException) 00546 { 00547 System.exit(0); 00548 } 00549 } 00550 } 00551 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.help  ) 
 

Displays help message.

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを再定義しています。

VirtualDatabaseConsole.java410 行で定義されています。

00411 { 00412 console.println(ConsoleTranslate.get("module.commands.available", 00413 getDescriptionString())); 00414 console.println(" begin"); 00415 console.println(" " + ConsoleTranslate.get("sql.command.begin")); 00416 console.println(" commit"); 00417 console.println(" " + ConsoleTranslate.get("sql.command.commit")); 00418 console.println(" fetchsize x"); 00419 console.println(" " + ConsoleTranslate.get("sql.command.fetchsize")); 00420 console.println(" help"); 00421 console.println(" " + ConsoleTranslate.get("console.command.help")); 00422 console.println(" load <file>"); 00423 console.println(" " + ConsoleTranslate.get("sql.command.load")); 00424 console.println(" maxrows x"); 00425 console.println(" " + ConsoleTranslate.get("sql.command.maxrows")); 00426 console.println(" quit"); 00427 console.println(" " + ConsoleTranslate.get("sql.command.quit")); 00428 console.println(" rollback"); 00429 console.println(" " + ConsoleTranslate.get("sql.command.rollback")); 00430 console.println(" showtables"); 00431 console.println(" " + ConsoleTranslate.get("sql.command.showtables")); 00432 console.println(" timeout x"); 00433 console.println(" " + ConsoleTranslate.get("sql.command.timeout")); 00434 console.println(" {call proc_name(?,?,...)}"); 00435 console.println(" " + ConsoleTranslate.get("sql.command.procedure")); 00436 console.println(ConsoleTranslate.get("sql.command.other")); 00437 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.load String  fileName  ) 
 

Executes all the SQL requests contained in the specified file.

引数:
fileName the file name to open
VirtualDatabaseConsole.java354 行で定義されています。
00355 { 00356 BufferedReader file = null; 00357 try 00358 { 00359 file = new BufferedReader(new FileReader(fileName)); 00360 } 00361 catch (Exception e) 00362 { 00363 console.printError( 00364 ConsoleTranslate.get("sql.command.load.file.error", e), e); 00365 return; 00366 } 00367 00368 console.println(ConsoleTranslate.get("sql.command.loading.file", fileName)); 00369 try 00370 { 00371 String request; 00372 00373 while ((request = file.readLine()) != null) 00374 { 00375 request = request.trim(); 00376 console.println(request); 00377 00378 if (request.equalsIgnoreCase("begin")) 00379 connection.setAutoCommit(false); 00380 else if (request.equalsIgnoreCase("commit")) 00381 connection.commit(); 00382 else if (request.equalsIgnoreCase("rollback")) 00383 connection.rollback(); 00384 else 00385 { // Regular SQL request 00386 execSQL(request, false); 00387 } 00388 } 00389 } 00390 catch (Exception e) 00391 { 00392 console.printError(ConsoleTranslate.get("sql.command.load.execute.error", 00393 e), e); 00394 } 00395 finally 00396 { 00397 try 00398 { 00399 file.close(); 00400 } 00401 catch (IOException ignore) 00402 { 00403 } 00404 } 00405 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.loadCommands  )  [protected, virtual]
 

参照:
org.objectweb.cjdbc.console.text.module.AbstractConsoleModule.loadCommands()

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを実装しています.

VirtualDatabaseConsole.java582 行で定義されています。

00583 { 00584 00585 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.login String[]  params  )  throws Exception [virtual]
 

参照:
org.objectweb.cjdbc.console.text.module.AbstractConsoleModule.login(java.lang.String[])

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを実装しています.

VirtualDatabaseConsole.java590 行で定義されています。

00591 { 00592 login = null; 00593 url = (params.length > 0 && params[0] != null) ? params[0].trim() : null; 00594 try 00595 { 00596 if ((url == null) || url.trim().equals("")) 00597 { 00598 url = console.readLine(ConsoleTranslate.get("sql.login.prompt.url")); 00599 if (url == null) 00600 return; 00601 } 00602 login = console.readLine(ConsoleTranslate.get("sql.login.prompt.user")); 00603 if (login == null) 00604 return; 00605 String password = console.readPassword(ConsoleTranslate 00606 .get("sql.login.prompt.password")); 00607 if (password == null) 00608 return; 00609 00610 connection = getConnection(url, login, password); 00611 } 00612 catch (Exception e) 00613 { 00614 throw new ConsoleException(ConsoleTranslate.get("sql.login.exception", e)); 00615 } 00616 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.quit  ) 
 

参照:
org.objectweb.cjdbc.console.text.module.AbstractConsoleModule.quit()

org.objectweb.cjdbc.console.text.module.AbstractConsoleModuleを再定義しています。

VirtualDatabaseConsole.java621 行で定義されています。

00622 { 00623 quit = true; 00624 if (connection != null) 00625 { 00626 try 00627 { 00628 connection.close(); 00629 } 00630 catch (Exception e) 00631 { 00632 // ignore 00633 } 00634 } 00635 }

void org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.showtables  ) 
 

Display all tables of this virtual database VirtualDatabaseConsole.java329 行で定義されています。

00330 { 00331 try 00332 { 00333 DatabaseMetaData dbmd = connection.getMetaData(); 00334 ResultSet tableSet = dbmd.getTables(null, null, null, null); 00335 while (!tableSet.isLast()) 00336 { 00337 tableSet.next(); 00338 console.println(tableSet.getString(tableSet.findColumn("TABLE_NAME"))); 00339 } 00340 } 00341 catch (Exception e) 00342 { 00343 console.printError(ConsoleTranslate.get("sql.command.sqlquery.error", e), 00344 e); 00345 } 00346 00347 }


変数

Connection org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.connection = null [private]
 

VirtualDatabaseConsole.java58 行で定義されています。

int org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.fetchsize = 0 [private]
 

VirtualDatabaseConsole.java63 行で定義されています。

String org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.login [private]
 

VirtualDatabaseConsole.java67 行で定義されています。

参照元 org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.getConnection(), と org.objectweb.cjdbc.console.text.commands.controller.Connect.parse().

final int org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.MAX_COLUMN_DISPLAY_WIDTH = 25 [static, private]
 

Max column width when displaying a ResultSet. VirtualDatabaseConsole.java56 行で定義されています。

int org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.maxrows = 0 [private]
 

VirtualDatabaseConsole.java65 行で定義されています。

int org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.timeout = 60 [private]
 

Default query timeout. VirtualDatabaseConsole.java61 行で定義されています。

String org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.url [private]
 

VirtualDatabaseConsole.java67 行で定義されています。

参照元 org.objectweb.cjdbc.console.text.module.VirtualDatabaseConsole.getConnection().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:33 2004に生成されました。 doxygen 1.3.8