avatar

574

Ensure that all database statements, tables, and connections are committed and shut down at the close of the app.

by mrs, 24 Jul, 2008 06:07 PM
562 574  
33 import com.jbidwatcher.util.config.JConfig;
44 import com.jbidwatcher.util.queue.MQFactory;
55 import com.jbidwatcher.util.db.ActiveRecordCache;
6 import com.jbidwatcher.util.db.ActiveRecord;
67 import com.jbidwatcher.util.Constants;
78 import com.jbidwatcher.auction.server.AuctionStats;
89 import com.jbidwatcher.auction.server.AuctionServerManager;
------
174175     AuctionStats as = AuctionServerManager.getInstance().getStats();
175176     JConfig.setConfiguration("last.auctioncount", Integer.toString(as.getCount()));
176177     JConfig.saveConfiguration(cfgFilename);
178     ActiveRecord.shutdown();
177179     System.exit(0);
178180   }
179181 }
512 574  
1616  * Time: 1:54:46 PM
1717  */
1818 public abstract class ActiveRecord extends HashBacked {
19   private static ArrayList<Table> sTables = new ArrayList<Table>();
1920   protected static Table openDB(String tableName) {
2021     if (tableName == null) return null;
2122 
2223     Table db;
2324     try {
2425       db = new Table(tableName);
26       sTables.add(db);
2527     } catch (Exception e) {
2628       throw new RuntimeException("Can't access the " + tableName + " database table", e);
2729     }
2830     return db;
2931   }
3032 
33   public static void shutdown() {
34     for(Table t : sTables) {
35       t.shutdown();
36     }
37   }
38 
3139   protected static Table getTable(Object o) {
3240     ActiveRecord record = (ActiveRecord) o;
3341     return record.getDatabase();