Ensure that all database statements, tables, and connections are committed and shut down at the close of the app.
- M jbidwatcher/trunk/src/com/jbidwatcher/app/MacFriendlyFrame.java view
- M jbidwatcher/trunk/src/com/jbidwatcher/util/db/ActiveRecord.java view
| 562 | 574 | |
|---|---|---|
| 3 | 3 | import com.jbidwatcher.util.config.JConfig; |
| 4 | 4 | import com.jbidwatcher.util.queue.MQFactory; |
| 5 | 5 | import com.jbidwatcher.util.db.ActiveRecordCache; |
| 6 | import com.jbidwatcher.util.db.ActiveRecord; | |
| 6 | 7 | import com.jbidwatcher.util.Constants; |
| 7 | 8 | import com.jbidwatcher.auction.server.AuctionStats; |
| 8 | 9 | import com.jbidwatcher.auction.server.AuctionServerManager; |
| --- | --- | |
| 174 | 175 | AuctionStats as = AuctionServerManager.getInstance().getStats(); |
| 175 | 176 | JConfig.setConfiguration("last.auctioncount", Integer.toString(as.getCount())); |
| 176 | 177 | JConfig.saveConfiguration(cfgFilename); |
| 178 | ActiveRecord.shutdown(); | |
| 177 | 179 | System.exit(0); |
| 178 | 180 | } |
| 179 | 181 | } |
| 512 | 574 | |
|---|---|---|
| 16 | 16 | * Time: 1:54:46 PM |
| 17 | 17 | */ |
| 18 | 18 | public abstract class ActiveRecord extends HashBacked { |
| 19 | private static ArrayList<Table> sTables = new ArrayList<Table>(); | |
| 19 | 20 | protected static Table openDB(String tableName) { |
| 20 | 21 | if (tableName == null) return null; |
| 21 | 22 | |
| 22 | 23 | Table db; |
| 23 | 24 | try { |
| 24 | 25 | db = new Table(tableName); |
| 26 | sTables.add(db); | |
| 25 | 27 | } catch (Exception e) { |
| 26 | 28 | throw new RuntimeException("Can't access the " + tableName + " database table", e); |
| 27 | 29 | } |
| 28 | 30 | return db; |
| 29 | 31 | } |
| 30 | 32 | |
| 33 | public static void shutdown() { | |
| 34 | for(Table t : sTables) { | |
| 35 | t.shutdown(); | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 31 | 39 | protected static Table getTable(Object o) { |
| 32 | 40 | ActiveRecord record = (ActiveRecord) o; |
| 33 | 41 | return record.getDatabase(); |
