about summary refs log tree commit diff
path: root/src/db.hh
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-31T16·05+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-31T16·05+0000
commit06d3d7355d1b0ec05e61d2e7fe67f8d7153c1ff9 (patch)
tree424a162babe37ef113f8f908715e095f180d001f /src/db.hh
parent177a7782aee4c4789ad5377b5993bfa0b692282e (diff)
* Enclose most operations that update the database in transactions.
* Open all database tables (Db objects) at initialisation time, not
  every time they are used.  This is necessary because tables have to
  outlive all transactions that refer to them.

Diffstat (limited to 'src/db.hh')
-rw-r--r--src/db.hh25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/db.hh b/src/db.hh
index 57b6e4d8ebfb..4bac943e554d 100644
--- a/src/db.hh
+++ b/src/db.hh
@@ -3,6 +3,7 @@
 
 #include <string>
 #include <list>
+#include <map>
 
 #include <db_cxx.h>
 
@@ -26,6 +27,7 @@ public:
     Transaction(Database & _db);
     ~Transaction();
 
+    void abort();
     void commit();
 };
 
@@ -33,6 +35,9 @@ public:
 #define noTxn Transaction()
 
 
+typedef unsigned int TableId; /* table handles */
+
+
 class Database
 {
     friend class Transaction;
@@ -40,10 +45,12 @@ class Database
 private:
     DbEnv * env;
 
+    TableId nextId;
+    map<TableId, Db *> tables;
+
     void requireEnv();
 
-    Db * openDB(const Transaction & txn,
-        const string & table, bool create);
+    Db * getDb(TableId table);
 
 public:
     Database();
@@ -51,24 +58,24 @@ public:
     
     void open(const string & path);
 
-    void createTable(const string & table);
+    TableId openTable(const string & table);
 
-    bool queryString(const Transaction & txn, const string & table, 
+    bool queryString(const Transaction & txn, TableId table, 
         const string & key, string & data);
 
-    bool queryStrings(const Transaction & txn, const string & table, 
+    bool queryStrings(const Transaction & txn, TableId table, 
         const string & key, Strings & data);
 
-    void setString(const Transaction & txn, const string & table,
+    void setString(const Transaction & txn, TableId table,
         const string & key, const string & data);
 
-    void setStrings(const Transaction & txn, const string & table,
+    void setStrings(const Transaction & txn, TableId table,
         const string & key, const Strings & data);
 
-    void delPair(const Transaction & txn, const string & table,
+    void delPair(const Transaction & txn, TableId table,
         const string & key);
 
-    void enumTable(const Transaction & txn, const string & table,
+    void enumTable(const Transaction & txn, TableId table,
         Strings & keys);
 };