Commit 03fe8978 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Move database API configuration getters/setters to generic implementation.

Note for getLastOID: all parameter was not used and overriden in mysqldb implementation, it is safely removed for database API.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1377 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 60b4113c
......@@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from neo import util
class DatabaseManager(object):
"""This class only describes an interface for database managers."""
......@@ -31,48 +33,93 @@ class DatabaseManager(object):
discarded."""
raise NotImplementedError('this method must be overridden')
def getUUID(self):
"""Load an UUID from a database. If not present, return None."""
def getConfiguration(self, key):
"""
Return a configuration value, returns None if not found or not set
"""
raise NotImplementedError('this method must be overridden')
def setUUID(self, uuid):
"""Store an UUID into a database."""
def setConfiguration(self, key, value):
"""
Set a configuration value
"""
raise NotImplementedError('this method must be overridden')
def getUUID(self):
"""
Load an UUID from a database.
"""
return util.bin(self.getConfiguration('uuid'))
def setUUID(self, uuid):
"""
Store an UUID into a database.
"""
self.setConfiguration('uuid', util.dump(uuid))
def getNumPartitions(self):
"""Load the number of partitions from a database. If not present,
return None."""
raise NotImplementedError('this method must be overridden')
"""
Load the number of partitions from a database.
"""
n = self.getConfiguration('partitions')
if n is not None:
return int(n)
def setNumPartitions(self, num_partitions):
"""Store the number of partitions into a database."""
raise NotImplementedError('this method must be overridden')
"""
Store the number of partitions into a database.
"""
self.setConfiguration('partitions', num_partitions)
def getNumReplicas(self):
"""Load the number of replicas from a database. If not present,
return None."""
raise NotImplementedError('this method must be overridden')
def setNumReplicas(self, num_partitions):
"""Store the number of replicas into a database."""
raise NotImplementedError('this method must be overridden')
"""
Load the number of replicas from a database.
"""
n = self.getConfiguration('replicas')
if n is not None:
return int(n)
def setNumReplicas(self, num_replicas):
"""
Store the number of replicas into a database.
"""
self.setConfiguration('replicas', num_replicas)
def getName(self):
"""Load a name from a database. If not present, return None."""
raise NotImplementedError('this method must be overridden')
"""
Load a name from a database.
"""
return self.getConfiguration('name')
def setName(self, name):
"""Store a name into a database."""
raise NotImplementedError('this method must be overridden')
"""
Store a name into a database.
"""
self.setConfiguration('name', name)
def getPTID(self):
"""Load a Partition Table ID from a database. If not present,
return None."""
raise NotImplementedError('this method must be overridden')
"""
Load a Partition Table ID from a database.
"""
return util.bin(self.getConfiguration('ptid'))
def setPTID(self, ptid):
"""Store a Partition Table ID into a database."""
raise NotImplementedError('this method must be overridden')
"""
Store a Partition Table ID into a database.
"""
self.setConfiguration('ptid', util.dump(ptid))
def getLastOID(self):
"""
Returns the last OID used
"""
return util.bin(self.getConfiguration('loid'))
def setLastOID(self, loid):
"""
Set the last OID used
"""
self.setConfiguration('loid', util.dump(loid))
def getPartitionTable(self):
"""Return a whole partition table as a tuple of rows. Each row
......@@ -80,12 +127,6 @@ class DatabaseManager(object):
node, and a cell state."""
raise NotImplementedError('this method must be overridden')
def getLastOID(self, all = True):
"""Return the last OID in a database. If all is true,
unfinished transactions must be taken account into. If there
is no OID in the database, return None."""
raise NotImplementedError('this method must be overridden')
def getLastTID(self, all = True):
"""Return the last TID in a database. If all is true,
unfinished transactions must be taken account into. If there
......
......@@ -198,52 +198,6 @@ class MySQLDatabaseManager(DatabaseManager):
raise
self.commit()
def getUUID(self):
uuid = self.getConfiguration('uuid')
return util.bin(uuid)
def setUUID(self, uuid):
uuid = util.dump(uuid)
self.setConfiguration('uuid', uuid)
def getNumPartitions(self):
n = self.getConfiguration('partitions')
if n is not None:
return int(n)
def setNumPartitions(self, num_partitions):
self.setConfiguration('partitions', num_partitions)
def getNumReplicas(self):
n = self.getConfiguration('replicas')
if n is not None:
return int(n)
def setNumReplicas(self, num_replicas):
self.setConfiguration('replicas', num_replicas)
def getName(self):
return self.getConfiguration('name')
def setName(self, name):
self.setConfiguration('name', name)
def getPTID(self):
ptid = self.getConfiguration('ptid')
return util.bin(ptid)
def setPTID(self, ptid):
ptid = util.dump(ptid)
self.setConfiguration('ptid', ptid)
def getLastOID(self):
loid = self.getConfiguration('loid')
return util.bin(loid)
def setLastOID(self, loid):
loid = util.dump(loid)
self.setConfiguration('loid', loid)
def getPartitionTable(self):
q = self.query
cell_list = q("""SELECT rid, uuid, state FROM pt""")
......
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