Mercurial > p > roundup > code
annotate roundup/backends/rdbms_common.py @ 1753:9d7c396defe1 maint-0.5
backporting fix from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Tue, 26 Aug 2003 00:15:09 +0000 |
| parents | 44319ba5a7a7 |
| children |
| rev | line source |
|---|---|
|
1753
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1 # $Id: rdbms_common.py,v 1.27.2.10 2003-08-26 00:15:09 richard Exp $ |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 ''' Relational database (SQL) backend common code. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 Basics: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 - map roundup classes to relational tables |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 - automatically detect schema changes and modify the table schemas |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 appropriately (we store the "database version" of the schema in the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 database itself as the only row of the "schema" table) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 - multilinks (which represent a many-to-many relationship) are handled through |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 intermediate tables |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 - journals are stored adjunct to the per-class tables |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 - table names and columns have "_" prepended so the names can't clash with |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 restricted names (like "order") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 - retirement is determined by the __retired__ column being true |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 Database-specific changes may generally be pushed out to the overridable |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
18 sql_* methods, since everything else should be fairly generic. There's |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
19 probably a bit of work to be done if a database is used that actually |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
20 honors column typing, since the initial databases don't (sqlite stores |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
21 everything as a string, and gadfly stores anything that's marsallable). |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
22 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
24 # standard python modules |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
25 import sys, os, time, re, errno, weakref, copy |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
27 # roundup modules |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
28 from roundup import hyperdb, date, password, roundupdb, security |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
29 from roundup.hyperdb import String, Password, Date, Interval, Link, \ |
|
1418
e6b2d51e5b95
backport fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1410
diff
changeset
|
30 Multilink, DatabaseError, Boolean, Number, Node |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
31 from roundup.backends import locking |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
32 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
33 # support |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
34 from blobfiles import FileStorage |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
35 from roundup.indexer import Indexer |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 from sessions import Sessions |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
38 # number of rows to keep in memory |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
39 ROW_CACHE_SIZE = 100 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 class Database(FileStorage, hyperdb.Database, roundupdb.Database): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
42 ''' Wrapper around an SQL database that presents a hyperdb interface. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
43 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
44 - some functionality is specific to the actual SQL database, hence |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
45 the sql_* methods that are NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
46 - we keep a cache of the latest ROW_CACHE_SIZE row fetches. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
47 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
48 def __init__(self, config, journaltag=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 ''' Open the database and load the schema from it. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
50 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 self.config, self.journaltag = config, journaltag |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
52 self.dir = config.DATABASE |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
53 self.classes = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 self.indexer = Indexer(self.dir) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
55 self.sessions = Sessions(self.config) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
56 self.security = security.Security(self) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
57 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
58 # additional transaction support for external files and the like |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
59 self.transactions = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 # keep a cache of the N most recently retrieved rows of any kind |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 # (classname, nodeid) = row |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 self.cache = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 self.cache_lru = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 # database lock |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 self.lockfile = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 # open a connection to the database, creating the "conn" attribute |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 self.open_connection() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 def clearCache(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 self.cache = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 self.cache_lru = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 def open_connection(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 ''' Open a connection to the database, creating it if necessary |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
81 def sql(self, sql, args=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
82 ''' Execute the sql with the optional args. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
83 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
84 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
85 print >>hyperdb.DEBUG, (self, sql, args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
86 if args: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
87 self.cursor.execute(sql, args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
88 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
89 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
90 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
91 def sql_fetchone(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
92 ''' Fetch a single row. If there's nothing to fetch, return None. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
93 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
94 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
95 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
96 def sql_stringquote(self, value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
97 ''' Quote the string so it's safe to put in the 'sql quotes' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
98 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
99 return re.sub("'", "''", str(value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
100 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
101 def save_dbschema(self, schema): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
102 ''' Save the schema definition that the database currently implements |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
103 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
104 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
105 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
106 def load_dbschema(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
107 ''' Load the schema definition that the database currently implements |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
108 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
109 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
111 def post_init(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
112 ''' Called once the schema initialisation has finished. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
113 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
114 We should now confirm that the schema defined by our "classes" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
115 attribute actually matches the schema in the database. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
116 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
117 # now detect changes in the schema |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
118 save = 0 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
119 for classname, spec in self.classes.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
120 if self.database_schema.has_key(classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
121 dbspec = self.database_schema[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
122 if self.update_class(spec, dbspec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
123 self.database_schema[classname] = spec.schema() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 save = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
125 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
126 self.create_class(spec) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
127 self.database_schema[classname] = spec.schema() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
128 save = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
129 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
130 for classname in self.database_schema.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
131 if not self.classes.has_key(classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
132 self.drop_class(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 # update the database version of the schema |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 if save: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
136 self.sql('delete from schema') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
137 self.save_dbschema(self.database_schema) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
138 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
139 # reindex the db if necessary |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
140 if self.indexer.should_reindex(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
141 self.reindex() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
142 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
143 # commit |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
144 self.conn.commit() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
145 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
146 # figure the "curuserid" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
147 if self.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
148 self.curuserid = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
149 elif self.journaltag == 'admin': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
150 # admin user may not exist, but always has ID 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
151 self.curuserid = '1' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
152 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
153 self.curuserid = self.user.lookup(self.journaltag) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
154 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
155 def reindex(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
156 for klass in self.classes.values(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
157 for nodeid in klass.list(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
158 klass.index(nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
159 self.indexer.save_index() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
160 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
161 def determine_columns(self, properties): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
162 ''' Figure the column names and multilink properties from the spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
163 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
164 "properties" is a list of (name, prop) where prop may be an |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
165 instance of a hyperdb "type" _or_ a string repr of that type. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
166 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
167 cols = ['_activity', '_creator', '_creation'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
168 mls = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
169 # add the multilinks separately |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
170 for col, prop in properties: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
171 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
172 mls.append(col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
173 elif isinstance(prop, type('')) and prop.find('Multilink') != -1: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
174 mls.append(col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
175 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
176 cols.append('_'+col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
177 cols.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
178 return cols, mls |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
179 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
180 def update_class(self, spec, old_spec): |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
181 ''' Determine the differences between the current spec and the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
182 database version of the spec, and update where necessary |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
183 ''' |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
184 new_spec = spec |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
185 new_has = new_spec.properties.has_key |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
186 |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
187 new_spec = new_spec.schema() |
|
1516
c8a596aa5aba
fixed rdbms table update detection logic [SF#703297]
Richard Jones <richard@users.sourceforge.net>
parents:
1501
diff
changeset
|
188 new_spec[1].sort() |
|
c8a596aa5aba
fixed rdbms table update detection logic [SF#703297]
Richard Jones <richard@users.sourceforge.net>
parents:
1501
diff
changeset
|
189 old_spec[1].sort() |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
190 if new_spec == old_spec: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
191 # no changes |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
192 return 0 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
193 |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
194 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
195 print >>hyperdb.DEBUG, 'update_class FIRING' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
196 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
197 # key property changed? |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
198 if old_spec[0] != new_spec[0]: |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
199 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
200 print >>hyperdb.DEBUG, 'update_class setting keyprop', `spec[0]` |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
201 # XXX turn on indexing for the key property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
202 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
203 # detect multilinks that have been removed, and drop their table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
204 old_has = {} |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
205 for name,prop in old_spec[1]: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
206 old_has[name] = 1 |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
207 if not new_has(name) and isinstance(prop, Multilink): |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
208 # it's a multilink, and it's been removed - drop the old |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
209 # table |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
210 sql = 'drop table %s_%s'%(spec.classname, prop) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
211 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
212 print >>hyperdb.DEBUG, 'update_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
213 self.cursor.execute(sql) |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
214 continue |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
215 old_has = old_has.has_key |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
216 |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
217 # now figure how we populate the new table |
|
1501
8fd1ad93f920
backport fix to gadfly schema updating from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1491
diff
changeset
|
218 fetch = ['_activity', '_creation', '_creator'] |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
219 properties = spec.getprops() |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
220 for propname,x in new_spec[1]: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
221 prop = properties[propname] |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
222 if isinstance(prop, Multilink): |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
223 if not old_has(propname): |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
224 # we need to create the new table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
225 self.create_multilink_table(spec, propname) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
226 elif old_has(propname): |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
227 # we copy this col over from the old table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
228 fetch.append('_'+propname) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
229 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
230 # select the data out of the old table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
231 fetch.append('id') |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
232 fetch.append('__retired__') |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
233 fetchcols = ','.join(fetch) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
234 cn = spec.classname |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
235 sql = 'select %s from _%s'%(fetchcols, cn) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
236 if __debug__: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
237 print >>hyperdb.DEBUG, 'update_class', (self, sql) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
238 self.cursor.execute(sql) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
239 olddata = self.cursor.fetchall() |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
240 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
241 # drop the old table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
242 self.cursor.execute('drop table _%s'%cn) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
243 |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
244 # create the new table |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
245 self.create_class_table(spec) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
246 |
|
1481
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
247 if olddata: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
248 # do the insert |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
249 args = ','.join([self.arg for x in fetch]) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
250 sql = 'insert into _%s (%s) values (%s)'%(cn, fetchcols, args) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
251 if __debug__: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
252 print >>hyperdb.DEBUG, 'update_class', (self, sql, olddata[0]) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
253 for entry in olddata: |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
254 self.cursor.execute(sql, *entry) |
|
31cc79f966ac
backport of rdbms backend fix
Richard Jones <richard@users.sourceforge.net>
parents:
1418
diff
changeset
|
255 |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
256 return 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
257 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
258 def create_class_table(self, spec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
259 ''' create the class table for the given spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
260 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
261 cols, mls = self.determine_columns(spec.properties.items()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
262 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
263 # add on our special columns |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
264 cols.append('id') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
265 cols.append('__retired__') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
266 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
267 # create the base table |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
268 scols = ','.join(['%s varchar'%x for x in cols]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
269 sql = 'create table _%s (%s)'%(spec.classname, scols) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
270 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
271 print >>hyperdb.DEBUG, 'create_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
272 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
273 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
274 return cols, mls |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
275 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
276 def create_journal_table(self, spec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
277 ''' create the journal table for a class given the spec and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
278 already-determined cols |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
279 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
280 # journal table |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
281 cols = ','.join(['%s varchar'%x |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
282 for x in 'nodeid date tag action params'.split()]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
283 sql = 'create table %s__journal (%s)'%(spec.classname, cols) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
284 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
285 print >>hyperdb.DEBUG, 'create_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
286 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
287 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
288 def create_multilink_table(self, spec, ml): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
289 ''' Create a multilink table for the "ml" property of the class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
290 given by the spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
291 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
292 sql = 'create table %s_%s (linkid varchar, nodeid varchar)'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
293 spec.classname, ml) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
294 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
295 print >>hyperdb.DEBUG, 'create_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
296 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
297 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
298 def create_class(self, spec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
299 ''' Create a database table according to the given spec. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
300 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
301 cols, mls = self.create_class_table(spec) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
302 self.create_journal_table(spec) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
303 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
304 # now create the multilink tables |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
305 for ml in mls: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
306 self.create_multilink_table(spec, ml) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
307 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
308 # ID counter |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
309 sql = 'insert into ids (name, num) values (%s,%s)'%(self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
310 vals = (spec.classname, 1) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
311 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
312 print >>hyperdb.DEBUG, 'create_class', (self, sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
313 self.cursor.execute(sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
314 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
315 def drop_class(self, spec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
316 ''' Drop the given table from the database. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
317 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
318 Drop the journal and multilink tables too. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
319 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
320 # figure the multilinks |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
321 mls = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
322 for col, prop in spec.properties.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
323 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
324 mls.append(col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
325 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
326 sql = 'drop table _%s'%spec.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
327 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
328 print >>hyperdb.DEBUG, 'drop_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
329 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
330 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
331 sql = 'drop table %s__journal'%spec.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
332 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
333 print >>hyperdb.DEBUG, 'drop_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
334 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
335 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
336 for ml in mls: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
337 sql = 'drop table %s_%s'%(spec.classname, ml) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
338 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
339 print >>hyperdb.DEBUG, 'drop_class', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
340 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
341 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
342 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
343 # Classes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
344 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
345 def __getattr__(self, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
346 ''' A convenient way of calling self.getclass(classname). |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
347 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
348 if self.classes.has_key(classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
349 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
350 print >>hyperdb.DEBUG, '__getattr__', (self, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
351 return self.classes[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
352 raise AttributeError, classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
353 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
354 def addclass(self, cl): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
355 ''' Add a Class to the hyperdatabase. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
356 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
357 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
358 print >>hyperdb.DEBUG, 'addclass', (self, cl) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
359 cn = cl.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
360 if self.classes.has_key(cn): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
361 raise ValueError, cn |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
362 self.classes[cn] = cl |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
363 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
364 def getclasses(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
365 ''' Return a list of the names of all existing classes. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
366 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
367 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
368 print >>hyperdb.DEBUG, 'getclasses', (self,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
369 l = self.classes.keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
370 l.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
371 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
372 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
373 def getclass(self, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
374 '''Get the Class object representing a particular class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
375 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
376 If 'classname' is not a valid class name, a KeyError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
377 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
378 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
379 print >>hyperdb.DEBUG, 'getclass', (self, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
380 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
381 return self.classes[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
382 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
383 raise KeyError, 'There is no class called "%s"'%classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
384 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
385 def clear(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
386 ''' Delete all database contents. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
387 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
388 Note: I don't commit here, which is different behaviour to the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
389 "nuke from orbit" behaviour in the *dbms. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
390 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
391 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
392 print >>hyperdb.DEBUG, 'clear', (self,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
393 for cn in self.classes.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
394 sql = 'delete from _%s'%cn |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
395 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
396 print >>hyperdb.DEBUG, 'clear', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
397 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
398 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
399 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
400 # Node IDs |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
401 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
402 def newid(self, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
403 ''' Generate a new id for the given class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
404 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
405 # get the next ID |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
406 sql = 'select num from ids where name=%s'%self.arg |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
407 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
408 print >>hyperdb.DEBUG, 'newid', (self, sql, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
409 self.cursor.execute(sql, (classname, )) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
410 newid = self.cursor.fetchone()[0] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
411 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
412 # update the counter |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
413 sql = 'update ids set num=%s where name=%s'%(self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
414 vals = (int(newid)+1, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
415 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
416 print >>hyperdb.DEBUG, 'newid', (self, sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
417 self.cursor.execute(sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
418 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
419 # return as string |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
420 return str(newid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
421 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
422 def setid(self, classname, setid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
423 ''' Set the id counter: used during import of database |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
424 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
425 sql = 'update ids set num=%s where name=%s'%(self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
426 vals = (setid, classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
427 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
428 print >>hyperdb.DEBUG, 'setid', (self, sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
429 self.cursor.execute(sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
430 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
431 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
432 # Nodes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
433 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
434 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
435 def addnode(self, classname, nodeid, node): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
436 ''' Add the specified node to its class's db. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
437 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
438 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
439 print >>hyperdb.DEBUG, 'addnode', (self, classname, nodeid, node) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
440 # gadfly requires values for all non-multilink columns |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
441 cl = self.classes[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
442 cols, mls = self.determine_columns(cl.properties.items()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
443 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
444 # we'll be supplied these props if we're doing an import |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
445 if not node.has_key('creator'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
446 # add in the "calculated" properties (dupe so we don't affect |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
447 # calling code's node assumptions) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
448 node = node.copy() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
449 node['creation'] = node['activity'] = date.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
450 node['creator'] = self.curuserid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
451 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
452 # default the non-multilink columns |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
453 for col, prop in cl.properties.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
454 if not isinstance(col, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
455 if not node.has_key(col): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
456 node[col] = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
457 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
458 # clear this node out of the cache if it's in there |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
459 key = (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
460 if self.cache.has_key(key): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
461 del self.cache[key] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
462 self.cache_lru.remove(key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
463 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
464 # make the node data safe for the DB |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
465 node = self.serialise(classname, node) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
466 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
467 # make sure the ordering is correct for column name -> column value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
468 vals = tuple([node[col[1:]] for col in cols]) + (nodeid, 0) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
469 s = ','.join([self.arg for x in cols]) + ',%s,%s'%(self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
470 cols = ','.join(cols) + ',id,__retired__' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
471 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
472 # perform the inserts |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
473 sql = 'insert into _%s (%s) values (%s)'%(classname, cols, s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
474 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
475 print >>hyperdb.DEBUG, 'addnode', (self, sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
476 self.cursor.execute(sql, vals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
477 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
478 # insert the multilink rows |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
479 for col in mls: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
480 t = '%s_%s'%(classname, col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
481 for entry in node[col]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
482 sql = 'insert into %s (linkid, nodeid) values (%s,%s)'%(t, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
483 self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
484 self.sql(sql, (entry, nodeid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
485 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
486 # make sure we do the commit-time extra stuff for this node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
487 self.transactions.append((self.doSaveNode, (classname, nodeid, node))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
488 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
489 def setnode(self, classname, nodeid, values, multilink_changes): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
490 ''' Change the specified node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
491 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
492 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
493 print >>hyperdb.DEBUG, 'setnode', (self, classname, nodeid, values) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
494 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
495 # clear this node out of the cache if it's in there |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
496 key = (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
497 if self.cache.has_key(key): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
498 del self.cache[key] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
499 self.cache_lru.remove(key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
500 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
501 # add the special props |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
502 values = values.copy() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
503 values['activity'] = date.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
504 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
505 # make db-friendly |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
506 values = self.serialise(classname, values) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
507 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
508 cl = self.classes[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
509 cols = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
510 mls = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
511 # add the multilinks separately |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
512 props = cl.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
513 for col in values.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
514 prop = props[col] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
515 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
516 mls.append(col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
517 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
518 cols.append('_'+col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
519 cols.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
520 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
521 # if there's any updates to regular columns, do them |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
522 if cols: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
523 # make sure the ordering is correct for column name -> column value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
524 sqlvals = tuple([values[col[1:]] for col in cols]) + (nodeid,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
525 s = ','.join(['%s=%s'%(x, self.arg) for x in cols]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
526 cols = ','.join(cols) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
527 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
528 # perform the update |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
529 sql = 'update _%s set %s where id=%s'%(classname, s, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
530 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
531 print >>hyperdb.DEBUG, 'setnode', (self, sql, sqlvals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
532 self.cursor.execute(sql, sqlvals) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
533 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
534 # now the fun bit, updating the multilinks ;) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
535 for col, (add, remove) in multilink_changes.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
536 tn = '%s_%s'%(classname, col) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
537 if add: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
538 sql = 'insert into %s (nodeid, linkid) values (%s,%s)'%(tn, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
539 self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
540 for addid in add: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
541 self.sql(sql, (nodeid, addid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
542 if remove: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
543 sql = 'delete from %s where nodeid=%s and linkid=%s'%(tn, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
544 self.arg, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
545 for removeid in remove: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
546 self.sql(sql, (nodeid, removeid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
547 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
548 # make sure we do the commit-time extra stuff for this node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
549 self.transactions.append((self.doSaveNode, (classname, nodeid, values))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
550 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
551 def getnode(self, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
552 ''' Get a node from the database. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
553 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
554 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
555 print >>hyperdb.DEBUG, 'getnode', (self, classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
556 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
557 # see if we have this node cached |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
558 key = (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
559 if self.cache.has_key(key): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
560 # push us back to the top of the LRU |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
561 self.cache_lru.remove(key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
562 self.cache_lru.insert(0, key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
563 # return the cached information |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
564 return self.cache[key] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
565 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
566 # figure the columns we're fetching |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
567 cl = self.classes[classname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
568 cols, mls = self.determine_columns(cl.properties.items()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
569 scols = ','.join(cols) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
570 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
571 # perform the basic property fetch |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
572 sql = 'select %s from _%s where id=%s'%(scols, classname, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
573 self.sql(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
574 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
575 values = self.sql_fetchone() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
576 if values is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
577 raise IndexError, 'no such %s node %s'%(classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
578 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
579 # make up the node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
580 node = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
581 for col in range(len(cols)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
582 node[cols[col][1:]] = values[col] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
583 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
584 # now the multilinks |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
585 for col in mls: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
586 # get the link ids |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
587 sql = 'select linkid from %s_%s where nodeid=%s'%(classname, col, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
588 self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
589 self.cursor.execute(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
590 # extract the first column from the result |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
591 node[col] = [x[0] for x in self.cursor.fetchall()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
592 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
593 # un-dbificate the node data |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
594 node = self.unserialise(classname, node) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
595 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
596 # save off in the cache |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
597 key = (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
598 self.cache[key] = node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
599 # update the LRU |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
600 self.cache_lru.insert(0, key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
601 if len(self.cache_lru) > ROW_CACHE_SIZE: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
602 del self.cache[self.cache_lru.pop()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
603 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
604 return node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
605 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
606 def destroynode(self, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
607 '''Remove a node from the database. Called exclusively by the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
608 destroy() method on Class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
609 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
610 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
611 print >>hyperdb.DEBUG, 'destroynode', (self, classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
612 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
613 # make sure the node exists |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
614 if not self.hasnode(classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
615 raise IndexError, '%s has no node %s'%(classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
616 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
617 # see if we have this node cached |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
618 if self.cache.has_key((classname, nodeid)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
619 del self.cache[(classname, nodeid)] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
620 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
621 # see if there's any obvious commit actions that we should get rid of |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
622 for entry in self.transactions[:]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
623 if entry[1][:2] == (classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
624 self.transactions.remove(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
625 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
626 # now do the SQL |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
627 sql = 'delete from _%s where id=%s'%(classname, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
628 self.sql(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
629 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
630 # remove from multilnks |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
631 cl = self.getclass(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
632 x, mls = self.determine_columns(cl.properties.items()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
633 for col in mls: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
634 # get the link ids |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
635 sql = 'delete from %s_%s where nodeid=%s'%(classname, col, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
636 self.cursor.execute(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
637 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
638 # remove journal entries |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
639 sql = 'delete from %s__journal where nodeid=%s'%(classname, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
640 self.sql(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
641 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
642 def serialise(self, classname, node): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
643 '''Copy the node contents, converting non-marshallable data into |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
644 marshallable data. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
645 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
646 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
647 print >>hyperdb.DEBUG, 'serialise', classname, node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
648 properties = self.getclass(classname).getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
649 d = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
650 for k, v in node.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
651 # if the property doesn't exist, or is the "retired" flag then |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
652 # it won't be in the properties dict |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
653 if not properties.has_key(k): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
654 d[k] = v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
655 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
656 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
657 # get the property spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
658 prop = properties[k] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
659 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
660 if isinstance(prop, Password) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
661 d[k] = str(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
662 elif isinstance(prop, Date) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
663 d[k] = v.serialise() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
664 elif isinstance(prop, Interval) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
665 d[k] = v.serialise() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
666 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
667 d[k] = v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
668 return d |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
669 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
670 def unserialise(self, classname, node): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
671 '''Decode the marshalled node data |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
672 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
673 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
674 print >>hyperdb.DEBUG, 'unserialise', classname, node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
675 properties = self.getclass(classname).getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
676 d = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
677 for k, v in node.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
678 # if the property doesn't exist, or is the "retired" flag then |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
679 # it won't be in the properties dict |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
680 if not properties.has_key(k): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
681 d[k] = v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
682 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
683 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
684 # get the property spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
685 prop = properties[k] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
686 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
687 if isinstance(prop, Date) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
688 d[k] = date.Date(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
689 elif isinstance(prop, Interval) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
690 d[k] = date.Interval(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
691 elif isinstance(prop, Password) and v is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
692 p = password.Password() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
693 p.unpack(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
694 d[k] = p |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
695 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
696 d[k] = v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
697 return d |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
698 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
699 def hasnode(self, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
700 ''' Determine if the database has a given node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
701 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
702 sql = 'select count(*) from _%s where id=%s'%(classname, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
703 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
704 print >>hyperdb.DEBUG, 'hasnode', (self, sql, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
705 self.cursor.execute(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
706 return int(self.cursor.fetchone()[0]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
707 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
708 def countnodes(self, classname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
709 ''' Count the number of nodes that exist for a particular Class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
710 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
711 sql = 'select count(*) from _%s'%classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
712 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
713 print >>hyperdb.DEBUG, 'countnodes', (self, sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
714 self.cursor.execute(sql) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
715 return self.cursor.fetchone()[0] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
716 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
717 def getnodeids(self, classname, retired=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
718 ''' Retrieve all the ids of the nodes for a particular Class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
719 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
720 Set retired=None to get all nodes. Otherwise it'll get all the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
721 retired or non-retired nodes, depending on the flag. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
722 ''' |
|
1709
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
723 # flip the sense of the 'retired' flag if we don't want all of them |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
724 if retired is not None: |
|
1709
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
725 args = (((retired==0) and 1) or 0,) |
|
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
726 sql = 'select id from _%s where __retired__ <> %s'%(classname, self.arg) |
|
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
727 else: |
|
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
728 args = () |
|
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
729 sql = 'select id from _%s'%(classname,) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
730 if __debug__: |
|
1709
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
731 print >>hyperdb.DEBUG, 'getnodeids', (self, sql, args) |
|
44319ba5a7a7
Fixed Py2.3 compatibility.
Anthony Baxter <anthonybaxter@users.sourceforge.net>
parents:
1550
diff
changeset
|
732 self.cursor.execute(sql, args) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
733 return [x[0] for x in self.cursor.fetchall()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
734 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
735 def addjournal(self, classname, nodeid, action, params, creator=None, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
736 creation=None): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
737 ''' Journal the Action |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
738 'action' may be: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
739 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
740 'create' or 'set' -- 'params' is a dictionary of property values |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
741 'link' or 'unlink' -- 'params' is (classname, nodeid, propname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
742 'retire' -- 'params' is None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
743 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
744 # serialise the parameters now if necessary |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
745 if isinstance(params, type({})): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
746 if action in ('set', 'create'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
747 params = self.serialise(classname, params) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
748 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
749 # handle supply of the special journalling parameters (usually |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
750 # supplied on importing an existing database) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
751 if creator: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
752 journaltag = creator |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
753 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
754 journaltag = self.curuserid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
755 if creation: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
756 journaldate = creation.serialise() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
757 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
758 journaldate = date.Date().serialise() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
759 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
760 # create the journal entry |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
761 cols = ','.join('nodeid date tag action params'.split()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
762 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
763 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
764 print >>hyperdb.DEBUG, 'addjournal', (nodeid, journaldate, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
765 journaltag, action, params) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
766 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
767 self.save_journal(classname, cols, nodeid, journaldate, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
768 journaltag, action, params) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
769 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
770 def save_journal(self, classname, cols, nodeid, journaldate, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
771 journaltag, action, params): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
772 ''' Save the journal entry to the database |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
773 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
774 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
775 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
776 def getjournal(self, classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
777 ''' get the journal for id |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
778 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
779 # make sure the node exists |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
780 if not self.hasnode(classname, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
781 raise IndexError, '%s has no node %s'%(classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
782 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
783 cols = ','.join('nodeid date tag action params'.split()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
784 return self.load_journal(classname, cols, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
785 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
786 def load_journal(self, classname, cols, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
787 ''' Load the journal from the database |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
788 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
789 raise NotImplemented |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
790 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
791 def pack(self, pack_before): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
792 ''' Delete all journal entries except "create" before 'pack_before'. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
793 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
794 # get a 'yyyymmddhhmmss' version of the date |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
795 date_stamp = pack_before.serialise() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
796 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
797 # do the delete |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
798 for classname in self.classes.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
799 sql = "delete from %s__journal where date<%s and "\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
800 "action<>'create'"%(classname, self.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
801 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
802 print >>hyperdb.DEBUG, 'pack', (self, sql, date_stamp) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
803 self.cursor.execute(sql, (date_stamp,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
804 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
805 def sql_commit(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
806 ''' Actually commit to the database. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
807 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
808 self.conn.commit() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
809 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
810 def commit(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
811 ''' Commit the current transactions. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
812 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
813 Save all data changed since the database was opened or since the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
814 last commit() or rollback(). |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
815 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
816 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
817 print >>hyperdb.DEBUG, 'commit', (self,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
818 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
819 # commit the database |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
820 self.sql_commit() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
821 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
822 # now, do all the other transaction stuff |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
823 reindex = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
824 for method, args in self.transactions: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
825 reindex[method(*args)] = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
826 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
827 # reindex the nodes that request it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
828 for classname, nodeid in filter(None, reindex.keys()): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
829 print >>hyperdb.DEBUG, 'commit.reindex', (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
830 self.getclass(classname).index(nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
831 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
832 # save the indexer state |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
833 self.indexer.save_index() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
834 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
835 # clear out the transactions |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
836 self.transactions = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
837 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
838 def rollback(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
839 ''' Reverse all actions from the current transaction. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
840 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
841 Undo all the changes made since the database was opened or the last |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
842 commit() or rollback() was performed. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
843 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
844 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
845 print >>hyperdb.DEBUG, 'rollback', (self,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
846 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
847 # roll back |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
848 self.conn.rollback() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
849 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
850 # roll back "other" transaction stuff |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
851 for method, args in self.transactions: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
852 # delete temporary files |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
853 if method == self.doStoreFile: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
854 self.rollbackStoreFile(*args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
855 self.transactions = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
856 |
|
1491
393ab6e36540
fixed sqlite rollback/caching bug [SF#689383]
Richard Jones <richard@users.sourceforge.net>
parents:
1481
diff
changeset
|
857 # clear the cache |
|
393ab6e36540
fixed sqlite rollback/caching bug [SF#689383]
Richard Jones <richard@users.sourceforge.net>
parents:
1481
diff
changeset
|
858 self.clearCache() |
|
393ab6e36540
fixed sqlite rollback/caching bug [SF#689383]
Richard Jones <richard@users.sourceforge.net>
parents:
1481
diff
changeset
|
859 |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
860 def doSaveNode(self, classname, nodeid, node): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
861 ''' dummy that just generates a reindex event |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
862 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
863 # return the classname, nodeid so we reindex this content |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
864 return (classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
865 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
866 def close(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
867 ''' Close off the connection. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
868 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
869 self.conn.close() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
870 if self.lockfile is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
871 locking.release_lock(self.lockfile) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
872 if self.lockfile is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
873 self.lockfile.close() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
874 self.lockfile = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
875 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
876 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
877 # The base Class class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
878 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
879 class Class(hyperdb.Class): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
880 ''' The handle to a particular class of nodes in a hyperdatabase. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
881 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
882 All methods except __repr__ and getnode must be implemented by a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
883 concrete backend Class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
884 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
885 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
886 def __init__(self, db, classname, **properties): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
887 '''Create a new class with a given name and property specification. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
888 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
889 'classname' must not collide with the name of an existing class, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
890 or a ValueError is raised. The keyword arguments in 'properties' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
891 must map names to property objects, or a TypeError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
892 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
893 if (properties.has_key('creation') or properties.has_key('activity') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
894 or properties.has_key('creator')): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
895 raise ValueError, '"creation", "activity" and "creator" are '\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
896 'reserved' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
897 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
898 self.classname = classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
899 self.properties = properties |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
900 self.db = weakref.proxy(db) # use a weak ref to avoid circularity |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
901 self.key = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
902 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
903 # should we journal changes (default yes) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
904 self.do_journal = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
905 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
906 # do the db-related init stuff |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
907 db.addclass(self) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
908 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
909 self.auditors = {'create': [], 'set': [], 'retire': []} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
910 self.reactors = {'create': [], 'set': [], 'retire': []} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
911 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
912 def schema(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
913 ''' A dumpable version of the schema that we can store in the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
914 database |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
915 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
916 return (self.key, [(x, repr(y)) for x,y in self.properties.items()]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
917 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
918 def enableJournalling(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
919 '''Turn journalling on for this class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
920 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
921 self.do_journal = 1 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
922 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
923 def disableJournalling(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
924 '''Turn journalling off for this class |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
925 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
926 self.do_journal = 0 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
927 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
928 # Editing nodes: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
929 def create(self, **propvalues): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
930 ''' Create a new node of this class and return its id. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
931 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
932 The keyword arguments in 'propvalues' map property names to values. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
933 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
934 The values of arguments must be acceptable for the types of their |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
935 corresponding properties or a TypeError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
936 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
937 If this class has a key property, it must be present and its value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
938 must not collide with other key strings or a ValueError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
939 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
940 Any other properties on this class that are missing from the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
941 'propvalues' dictionary are set to None. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
942 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
943 If an id in a link or multilink property does not refer to a valid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
944 node, an IndexError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
945 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
946 if propvalues.has_key('id'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
947 raise KeyError, '"id" is reserved' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
948 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
949 if self.db.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
950 raise DatabaseError, 'Database open read-only' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
951 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
952 if propvalues.has_key('creation') or propvalues.has_key('activity'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
953 raise KeyError, '"creation" and "activity" are reserved' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
954 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
955 self.fireAuditors('create', None, propvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
956 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
957 # new node's id |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
958 newid = self.db.newid(self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
959 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
960 # validate propvalues |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
961 num_re = re.compile('^\d+$') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
962 for key, value in propvalues.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
963 if key == self.key: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
964 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
965 self.lookup(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
966 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
967 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
968 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
969 raise ValueError, 'node with key "%s" exists'%value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
970 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
971 # try to handle this property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
972 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
973 prop = self.properties[key] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
974 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
975 raise KeyError, '"%s" has no property "%s"'%(self.classname, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
976 key) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
977 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
978 if value is not None and isinstance(prop, Link): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
979 if type(value) != type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
980 raise ValueError, 'link value must be String' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
981 link_class = self.properties[key].classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
982 # if it isn't a number, it's a key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
983 if not num_re.match(value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
984 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
985 value = self.db.classes[link_class].lookup(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
986 except (TypeError, KeyError): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
987 raise IndexError, 'new property "%s": %s not a %s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
988 key, value, link_class) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
989 elif not self.db.getclass(link_class).hasnode(value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
990 raise IndexError, '%s has no node %s'%(link_class, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
991 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
992 # save off the value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
993 propvalues[key] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
994 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
995 # register the link with the newly linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
996 if self.do_journal and self.properties[key].do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
997 self.db.addjournal(link_class, value, 'link', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
998 (self.classname, newid, key)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
999 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1000 elif isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1001 if type(value) != type([]): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1002 raise TypeError, 'new property "%s" not a list of ids'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1003 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1004 # clean up and validate the list of links |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1005 link_class = self.properties[key].classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1006 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1007 for entry in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1008 if type(entry) != type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1009 raise ValueError, '"%s" multilink value (%r) '\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1010 'must contain Strings'%(key, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1011 # if it isn't a number, it's a key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1012 if not num_re.match(entry): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1013 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1014 entry = self.db.classes[link_class].lookup(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1015 except (TypeError, KeyError): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1016 raise IndexError, 'new property "%s": %s not a %s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1017 key, entry, self.properties[key].classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1018 l.append(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1019 value = l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1020 propvalues[key] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1021 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1022 # handle additions |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1023 for nodeid in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1024 if not self.db.getclass(link_class).hasnode(nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1025 raise IndexError, '%s has no node %s'%(link_class, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1026 nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1027 # register the link with the newly linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1028 if self.do_journal and self.properties[key].do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1029 self.db.addjournal(link_class, nodeid, 'link', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1030 (self.classname, newid, key)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1031 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1032 elif isinstance(prop, String): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1033 if type(value) != type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1034 raise TypeError, 'new property "%s" not a string'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1035 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1036 elif isinstance(prop, Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1037 if not isinstance(value, password.Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1038 raise TypeError, 'new property "%s" not a Password'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1039 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1040 elif isinstance(prop, Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1041 if value is not None and not isinstance(value, date.Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1042 raise TypeError, 'new property "%s" not a Date'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1043 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1044 elif isinstance(prop, Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1045 if value is not None and not isinstance(value, date.Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1046 raise TypeError, 'new property "%s" not an Interval'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1047 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1048 elif value is not None and isinstance(prop, Number): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1049 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1050 float(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1051 except ValueError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1052 raise TypeError, 'new property "%s" not numeric'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1053 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1054 elif value is not None and isinstance(prop, Boolean): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1055 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1056 int(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1057 except ValueError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1058 raise TypeError, 'new property "%s" not boolean'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1059 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1060 # make sure there's data where there needs to be |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1061 for key, prop in self.properties.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1062 if propvalues.has_key(key): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1063 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1064 if key == self.key: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1065 raise ValueError, 'key property "%s" is required'%key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1066 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1067 propvalues[key] = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1068 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1069 propvalues[key] = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1070 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1071 # done |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1072 self.db.addnode(self.classname, newid, propvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1073 if self.do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1074 self.db.addjournal(self.classname, newid, 'create', {}) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1075 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1076 self.fireReactors('create', newid, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1077 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1078 return newid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1079 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1080 def export_list(self, propnames, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1081 ''' Export a node - generate a list of CSV-able data in the order |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1082 specified by propnames for the given node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1083 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1084 properties = self.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1085 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1086 for prop in propnames: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1087 proptype = properties[prop] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1088 value = self.get(nodeid, prop) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1089 # "marshal" data where needed |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1090 if value is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1091 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1092 elif isinstance(proptype, hyperdb.Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1093 value = value.get_tuple() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1094 elif isinstance(proptype, hyperdb.Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1095 value = value.get_tuple() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1096 elif isinstance(proptype, hyperdb.Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1097 value = str(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1098 l.append(repr(value)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1099 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1100 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1101 def import_list(self, propnames, proplist): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1102 ''' Import a node - all information including "id" is present and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1103 should not be sanity checked. Triggers are not triggered. The |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1104 journal should be initialised using the "creator" and "created" |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1105 information. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1106 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1107 Return the nodeid of the node imported. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1108 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1109 if self.db.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1110 raise DatabaseError, 'Database open read-only' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1111 properties = self.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1112 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1113 # make the new node's property map |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1114 d = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1115 for i in range(len(propnames)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1116 # Use eval to reverse the repr() used to output the CSV |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1117 value = eval(proplist[i]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1118 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1119 # Figure the property for this column |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1120 propname = propnames[i] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1121 prop = properties[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1122 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1123 # "unmarshal" where necessary |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1124 if propname == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1125 newid = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1126 continue |
|
1753
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1127 elif propname == 'is retired': |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1128 # is the item retired? |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1129 if int(value): |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1130 retire = 1 |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1131 continue |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1132 elif value is None: |
|
1753
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1133 d[propname] = None |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1134 continue |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1135 |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1136 prop = properties[propname] |
|
9d7c396defe1
backporting fix from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1709
diff
changeset
|
1137 if value is None: |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1138 # don't set Nones |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1139 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1140 elif isinstance(prop, hyperdb.Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1141 value = date.Date(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1142 elif isinstance(prop, hyperdb.Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1143 value = date.Interval(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1144 elif isinstance(prop, hyperdb.Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1145 pwd = password.Password() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1146 pwd.unpack(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1147 value = pwd |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1148 d[propname] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1149 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1150 # add the node and journal |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1151 self.db.addnode(self.classname, newid, d) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1152 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1153 # extract the extraneous journalling gumpf and nuke it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1154 if d.has_key('creator'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1155 creator = d['creator'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1156 del d['creator'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1157 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1158 creator = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1159 if d.has_key('creation'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1160 creation = d['creation'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1161 del d['creation'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1162 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1163 creation = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1164 if d.has_key('activity'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1165 del d['activity'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1166 self.db.addjournal(self.classname, newid, 'create', {}, creator, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1167 creation) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1168 return newid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1169 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1170 _marker = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1171 def get(self, nodeid, propname, default=_marker, cache=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1172 '''Get the value of a property on an existing node of this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1173 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1174 'nodeid' must be the id of an existing node of this class or an |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1175 IndexError is raised. 'propname' must be the name of a property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1176 of this class or a KeyError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1177 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1178 'cache' indicates whether the transaction cache should be queried |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1179 for the node. If the node has been modified and you need to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1180 determine what its values prior to modification are, you need to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1181 set cache=0. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1182 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1183 if propname == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1184 return nodeid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1185 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1186 # get the node's dict |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1187 d = self.db.getnode(self.classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1188 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1189 if propname == 'creation': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1190 if d.has_key('creation'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1191 return d['creation'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1192 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1193 return date.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1194 if propname == 'activity': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1195 if d.has_key('activity'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1196 return d['activity'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1197 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1198 return date.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1199 if propname == 'creator': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1200 if d.has_key('creator'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1201 return d['creator'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1202 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1203 return self.db.curuserid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1204 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1205 # get the property (raises KeyErorr if invalid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1206 prop = self.properties[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1207 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1208 if not d.has_key(propname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1209 if default is self._marker: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1210 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1211 return [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1212 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1213 return None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1214 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1215 return default |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1216 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1217 # don't pass our list to other code |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1218 if isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1219 return d[propname][:] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1220 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1221 return d[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1222 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1223 def getnode(self, nodeid, cache=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1224 ''' Return a convenience wrapper for the node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1225 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1226 'nodeid' must be the id of an existing node of this class or an |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1227 IndexError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1228 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1229 'cache' indicates whether the transaction cache should be queried |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1230 for the node. If the node has been modified and you need to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1231 determine what its values prior to modification are, you need to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1232 set cache=0. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1233 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1234 return Node(self, nodeid, cache=cache) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1235 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1236 def set(self, nodeid, **propvalues): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1237 '''Modify a property on an existing node of this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1238 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1239 'nodeid' must be the id of an existing node of this class or an |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1240 IndexError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1241 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1242 Each key in 'propvalues' must be the name of a property of this |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1243 class or a KeyError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1244 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1245 All values in 'propvalues' must be acceptable types for their |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1246 corresponding properties or a TypeError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1247 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1248 If the value of the key property is set, it must not collide with |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1249 other key strings or a ValueError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1250 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1251 If the value of a Link or Multilink property contains an invalid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1252 node id, a ValueError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1253 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1254 if not propvalues: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1255 return propvalues |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1256 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1257 if propvalues.has_key('creation') or propvalues.has_key('activity'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1258 raise KeyError, '"creation" and "activity" are reserved' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1259 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1260 if propvalues.has_key('id'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1261 raise KeyError, '"id" is reserved' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1262 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1263 if self.db.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1264 raise DatabaseError, 'Database open read-only' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1265 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1266 self.fireAuditors('set', nodeid, propvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1267 # Take a copy of the node dict so that the subsequent set |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1268 # operation doesn't modify the oldvalues structure. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1269 # XXX used to try the cache here first |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1270 oldvalues = copy.deepcopy(self.db.getnode(self.classname, nodeid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1271 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1272 node = self.db.getnode(self.classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1273 if self.is_retired(nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1274 raise IndexError, 'Requested item is retired' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1275 num_re = re.compile('^\d+$') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1276 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1277 # if the journal value is to be different, store it in here |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1278 journalvalues = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1279 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1280 # remember the add/remove stuff for multilinks, making it easier |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1281 # for the Database layer to do its stuff |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1282 multilink_changes = {} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1283 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1284 for propname, value in propvalues.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1285 # check to make sure we're not duplicating an existing key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1286 if propname == self.key and node[propname] != value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1287 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1288 self.lookup(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1289 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1290 pass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1291 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1292 raise ValueError, 'node with key "%s" exists'%value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1293 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1294 # this will raise the KeyError if the property isn't valid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1295 # ... we don't use getprops() here because we only care about |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1296 # the writeable properties. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1297 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1298 prop = self.properties[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1299 except KeyError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1300 raise KeyError, '"%s" has no property named "%s"'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1301 self.classname, propname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1302 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1303 # if the value's the same as the existing value, no sense in |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1304 # doing anything |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1305 current = node.get(propname, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1306 if value == current: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1307 del propvalues[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1308 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1309 journalvalues[propname] = current |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1310 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1311 # do stuff based on the prop type |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1312 if isinstance(prop, Link): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1313 link_class = prop.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1314 # if it isn't a number, it's a key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1315 if value is not None and not isinstance(value, type('')): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1316 raise ValueError, 'property "%s" link value be a string'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1317 propname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1318 if isinstance(value, type('')) and not num_re.match(value): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1319 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1320 value = self.db.classes[link_class].lookup(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1321 except (TypeError, KeyError): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1322 raise IndexError, 'new property "%s": %s not a %s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1323 propname, value, prop.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1324 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1325 if (value is not None and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1326 not self.db.getclass(link_class).hasnode(value)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1327 raise IndexError, '%s has no node %s'%(link_class, value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1328 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1329 if self.do_journal and prop.do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1330 # register the unlink with the old linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1331 if node[propname] is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1332 self.db.addjournal(link_class, node[propname], 'unlink', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1333 (self.classname, nodeid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1334 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1335 # register the link with the newly linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1336 if value is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1337 self.db.addjournal(link_class, value, 'link', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1338 (self.classname, nodeid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1339 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1340 elif isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1341 if type(value) != type([]): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1342 raise TypeError, 'new property "%s" not a list of'\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1343 ' ids'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1344 link_class = self.properties[propname].classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1345 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1346 for entry in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1347 # if it isn't a number, it's a key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1348 if type(entry) != type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1349 raise ValueError, 'new property "%s" link value ' \ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1350 'must be a string'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1351 if not num_re.match(entry): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1352 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1353 entry = self.db.classes[link_class].lookup(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1354 except (TypeError, KeyError): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1355 raise IndexError, 'new property "%s": %s not a %s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1356 propname, entry, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1357 self.properties[propname].classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1358 l.append(entry) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1359 value = l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1360 propvalues[propname] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1361 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1362 # figure the journal entry for this property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1363 add = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1364 remove = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1365 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1366 # handle removals |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1367 if node.has_key(propname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1368 l = node[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1369 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1370 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1371 for id in l[:]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1372 if id in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1373 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1374 # register the unlink with the old linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1375 if self.do_journal and self.properties[propname].do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1376 self.db.addjournal(link_class, id, 'unlink', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1377 (self.classname, nodeid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1378 l.remove(id) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1379 remove.append(id) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1380 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1381 # handle additions |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1382 for id in value: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1383 if not self.db.getclass(link_class).hasnode(id): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1384 raise IndexError, '%s has no node %s'%(link_class, id) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1385 if id in l: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1386 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1387 # register the link with the newly linked node |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1388 if self.do_journal and self.properties[propname].do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1389 self.db.addjournal(link_class, id, 'link', |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1390 (self.classname, nodeid, propname)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1391 l.append(id) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1392 add.append(id) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1393 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1394 # figure the journal entry |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1395 l = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1396 if add: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1397 l.append(('+', add)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1398 if remove: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1399 l.append(('-', remove)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1400 multilink_changes[propname] = (add, remove) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1401 if l: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1402 journalvalues[propname] = tuple(l) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1403 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1404 elif isinstance(prop, String): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1405 if value is not None and type(value) != type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1406 raise TypeError, 'new property "%s" not a string'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1407 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1408 elif isinstance(prop, Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1409 if not isinstance(value, password.Password): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1410 raise TypeError, 'new property "%s" not a Password'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1411 propvalues[propname] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1412 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1413 elif value is not None and isinstance(prop, Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1414 if not isinstance(value, date.Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1415 raise TypeError, 'new property "%s" not a Date'% propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1416 propvalues[propname] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1417 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1418 elif value is not None and isinstance(prop, Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1419 if not isinstance(value, date.Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1420 raise TypeError, 'new property "%s" not an '\ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1421 'Interval'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1422 propvalues[propname] = value |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1423 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1424 elif value is not None and isinstance(prop, Number): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1425 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1426 float(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1427 except ValueError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1428 raise TypeError, 'new property "%s" not numeric'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1429 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1430 elif value is not None and isinstance(prop, Boolean): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1431 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1432 int(value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1433 except ValueError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1434 raise TypeError, 'new property "%s" not boolean'%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1435 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1436 # nothing to do? |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1437 if not propvalues: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1438 return propvalues |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1439 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1440 # do the set, and journal it |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1441 self.db.setnode(self.classname, nodeid, propvalues, multilink_changes) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1442 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1443 if self.do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1444 self.db.addjournal(self.classname, nodeid, 'set', journalvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1445 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1446 self.fireReactors('set', nodeid, oldvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1447 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1448 return propvalues |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1449 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1450 def retire(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1451 '''Retire a node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1452 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1453 The properties on the node remain available from the get() method, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1454 and the node's id is never reused. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1455 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1456 Retired nodes are not returned by the find(), list(), or lookup() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1457 methods, and other nodes may reuse the values of their key properties. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1458 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1459 if self.db.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1460 raise DatabaseError, 'Database open read-only' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1461 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1462 self.fireAuditors('retire', nodeid, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1463 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1464 # use the arg for __retired__ to cope with any odd database type |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1465 # conversion (hello, sqlite) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1466 sql = 'update _%s set __retired__=%s where id=%s'%(self.classname, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1467 self.db.arg, self.db.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1468 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1469 print >>hyperdb.DEBUG, 'retire', (self, sql, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1470 self.db.cursor.execute(sql, (1, nodeid)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1471 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1472 self.fireReactors('retire', nodeid, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1473 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1474 def is_retired(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1475 '''Return true if the node is rerired |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1476 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1477 sql = 'select __retired__ from _%s where id=%s'%(self.classname, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1478 self.db.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1479 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1480 print >>hyperdb.DEBUG, 'is_retired', (self, sql, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1481 self.db.cursor.execute(sql, (nodeid,)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1482 return int(self.db.sql_fetchone()[0]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1483 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1484 def destroy(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1485 '''Destroy a node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1486 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1487 WARNING: this method should never be used except in extremely rare |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1488 situations where there could never be links to the node being |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1489 deleted |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1490 WARNING: use retire() instead |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1491 WARNING: the properties of this node will not be available ever again |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1492 WARNING: really, use retire() instead |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1493 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1494 Well, I think that's enough warnings. This method exists mostly to |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1495 support the session storage of the cgi interface. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1496 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1497 The node is completely removed from the hyperdb, including all journal |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1498 entries. It will no longer be available, and will generally break code |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1499 if there are any references to the node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1500 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1501 if self.db.journaltag is None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1502 raise DatabaseError, 'Database open read-only' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1503 self.db.destroynode(self.classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1504 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1505 def history(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1506 '''Retrieve the journal of edits on a particular node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1507 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1508 'nodeid' must be the id of an existing node of this class or an |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1509 IndexError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1510 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1511 The returned list contains tuples of the form |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1512 |
|
1410
3a853f1c20b5
backporting fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1366
diff
changeset
|
1513 (nodeid, date, tag, action, params) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1514 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1515 'date' is a Timestamp object specifying the time of the change and |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1516 'tag' is the journaltag specified when the database was opened. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1517 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1518 if not self.do_journal: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1519 raise ValueError, 'Journalling is disabled for this class' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1520 return self.db.getjournal(self.classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1521 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1522 # Locating nodes: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1523 def hasnode(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1524 '''Determine if the given nodeid actually exists |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1525 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1526 return self.db.hasnode(self.classname, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1527 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1528 def setkey(self, propname): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1529 '''Select a String property of this class to be the key property. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1530 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1531 'propname' must be the name of a String property of this class or |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1532 None, or a TypeError is raised. The values of the key property on |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1533 all existing nodes must be unique or a ValueError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1534 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1535 # XXX create an index on the key prop column |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1536 prop = self.getprops()[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1537 if not isinstance(prop, String): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1538 raise TypeError, 'key properties must be String' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1539 self.key = propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1540 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1541 def getkey(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1542 '''Return the name of the key property for this class or None.''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1543 return self.key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1544 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1545 def labelprop(self, default_to_id=0): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1546 ''' Return the property name for a label for the given node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1547 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1548 This method attempts to generate a consistent label for the node. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1549 It tries the following in order: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1550 1. key property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1551 2. "name" property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1552 3. "title" property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1553 4. first property from the sorted property name list |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1554 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1555 k = self.getkey() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1556 if k: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1557 return k |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1558 props = self.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1559 if props.has_key('name'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1560 return 'name' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1561 elif props.has_key('title'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1562 return 'title' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1563 if default_to_id: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1564 return 'id' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1565 props = props.keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1566 props.sort() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1567 return props[0] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1568 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1569 def lookup(self, keyvalue): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1570 '''Locate a particular node by its key property and return its id. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1571 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1572 If this class has no key property, a TypeError is raised. If the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1573 'keyvalue' matches one of the values for the key property among |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1574 the nodes in this class, the matching node's id is returned; |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1575 otherwise a KeyError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1576 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1577 if not self.key: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1578 raise TypeError, 'No key property set for class %s'%self.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1579 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1580 # use the arg to handle any odd database type conversion (hello, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1581 # sqlite) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1582 sql = "select id from _%s where _%s=%s and __retired__ <> %s"%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1583 self.classname, self.key, self.db.arg, self.db.arg) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1584 self.db.sql(sql, (keyvalue, 1)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1585 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1586 # see if there was a result that's not retired |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1587 row = self.db.sql_fetchone() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1588 if not row: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1589 raise KeyError, 'No key (%s) value "%s" for "%s"'%(self.key, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1590 keyvalue, self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1591 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1592 # return the id |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1593 return row[0] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1594 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1595 def find(self, **propspec): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1596 '''Get the ids of nodes in this class which link to the given nodes. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1597 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1598 'propspec' consists of keyword args propname=nodeid or |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1599 propname={nodeid:1, } |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1600 'propname' must be the name of a property in this class, or a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1601 KeyError is raised. That property must be a Link or Multilink |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1602 property, or a TypeError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1603 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1604 Any node in this class whose 'propname' property links to any of the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1605 nodeids will be returned. Used by the full text indexing, which knows |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1606 that "foo" occurs in msg1, msg3 and file7, so we have hits on these |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1607 issues: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1608 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1609 db.issue.find(messages={'1':1,'3':1}, files={'7':1}) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1610 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1611 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1612 print >>hyperdb.DEBUG, 'find', (self, propspec) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1613 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1614 # shortcut |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1615 if not propspec: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1616 return [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1617 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1618 # validate the args |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1619 props = self.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1620 propspec = propspec.items() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1621 for propname, nodeids in propspec: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1622 # check the prop is OK |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1623 prop = props[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1624 if not isinstance(prop, Link) and not isinstance(prop, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1625 raise TypeError, "'%s' not a Link/Multilink property"%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1626 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1627 # first, links |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1628 where = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1629 allvalues = () |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1630 a = self.db.arg |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1631 for prop, values in propspec: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1632 if not isinstance(props[prop], hyperdb.Link): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1633 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1634 if type(values) is type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1635 allvalues += (values,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1636 where.append('_%s = %s'%(prop, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1637 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1638 allvalues += tuple(values.keys()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1639 where.append('_%s in (%s)'%(prop, ','.join([a]*len(values)))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1640 tables = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1641 if where: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1642 tables.append('select id as nodeid from _%s where %s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1643 self.classname, ' and '.join(where))) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1644 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1645 # now multilinks |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1646 for prop, values in propspec: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1647 if not isinstance(props[prop], hyperdb.Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1648 continue |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1649 if type(values) is type(''): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1650 allvalues += (values,) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1651 s = a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1652 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1653 allvalues += tuple(values.keys()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1654 s = ','.join([a]*len(values)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1655 tables.append('select nodeid from %s_%s where linkid in (%s)'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1656 self.classname, prop, s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1657 sql = '\nunion\n'.join(tables) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1658 self.db.sql(sql, allvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1659 l = [x[0] for x in self.db.sql_fetchall()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1660 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1661 print >>hyperdb.DEBUG, 'find ... ', l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1662 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1663 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1664 def stringFind(self, **requirements): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1665 '''Locate a particular node by matching a set of its String |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1666 properties in a caseless search. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1667 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1668 If the property is not a String property, a TypeError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1669 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1670 The return is a list of the id of all nodes that match. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1671 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1672 where = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1673 args = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1674 for propname in requirements.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1675 prop = self.properties[propname] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1676 if isinstance(not prop, String): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1677 raise TypeError, "'%s' not a String property"%propname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1678 where.append(propname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1679 args.append(requirements[propname].lower()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1680 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1681 # generate the where clause |
|
1550
905f92b97d4e
backport of mail address case problem from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1516
diff
changeset
|
1682 s = ' and '.join(['lower(_%s)=%s'%(col, self.db.arg) for col in where]) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1683 sql = 'select id from _%s where %s'%(self.classname, s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1684 self.db.sql(sql, tuple(args)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1685 l = [x[0] for x in self.db.sql_fetchall()] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1686 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1687 print >>hyperdb.DEBUG, 'find ... ', l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1688 return l |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1689 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1690 def list(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1691 ''' Return a list of the ids of the active nodes in this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1692 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1693 return self.db.getnodeids(self.classname, retired=0) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1694 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1695 def filter(self, search_matches, filterspec, sort=(None,None), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1696 group=(None,None)): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1697 ''' Return a list of the ids of the active nodes in this class that |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1698 match the 'filter' spec, sorted by the group spec and then the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1699 sort spec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1700 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1701 "filterspec" is {propname: value(s)} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1702 "sort" and "group" are (dir, prop) where dir is '+', '-' or None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1703 and prop is a prop name or None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1704 "search_matches" is {nodeid: marker} |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1705 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1706 The filter must match all properties specificed - but if the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1707 property value to match is a list, any one of the values in the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1708 list may match for that property to match. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1709 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1710 # just don't bother if the full-text search matched diddly |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1711 if search_matches == {}: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1712 return [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1713 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1714 cn = self.classname |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1715 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1716 # figure the WHERE clause from the filterspec |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1717 props = self.getprops() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1718 frum = ['_'+cn] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1719 where = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1720 args = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1721 a = self.db.arg |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1722 for k, v in filterspec.items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1723 propclass = props[k] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1724 # now do other where clause stuff |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1725 if isinstance(propclass, Multilink): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1726 tn = '%s_%s'%(cn, k) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1727 frum.append(tn) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1728 if isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1729 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1730 where.append('id=%s.nodeid and %s.linkid in (%s)'%(tn,tn,s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1731 args = args + v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1732 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1733 where.append('id=%s.nodeid and %s.linkid = %s'%(tn, tn, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1734 args.append(v) |
|
1366
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1735 elif k == 'id': |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1736 if isinstance(v, type([])): |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1737 s = ','.join([a for x in v]) |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1738 where.append('%s in (%s)'%(k, s)) |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1739 args = args + v |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1740 else: |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1741 where.append('%s=%s'%(k, a)) |
|
1cc9c6bc17bd
merge fixes from HEAD
Richard Jones <richard@users.sourceforge.net>
parents:
1356
diff
changeset
|
1742 args.append(v) |
|
1356
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1743 elif isinstance(propclass, String): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1744 if not isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1745 v = [v] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1746 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1747 # Quote the bits in the string that need it and then embed |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1748 # in a "substring" search. Note - need to quote the '%' so |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1749 # they make it through the python layer happily |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1750 v = ['%%'+self.db.sql_stringquote(s)+'%%' for s in v] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1751 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1752 # now add to the where clause |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1753 where.append(' or '.join(["_%s LIKE '%s'"%(k, s) for s in v])) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1754 # note: args are embedded in the query string now |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1755 elif isinstance(propclass, Link): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1756 if isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1757 if '-1' in v: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1758 v.remove('-1') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1759 xtra = ' or _%s is NULL'%k |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1760 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1761 xtra = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1762 if v: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1763 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1764 where.append('(_%s in (%s)%s)'%(k, s, xtra)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1765 args = args + v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1766 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1767 where.append('_%s is NULL'%k) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1768 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1769 if v == '-1': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1770 v = None |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1771 where.append('_%s is NULL'%k) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1772 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1773 where.append('_%s=%s'%(k, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1774 args.append(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1775 elif isinstance(propclass, Date): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1776 if isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1777 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1778 where.append('_%s in (%s)'%(k, s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1779 args = args + [date.Date(x).serialise() for x in v] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1780 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1781 where.append('_%s=%s'%(k, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1782 args.append(date.Date(v).serialise()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1783 elif isinstance(propclass, Interval): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1784 if isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1785 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1786 where.append('_%s in (%s)'%(k, s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1787 args = args + [date.Interval(x).serialise() for x in v] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1788 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1789 where.append('_%s=%s'%(k, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1790 args.append(date.Interval(v).serialise()) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1791 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1792 if isinstance(v, type([])): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1793 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1794 where.append('_%s in (%s)'%(k, s)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1795 args = args + v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1796 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1797 where.append('_%s=%s'%(k, a)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1798 args.append(v) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1799 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1800 # add results of full text search |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1801 if search_matches is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1802 v = search_matches.keys() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1803 s = ','.join([a for x in v]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1804 where.append('id in (%s)'%s) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1805 args = args + v |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1806 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1807 # "grouping" is just the first-order sorting in the SQL fetch |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1808 # can modify it...) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1809 orderby = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1810 ordercols = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1811 if group[0] is not None and group[1] is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1812 if group[0] != '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1813 orderby.append('_'+group[1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1814 ordercols.append('_'+group[1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1815 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1816 orderby.append('_'+group[1]+' desc') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1817 ordercols.append('_'+group[1]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1818 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1819 # now add in the sorting |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1820 group = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1821 if sort[0] is not None and sort[1] is not None: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1822 direction, colname = sort |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1823 if direction != '-': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1824 if colname == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1825 orderby.append(colname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1826 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1827 orderby.append('_'+colname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1828 ordercols.append('_'+colname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1829 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1830 if colname == 'id': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1831 orderby.append(colname+' desc') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1832 ordercols.append(colname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1833 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1834 orderby.append('_'+colname+' desc') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1835 ordercols.append('_'+colname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1836 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1837 # construct the SQL |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1838 frum = ','.join(frum) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1839 if where: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1840 where = ' where ' + (' and '.join(where)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1841 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1842 where = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1843 cols = ['id'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1844 if orderby: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1845 cols = cols + ordercols |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1846 order = ' order by %s'%(','.join(orderby)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1847 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1848 order = '' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1849 cols = ','.join(cols) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1850 sql = 'select %s from %s %s%s%s'%(cols, frum, where, group, order) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1851 args = tuple(args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1852 if __debug__: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1853 print >>hyperdb.DEBUG, 'filter', (self, sql, args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1854 self.db.cursor.execute(sql, args) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1855 l = self.db.cursor.fetchall() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1856 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1857 # return the IDs (the first column) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1858 # XXX The filter(None, l) bit is sqlite-specific... if there's _NO_ |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1859 # XXX matches to a fetch, it returns NULL instead of nothing!?! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1860 return filter(None, [row[0] for row in l]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1861 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1862 def count(self): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1863 '''Get the number of nodes in this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1864 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1865 If the returned integer is 'numnodes', the ids of all the nodes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1866 in this class run from 1 to numnodes, and numnodes+1 will be the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1867 id of the next node to be created in this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1868 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1869 return self.db.countnodes(self.classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1870 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1871 # Manipulating properties: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1872 def getprops(self, protected=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1873 '''Return a dictionary mapping property names to property objects. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1874 If the "protected" flag is true, we include protected properties - |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1875 those which may not be modified. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1876 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1877 d = self.properties.copy() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1878 if protected: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1879 d['id'] = String() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1880 d['creation'] = hyperdb.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1881 d['activity'] = hyperdb.Date() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1882 d['creator'] = hyperdb.Link('user') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1883 return d |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1884 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1885 def addprop(self, **properties): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1886 '''Add properties to this class. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1887 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1888 The keyword arguments in 'properties' must map names to property |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1889 objects, or a TypeError is raised. None of the keys in 'properties' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1890 may collide with the names of existing properties, or a ValueError |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1891 is raised before any properties have been added. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1892 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1893 for key in properties.keys(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1894 if self.properties.has_key(key): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1895 raise ValueError, key |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1896 self.properties.update(properties) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1897 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1898 def index(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1899 '''Add (or refresh) the node to search indexes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1900 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1901 # find all the String properties that have indexme |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1902 for prop, propclass in self.getprops().items(): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1903 if isinstance(propclass, String) and propclass.indexme: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1904 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1905 value = str(self.get(nodeid, prop)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1906 except IndexError: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1907 # node no longer exists - entry should be removed |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1908 self.db.indexer.purge_entry((self.classname, nodeid, prop)) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1909 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1910 # and index them under (classname, nodeid, property) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1911 self.db.indexer.add_text((self.classname, nodeid, prop), |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1912 value) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1913 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1914 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1915 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1916 # Detector interface |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1917 # |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1918 def audit(self, event, detector): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1919 '''Register a detector |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1920 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1921 l = self.auditors[event] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1922 if detector not in l: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1923 self.auditors[event].append(detector) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1924 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1925 def fireAuditors(self, action, nodeid, newvalues): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1926 '''Fire all registered auditors. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1927 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1928 for audit in self.auditors[action]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1929 audit(self.db, self, nodeid, newvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1930 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1931 def react(self, event, detector): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1932 '''Register a detector |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1933 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1934 l = self.reactors[event] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1935 if detector not in l: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1936 self.reactors[event].append(detector) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1937 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1938 def fireReactors(self, action, nodeid, oldvalues): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1939 '''Fire all registered reactors. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1940 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1941 for react in self.reactors[action]: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1942 react(self.db, self, nodeid, oldvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1943 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1944 class FileClass(Class): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1945 '''This class defines a large chunk of data. To support this, it has a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1946 mandatory String property "content" which is typically saved off |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1947 externally to the hyperdb. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1948 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1949 The default MIME type of this data is defined by the |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1950 "default_mime_type" class attribute, which may be overridden by each |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1951 node if the class defines a "type" String property. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1952 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1953 default_mime_type = 'text/plain' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1954 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1955 def create(self, **propvalues): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1956 ''' snaffle the file propvalue and store in a file |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1957 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1958 content = propvalues['content'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1959 del propvalues['content'] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1960 newid = Class.create(self, **propvalues) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1961 self.db.storefile(self.classname, newid, None, content) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1962 return newid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1963 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1964 def import_list(self, propnames, proplist): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1965 ''' Trap the "content" property... |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1966 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1967 # dupe this list so we don't affect others |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1968 propnames = propnames[:] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1969 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1970 # extract the "content" property from the proplist |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1971 i = propnames.index('content') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1972 content = eval(proplist[i]) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1973 del propnames[i] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1974 del proplist[i] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1975 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1976 # do the normal import |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1977 newid = Class.import_list(self, propnames, proplist) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1978 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1979 # save off the "content" file |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1980 self.db.storefile(self.classname, newid, None, content) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1981 return newid |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1982 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1983 _marker = [] |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1984 def get(self, nodeid, propname, default=_marker, cache=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1985 ''' trap the content propname and get it from the file |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1986 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1987 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1988 poss_msg = 'Possibly a access right configuration problem.' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1989 if propname == 'content': |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1990 try: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1991 return self.db.getfile(self.classname, nodeid, None) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1992 except IOError, (strerror): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1993 # BUG: by catching this we donot see an error in the log. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1994 return 'ERROR reading file: %s%s\n%s\n%s'%( |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1995 self.classname, nodeid, poss_msg, strerror) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1996 if default is not self._marker: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1997 return Class.get(self, nodeid, propname, default, cache=cache) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1998 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1999 return Class.get(self, nodeid, propname, cache=cache) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2000 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2001 def getprops(self, protected=1): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2002 ''' In addition to the actual properties on the node, these methods |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2003 provide the "content" property. If the "protected" flag is true, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2004 we include protected properties - those which may not be |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2005 modified. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2006 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2007 d = Class.getprops(self, protected=protected).copy() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2008 d['content'] = hyperdb.String() |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2009 return d |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2010 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2011 def index(self, nodeid): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2012 ''' Index the node in the search index. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2013 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2014 We want to index the content in addition to the normal String |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2015 property indexing. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2016 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2017 # perform normal indexing |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2018 Class.index(self, nodeid) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2019 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2020 # get the content to index |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2021 content = self.get(nodeid, 'content') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2022 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2023 # figure the mime type |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2024 if self.properties.has_key('type'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2025 mime_type = self.get(nodeid, 'type') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2026 else: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2027 mime_type = self.default_mime_type |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2028 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2029 # and index! |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2030 self.db.indexer.add_text((self.classname, nodeid, 'content'), content, |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2031 mime_type) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2032 |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2033 # XXX deviation from spec - was called ItemClass |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2034 class IssueClass(Class, roundupdb.IssueClass): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2035 # Overridden methods: |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2036 def __init__(self, db, classname, **properties): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2037 '''The newly-created class automatically includes the "messages", |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2038 "files", "nosy", and "superseder" properties. If the 'properties' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2039 dictionary attempts to specify any of these properties or a |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2040 "creation" or "activity" property, a ValueError is raised. |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2041 ''' |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2042 if not properties.has_key('title'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2043 properties['title'] = hyperdb.String(indexme='yes') |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2044 if not properties.has_key('messages'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2045 properties['messages'] = hyperdb.Multilink("msg") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2046 if not properties.has_key('files'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2047 properties['files'] = hyperdb.Multilink("file") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2048 if not properties.has_key('nosy'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2049 # note: journalling is turned off as it really just wastes |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2050 # space. this behaviour may be overridden in an instance |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2051 properties['nosy'] = hyperdb.Multilink("user", do_journal="no") |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2052 if not properties.has_key('superseder'): |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2053 properties['superseder'] = hyperdb.Multilink(classname) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2054 Class.__init__(self, db, classname, **properties) |
|
83f33642d220
[[Metadata associated with this commit was garbled during conversion from CVS
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2055 |
