Set the new database settings in temporary fields, then on shutdown, move them into the actual configuration settings just before save, and delete the jbidwatcher.created_db setting, so next reload it will use the new database, and load the auctions.xml into it.
- M jbidwatcher/trunk/src/com/jbidwatcher/app/MacFriendlyFrame.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/ui/config/JConfigDatabaseTab.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/util/db/Database.java view
| 751 | 951 | |
|---|---|---|
| 3 | 3 | import com.jbidwatcher.util.config.JConfig; |
| 4 | 4 | import com.jbidwatcher.util.queue.MQFactory; |
| 5 | 5 | import com.jbidwatcher.util.db.ActiveRecord; |
| 6 | import com.jbidwatcher.util.db.Database; | |
| 6 | 7 | import com.jbidwatcher.util.Constants; |
| 7 | 8 | import com.jbidwatcher.auction.server.AuctionStats; |
| 8 | 9 | import com.jbidwatcher.auction.server.AuctionServerManager; |
| --- | --- | |
| 171 | 172 | SearchManager.getInstance().saveSearches(); |
| 172 | 173 | AuctionStats as = AuctionServerManager.getInstance().getStats(); |
| 173 | 174 | JConfig.setConfiguration("last.auctioncount", Integer.toString(as.getCount())); |
| 175 | Database.saveDBConfig(); | |
| 174 | 176 | JConfig.saveConfiguration(cfgFilename); |
| 175 | ActiveRecord.shutdown(); | |
| 177 | ActiveRecord.shutdown(); // TODO -- Can this be put before the saveDBConfig? | |
| 176 | 178 | JConfig.log().logMessage("Shutting down JBidwatcher."); |
| 177 | 179 | JConfig.log().closeLog(); |
| 178 | 180 | System.exit(0); |
| 948 | 951 | |
|---|---|---|
| 74 | 74 | JConfig.kill("db.pass"); |
| 75 | 75 | } else if (mysqlDB.isSelected()) { |
| 76 | 76 | String host = mysqlHost.getText(); |
| 77 | JConfig.setConfiguration("db.mysql.host", host); | |
| 77 | ||
| 78 | 78 | String port = mysqlPort.getText(); |
| 79 | JConfig.setConfiguration("db.mysql.port", port); | |
| 80 | 79 | Integer portNum; |
| 81 | 80 | try { portNum = Integer.parseInt(port); } catch(Exception e) { portNum = -1; } |
| 81 | ||
| 82 | 82 | String db = mysqlDatabase.getText(); |
| 83 | JConfig.setConfiguration("db.mysql.database", db); | |
| 83 | ||
| 84 | 84 | String connectURL = "jdbc:mysql://" + host; |
| 85 | 85 | if(portNum != -1) connectURL += ":" + portNum; |
| 86 | 86 | connectURL += "/"; |
| 87 | 87 | |
| 88 | JConfig.setConfiguration("db.framework", "remote"); | |
| 89 | JConfig.setConfiguration("db.protocol", connectURL); | |
| 90 | JConfig.setConfiguration("db.driver", "com.mysql.jdbc.Driver"); | |
| 91 | JConfig.setConfiguration("db.user", mysqlUser.getText()); | |
| 92 | JConfig.setConfiguration("db.pass", new String(mysqlPassword.getPassword())); | |
| 88 | JConfig.setConfiguration("db.mysql.host", host); | |
| 89 | JConfig.setConfiguration("db.mysql.port", port); | |
| 90 | JConfig.setConfiguration("db.mysql.database", db); | |
| 91 | JConfig.setConfiguration("temp.db.framework", "remote"); | |
| 92 | JConfig.setConfiguration("temp.db.protocol", connectURL); | |
| 93 | JConfig.setConfiguration("temp.db.driver", "com.mysql.jdbc.Driver"); | |
| 94 | JConfig.setConfiguration("temp.db.user", mysqlUser.getText()); | |
| 95 | JConfig.setConfiguration("temp.db.pass", new String(mysqlPassword.getPassword())); | |
| 93 | 96 | } |
| 94 | 97 | |
| 95 | 98 | return true; |
| 948 | 951 | |
|---|---|---|
| 184 | 184 | public Connection getConnection() { |
| 185 | 185 | return mConn; |
| 186 | 186 | } |
| 187 | ||
| 188 | public static void saveDBConfig() { | |
| 189 | if(JConfig.queryConfiguration("temp.db.protocol") != null) { | |
| 190 | String[] keys = { "db.framework", "db.protocol", "db.driver", "db.user", "db.pass" }; | |
| 191 | for(String key : keys) { | |
| 192 | JConfig.setConfiguration(key, JConfig.queryConfiguration("temp." + key)); | |
| 193 | } | |
| 194 | JConfig.kill("jbidwatcher.created_db"); | |
| 195 | } | |
| 196 | } | |
| 187 | 197 | } |
