- Timestamp:
- 2013-05-08T11:10:33+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DerbyWrapper.java
r26911 r27316 19 19 package org.greenstone.gsdl3.util; 20 20 21 import javax.swing.*;22 23 import org.greenstone.gsdl3.service.Authentication;24 25 import java.io.File;26 21 import java.sql.Connection; 27 22 import java.sql.DriverManager; 28 23 import java.sql.ResultSet; 29 24 import java.sql.SQLException; 30 import java.sql.SQLWarning;31 25 import java.sql.Statement; 32 26 import java.util.ArrayList; 33 27 import java.util.HashMap; 34 import java.util.Properties; 28 29 import org.greenstone.gsdl3.service.Authentication; 35 30 36 31 public class DerbyWrapper … … 87 82 public void closeDatabase() 88 83 { 89 84 //state = null; 90 85 //conn = null; 91 86 boolean gotSQLExc = false; 92 87 try 93 94 95 96 97 88 { 89 // shutdown the database 90 DriverManager.getConnection(protocol_str + ";shutdown=true"); 91 92 } 98 93 catch (SQLException se) 99 94 { 100 // this is good (i.e. what Derby is designed to do on a successful shutdown) 101 gotSQLExc = true; 102 } 103 catch (Exception e) { 104 e.printStackTrace(); 95 // this is good (i.e. what Derby is designed to do on a successful shutdown) 96 gotSQLExc = true; 97 } 98 catch (Exception e) 99 { 100 e.printStackTrace(); 105 101 } 106 102 107 103 if (!gotSQLExc) 108 104 { 109 System.err.println("Warning: Derby Database did not shut down normally"); 110 } 111 } 112 113 public static void shutdownDatabaseServer() 114 { 115 boolean gotSQLExc = false; 116 117 try { 118 // shutdown the whole server 119 DriverManager.getConnection(PROTOCOL + ";shutdown=true"); 120 121 } 122 catch (SQLException se) { 123 // this is good (i.e. what Derby is designed to do on a successful shutdown) 124 gotSQLExc = true; 125 //System.out.println("Shutdown returned: " + se); 126 } 127 catch (Exception e) { 128 129 e.printStackTrace(); 130 } 131 if (!gotSQLExc) { 132 System.err.println("Warning: Derby did not shut down normally"); 133 } 134 135 } 105 System.err.println("Warning: Derby Database did not shut down normally"); 106 } 107 } 108 109 public static void shutdownDatabaseServer() 110 { 111 boolean gotSQLExc = false; 112 113 try 114 { 115 // shutdown the whole server 116 DriverManager.getConnection(PROTOCOL + ";shutdown=true"); 117 118 } 119 catch (SQLException se) 120 { 121 // this is good (i.e. what Derby is designed to do on a successful shutdown) 122 gotSQLExc = true; 123 //System.out.println("Shutdown returned: " + se); 124 } 125 catch (Exception e) 126 { 127 128 e.printStackTrace(); 129 } 130 if (!gotSQLExc) 131 { 132 System.err.println("Warning: Derby did not shut down normally"); 133 } 134 135 } 136 136 137 137 public void createDatabase() … … 375 375 } 376 376 377 378 377 // findUser(null) will return all users, which is why a UserQueryResult 378 // (a vector of UserTermInfo) is returned 379 379 public UserQueryResult findUser(String username) throws SQLException 380 380 { … … 443 443 conn.setAutoCommit(false); 444 444 String sql_modify_user_info = "update " + USERS + " set "; 445 445 446 446 boolean needComma = false; 447 447 if (new_password != null && !new_password.equals("")) … … 456 456 needComma = true; 457 457 } 458 459 if (email != null)458 459 if (email != null) 460 460 { 461 461 sql_modify_user_info += (needComma ? "," : "") + " email='" + email + "'"; 462 462 } 463 463 464 464 sql_modify_user_info += " where username='" + username + "'"; 465 465 state.execute(sql_modify_user_info); … … 496 496 public void db2txt() 497 497 { 498 System.err.println(db2txtString());498 System.err.println(db2txtString()); 499 499 } 500 500 501 501 public String db2txtString() 502 502 { 503 504 505 try 506 { 507 508 509 510 511 503 //String db2txt = "Error in converting db2txt string."; 504 String db2txt = ""; 505 try 506 { 507 conn.setAutoCommit(false); // An exception at this line can happen when the GS3 tomcat server is already running 508 // and GS3 is already accessing the usersDB when this function independently tries to 509 // connect to it (via usersDB2txt.java's main(). For an explanation of the possible 510 // reasons, see http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html 511 // section "Embedded Derby supports multiple users in one JVM". 512 512 String sql_list_all_user = "select username, password, accountstatus, comment, email from " + USERS; 513 513 ResultSet rs = state.executeQuery(sql_list_all_user); … … 541 541 } 542 542 conn.commit(); 543 543 544 544 buffer.append("USERNAME = " + user.get("username")); 545 545 buffer.append("\nPASSWORD = " + user.get("password")); … … 548 548 buffer.append("\nCOMMENT = " + user.get("comment")); 549 549 buffer.append("\nEMAIL = " + user.get("email")); 550 buffer.append("\n-------------------------------------\n"); 550 buffer.append("\n-------------------------------------\n"); 551 551 } 552 552 db2txt = buffer.toString(); … … 558 558 { 559 559 ex.printStackTrace(); 560 } finally { 561 return db2txt; 560 } 561 finally 562 { 563 return db2txt; 562 564 } 563 565 }
Note:
See TracChangeset
for help on using the changeset viewer.