Commit 019d55c5 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Factorize try/except in setConfiguration.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1023 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ce44e838
...@@ -185,23 +185,23 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -185,23 +185,23 @@ class MySQLDatabaseManager(DatabaseManager):
return None return None
def setConfiguration(self, key, value): def setConfiguration(self, key, value):
self.begin()
try:
q = self.query q = self.query
e = self.escape e = self.escape
key = e(str(key)) key = e(str(key))
value = e(str(value)) value = e(str(value))
q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value)) q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
except:
self.rollback()
raise
self.commit()
def getUUID(self): def getUUID(self):
return self.getConfiguration('uuid') return self.getConfiguration('uuid')
def setUUID(self, uuid): def setUUID(self, uuid):
self.begin()
try:
self.setConfiguration('uuid', uuid) self.setConfiguration('uuid', uuid)
except:
self.rollback()
raise
self.commit()
def getNumPartitions(self): def getNumPartitions(self):
n = self.getConfiguration('partitions') n = self.getConfiguration('partitions')
...@@ -209,13 +209,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -209,13 +209,7 @@ class MySQLDatabaseManager(DatabaseManager):
return int(n) return int(n)
def setNumPartitions(self, num_partitions): def setNumPartitions(self, num_partitions):
self.begin()
try:
self.setConfiguration('partitions', num_partitions) self.setConfiguration('partitions', num_partitions)
except:
self.rollback()
raise
self.commit()
def getNumReplicas(self): def getNumReplicas(self):
n = self.getConfiguration('replicas') n = self.getConfiguration('replicas')
...@@ -223,37 +217,19 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -223,37 +217,19 @@ class MySQLDatabaseManager(DatabaseManager):
return int(n) return int(n)
def setNumReplicas(self, num_replicas): def setNumReplicas(self, num_replicas):
self.begin()
try:
self.setConfiguration('replicas', num_replicas) self.setConfiguration('replicas', num_replicas)
except:
self.rollback()
raise
self.commit()
def getName(self): def getName(self):
return self.getConfiguration('name') return self.getConfiguration('name')
def setName(self, name): def setName(self, name):
self.begin()
try:
self.setConfiguration('name', name) self.setConfiguration('name', name)
except:
self.rollback()
raise
self.commit()
def getPTID(self): def getPTID(self):
return self.getConfiguration('ptid') return self.getConfiguration('ptid')
def setPTID(self, ptid): def setPTID(self, ptid):
self.begin()
try:
self.setConfiguration('ptid', ptid) self.setConfiguration('ptid', ptid)
except:
self.rollback()
raise
self.commit()
def getPartitionTable(self): def getPartitionTable(self):
q = self.query q = self.query
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment