Skip to content

Commit edfb042

Browse files
author
Brian Kelley
committed
A classes key can now be changed in the metakit backend.
This was fixed by changing the name of the index table to "_%(classname).%(key)" and by removing the old table and reindexing on key changes. This fixes all open metakit regression tests.
1 parent 55fc606 commit edfb042

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

roundup/backends/back_metakit.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: back_metakit.py,v 1.59 2004-02-23 16:57:30 wc2so1 Exp $
1+
# $Id: back_metakit.py,v 1.60 2004-02-23 17:19:09 wc2so1 Exp $
22
'''Metakit backend for Roundup, originally by Gordon McMillan.
33
44
Known Current Bugs:
@@ -883,12 +883,18 @@ def setkey(self, propname):
883883
'propname' must be the name of a String property of this class or
884884
None, or a TypeError is raised. The values of the key property on
885885
all existing nodes must be unique or a ValueError is raised.
886-
'''
886+
'''
887887
if self.key:
888888
if propname == self.key:
889889
return
890-
raise ValueError, "%s already indexed on %s"%(self.classname,
891-
self.key)
890+
else:
891+
# drop the old key table
892+
tablename = "_%s.%s"%(self.classname, self.key)
893+
self.db._db.getas(tablename)
894+
895+
#raise ValueError, "%s already indexed on %s"%(self.classname,
896+
# self.key)
897+
892898
prop = self.properties.get(propname, None)
893899
if prop is None:
894900
prop = self.privateprops.get(propname, None)
@@ -897,20 +903,23 @@ def setkey(self, propname):
897903
if not isinstance(prop, hyperdb.String):
898904
raise TypeError, "%s is not a String" % propname
899905

900-
# TODO: metakit needs to be able to cope with the key property
901-
# *changing*, which it can't do at present. At the moment, it
902-
# creates the key prop index once, with no record of the name of
903-
# the property for the index.
904-
905-
# first setkey for this run
906+
# the way he index on properties is by creating a
907+
# table named _%(classname)s.%(key)s, if this table
908+
# exists then everything is okay. If this table
909+
# doesn't exist, then generate a new table on the
910+
# key value.
911+
912+
# first setkey for this run or key has been changed
906913
self.key = propname
907-
iv = self.db._db.view('_%s' % self.classname)
914+
tablename = "_%s.%s"%(self.classname, self.key)
915+
916+
iv = self.db._db.view(tablename)
908917
if self.db.fastopen and iv.structure():
909918
return
910919

911-
# very first setkey ever
920+
# very first setkey ever or the key has changed
912921
self.db.dirty = 1
913-
iv = self.db._db.getas('_%s[k:S,i:I]' % self.classname)
922+
iv = self.db._db.getas('_%s[k:S,i:I]' % tablename)
914923
iv = iv.ordered(1)
915924
for row in self.getview():
916925
iv.append(k=getattr(row, propname), i=row.id)
@@ -1596,7 +1605,8 @@ def getview(self, RW=0):
15961605
return self.db._db.view(self.classname).ordered(1)
15971606
def getindexview(self, RW=0):
15981607
# XXX FIX ME -> The RW flag doesn't do anything.
1599-
return self.db._db.view("_%s" % self.classname).ordered(1)
1608+
tablename = "_%s.%s"%(self.classname, self.key)
1609+
return self.db._db.view("_%s" % tablename).ordered(1)
16001610

16011611
def _fetchML(sv):
16021612
l = []

0 commit comments

Comments
 (0)