1
from twisted.enterprise import row
4
##################################################
5
########## Definitions of Row Classes ############
6
##################################################
9
"""This is a lame, but simple way to generate keys.
10
For real code, use the database instead."""
11
def __init__(self, minimum, pool):
13
self.pool = minimum + pool
14
self.current = self.min
17
next = self.current + 1
19
if self.current >= self.pool:
20
raise ValueError("Key factory key pool exceeded.")
23
def myRowFactory(rowClass, data, kw):
25
newRow.__dict__.update(kw)
28
class RoomRow(row.RowObject):
39
rowKeyColumns = [("roomId","int")]
40
rowTableName = "testrooms"
41
rowFactoryMethod = [myRowFactory]
46
def addStuff(self, stuff):
47
self.furniture.append(stuff)
49
def moveTo(self, x, y):
54
return "<Room #%s: %s (%s) (%s,%s)>" % (self.roomId, self.name, self.owner, self.posx, self.posy)
56
class FurnitureRow(row.RowObject):
64
rowKeyColumns = [("furnId","int")]
65
rowTableName = "furniture"
66
rowForeignKeys = [("testrooms", [("roomId","int")], [("roomId","int")], "addStuff", 1) ]
69
return "Furniture #%s: room #%s (%s) (%s,%s)" % (self.furnId, self.roomId, self.name, self.posx, self.posy)
71
class RugRow(row.RowObject):
77
rowKeyColumns = [("rugId","int")]
79
rowFactoryMethod = [myRowFactory]
80
rowForeignKeys = [( "testrooms", [("roomId","int")],[("roomId","int")], "addStuff", 1) ]
83
return "Rug %#s: room #%s, (%s)" % (self.rugId, self.roomId, self.name)
85
class LampRow(row.RowObject):
89
("furnName", "varchar"),
90
("lampName", "varchar")
92
rowKeyColumns = [("lampId","int")]
93
rowTableName = "lamps"
94
rowForeignKeys = [("furniture",
95
[("furnId","int"),("furnName", "varchar")], # child table columns (this table)
96
[("furnId","int"),("name", "varchar")], # parent table columns (the other table)
100
# NOTE: this has no containerMethod so children will be added to "childRows"
103
return "Lamp #%s" % self.lampId