]> git.jsancho.org Git - mojodb.git/commitdiff
Savepoints to protect integrity of documents master
authorJavier Sancho <jsf@jsancho.org>
Thu, 20 Mar 2014 15:06:44 +0000 (16:06 +0100)
committerJavier Sancho <jsf@jsancho.org>
Thu, 20 Mar 2014 15:06:44 +0000 (16:06 +0100)
MySQL.py
collection.py
connection.py

index ba00c333349485a6fd7d2549826d1e7cc5654734..03969f78c5add49964e417498a6d56bc11dcb637 100644 (file)
--- a/MySQL.py
+++ b/MySQL.py
@@ -171,3 +171,15 @@ class Connection(connection.Connection):
 
     def rollback(self):
         self._db_con.rollback()
 
     def rollback(self):
         self._db_con.rollback()
+
+    def savepoint(self, name):
+        self.execute("SAVEPOINT %s" % name)
+        return True
+
+    def commit_savepoint(self, name):
+        self.execute("RELEASE SAVEPOINT %s" % name)
+        return True
+
+    def rollback_savepoint(self, name):
+        self.execute("ROLLBACK TO %s" % name)
+        return True
index b8d51a071af117291ff26a1e9e4f3eb406b3d55e..804135379d089cf4ebc5f0e6f0f8b3a1a8981f42 100644 (file)
@@ -75,11 +75,17 @@ class Collection(object):
 
     def _insert_document(self, doc_id, doc):
         fields = self._get_fields()
 
     def _insert_document(self, doc_id, doc):
         fields = self._get_fields()
-        for f in doc:
-            if not f in fields:
-                self._create_field(f)
-            table_f = '%s$%s' % (self.table_name, f)
-            self._insert_field(doc_id, table_f, f, doc[f])
+        self.database.connection.savepoint("insert_document")
+        try:
+            for f in doc:
+                if not f in fields:
+                    self._create_field(f)
+                table_f = '%s$%s' % (self.table_name, f)
+                self._insert_field(doc_id, table_f, f, doc[f])
+            self.database.connection.commit_savepoint("insert_document")
+        except:
+            self.database.connection.rollback_savepoint("insert_document")
+            raise
 
     def _insert_field(self, doc_id, field_table, field_name, field_value):
         values = {
 
     def _insert_field(self, doc_id, field_table, field_name, field_value):
         values = {
index 7623047ca1bd0634081a1f0ba8c696e2af85e140..c3f5647bd0a63d8c6aba237e3e157679581a1943 100644 (file)
@@ -93,3 +93,12 @@ class Connection(object):
 
     def rollback(self):
         pass
 
     def rollback(self):
         pass
+
+    def savepoint(self, name):
+        pass
+
+    def commit_savepoint(self, name):
+        pass
+
+    def rollback_savepoint(self, name):
+        pass