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,37 +185,31 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -185,37 +185,31 @@ class MySQLDatabaseManager(DatabaseManager):
return None return None
def setConfiguration(self, key, value): def setConfiguration(self, key, value):
q = self.query
e = self.escape
key = e(str(key))
value = e(str(value))
q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
def getUUID(self):
return self.getConfiguration('uuid')
def setUUID(self, uuid):
self.begin() self.begin()
try: try:
self.setConfiguration('uuid', uuid) q = self.query
e = self.escape
key = e(str(key))
value = e(str(value))
q("""REPLACE INTO config VALUES ('%s', '%s')""" % (key, value))
except: except:
self.rollback() self.rollback()
raise raise
self.commit() self.commit()
def getUUID(self):
return self.getConfiguration('uuid')
def setUUID(self, uuid):
self.setConfiguration('uuid', uuid)
def getNumPartitions(self): def getNumPartitions(self):
n = self.getConfiguration('partitions') n = self.getConfiguration('partitions')
if n is not None: if n is not None:
return int(n) return int(n)
def setNumPartitions(self, num_partitions): def setNumPartitions(self, num_partitions):
self.begin() self.setConfiguration('partitions', num_partitions)
try:
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() self.setConfiguration('replicas', num_replicas)
try:
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() self.setConfiguration('name', name)
try:
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() self.setConfiguration('ptid', ptid)
try:
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