[Zope-CVS] CVS: Products/Ape/lib/apelib/sql - oidgen.py:1.1.2.1
classification.py:1.5.4.1 properties.py:1.5.2.1
security.py:1.4.6.1 sqlbase.py:1.9.2.1 structure.py:1.5.6.1
keygen.py:NONE
Shane Hathaway
shane at zope.com
Sat Dec 20 02:31:37 EST 2003
Update of /cvs-repository/Products/Ape/lib/apelib/sql
In directory cvs.zope.org:/tmp/cvs-serv30479/sql
Modified Files:
Tag: ape-0_8-branch
classification.py properties.py security.py sqlbase.py
structure.py
Added Files:
Tag: ape-0_8-branch
oidgen.py
Removed Files:
Tag: ape-0_8-branch
keygen.py
Log Message:
Continued refactoring and renaming.
Over 60 tests now pass.
=== Added File Products/Ape/lib/apelib/sql/oidgen.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""SQL OID generator
$Id: oidgen.py,v 1.1.2.1 2003/12/20 07:31:05 shane Exp $
"""
from apelib.core import interfaces
import sqlbase
class SQLOIDGenerator (sqlbase.SQLGatewayBase):
__implements__ = (interfaces.IOIDGenerator,
interfaces.IDatabaseInitializer)
table_base_name = 'oid_seq'
column_defs = ()
def init(self, event):
conn = event.connections[self.conn_name]
first_time = 0
try:
rows = self.execute(event, 'sequence_check', 1)
if len(rows) == 0:
first_time = 1
except conn.error:
conn.db.rollback()
self.execute(event, 'sequence_create')
first_time = 1
if first_time:
self.execute(event, 'sequence_insert')
if event.clearing():
self.execute(event, 'sequence_clear')
conn.db.commit()
def new_oid(self, event, name, stored):
if not stored:
raise exceptions.ConfigurationError(
'OIDs generated by SQLOIDGenerator must be stored')
if interfaces.ISDEvent.isImplementedBy(event):
# Request that the other side do the work (for ZEO)
n = event.obj_db.new_oid()
else:
self.execute(event, 'sequence_update')
n = self.execute(event, 'sequence_read', 1)[0][0]
return str(n)
=== Products/Ape/lib/apelib/sql/classification.py 1.5 => 1.5.4.1 ===
--- Products/Ape/lib/apelib/sql/classification.py:1.5 Wed Jul 9 11:40:06 2003
+++ Products/Ape/lib/apelib/sql/classification.py Sat Dec 20 02:31:05 2003
@@ -17,7 +17,6 @@
"""
from apelib.core.schemas import FieldSchema
-from apelib.core.exceptions import NoStateFoundError
from sqlbase import SQLGatewayBase
@@ -35,8 +34,7 @@
)
def load(self, event):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
classification = {}
if items:
rec = items[0]
@@ -45,12 +43,11 @@
if rec[1]:
classification['mapper_name'] = rec[1]
else:
- raise NoStateFoundError(key)
+ raise KeyError(event.oid)
return classification, rec
def store(self, event, classification):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
cn = classification.get('class_name', '')
mn = classification.get('mapper_name', '')
kw = {'key': key, 'class_name': cn, 'mapper_name': mn}
=== Products/Ape/lib/apelib/sql/properties.py 1.5 => 1.5.2.1 ===
--- Products/Ape/lib/apelib/sql/properties.py:1.5 Mon Aug 11 14:02:16 2003
+++ Products/Ape/lib/apelib/sql/properties.py Sat Dec 20 02:31:05 2003
@@ -196,12 +196,8 @@
self.var_props = SQLProperties(conn_name=conn_name)
self.fixed_props = {} # class name -> SQLFixedProperties instance
- def getSchema(self):
- return self.schema
-
- def getSources(self, event):
+ def getPollSources(self, event):
return None
-
def init(self, event):
self.var_props.init(event)
=== Products/Ape/lib/apelib/sql/security.py 1.4 => 1.4.6.1 ===
--- Products/Ape/lib/apelib/sql/security.py:1.4 Mon May 19 15:32:34 2003
+++ Products/Ape/lib/apelib/sql/security.py Sat Dec 20 02:31:05 2003
@@ -34,22 +34,20 @@
table_base_name = 'security'
def load(self, event):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
items.sort()
return items, tuple(items)
def store(self, event, state):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
items.sort()
state = list(state)
state.sort()
if state != items:
- self.execute(event, 'delete', key=key)
+ self.execute(event, 'delete', oid=event.oid)
for row in state:
self.execute(
- event, 'insert', key=key, declaration_type=row[0],
+ event, 'insert', oid=event.oid, declaration_type=row[0],
role=row[1], permission=row[2], username=row[3])
return tuple(state)
@@ -104,17 +102,16 @@
def load(self, event):
- key = event.getKeychain()[-1]
- rows = self.execute(event, 'users', 'read', 1, key=key)
+ rows = self.execute(event, 'users', 'read', 1, oid=event.oid)
data = {}
for id, password in rows:
data[id] = (password, [], [])
- rows = self.execute(event, 'user_roles', 'read', 1, key=key)
+ rows = self.execute(event, 'user_roles', 'read', 1, oid=event.oid)
for id, role in rows:
row = data.get(id)
if row is not None:
row[1].append(role)
- rows = self.execute(event, 'user_domains', 'read', 1, key=key)
+ rows = self.execute(event, 'user_domains', 'read', 1, oid=event.oid)
for id, domain in rows:
row = data.get(id)
if row is not None:
@@ -127,9 +124,6 @@
def store(self, event, state):
- keychain = event.getKeychain()
- keychain1 = keychain[:-1]
- key = long(keychain[-1])
old_rows, old_serial = self.load(event)
new_dict = {}
for rec in state:
@@ -144,9 +138,11 @@
new_row = new_dict.get(id)
if new_row is None:
# Remove this row.
- self.execute(event, 'users', 'delete', key=key, id=id)
- self.execute(event, 'user_roles', 'delete', key=key, id=id)
- self.execute(event, 'user_domains', 'delete', key=key, id=id)
+ self.execute(event, 'users', 'delete', oid=event.oid, id=id)
+ self.execute(
+ event, 'user_roles', 'delete', oid=event.oid, id=id)
+ self.execute(
+ event, 'user_domains', 'delete', oid=event.oid, id=id)
elif new_row == old_row:
# Don't need to update this row.
del new_dict[id]
@@ -160,29 +156,31 @@
if old_password != password:
# Update the password.
self.execute(event, 'users', 'update',
- key=key, id=id, password=password)
+ oid=event.oid, id=id, password=password)
else:
# Insert a new record.
self.execute(event, 'users', 'insert',
- key=key, id=id, password=password)
+ oid=event.oid, id=id, password=password)
old_roles = ()
old_domains = ()
# Update the role list.
if tuple(roles) != tuple(old_roles):
- self.execute(event, 'user_roles', 'delete', key=key, id=id)
+ self.execute(
+ event, 'user_roles', 'delete', oid=event.oid, id=id)
for role in roles:
assert role
self.execute(event, 'user_roles', 'insert',
- key=key, id=id, role=role)
+ oid=event.oid, id=id, role=role)
# Update the domain list.
if tuple(domains) != tuple(old_domains):
- self.execute(event, 'user_domains', 'delete', key=key, id=id)
+ self.execute(
+ event, 'user_domains', 'delete', oid=event.oid, id=id)
for domain in domains:
assert domain
self.execute(event, 'user_domains', 'insert',
- key=key, id=id, domain=domain)
+ oid=event.oid, id=id, domain=domain)
state = list(state)
state.sort()
=== Products/Ape/lib/apelib/sql/sqlbase.py 1.9 => 1.9.2.1 ===
--- Products/Ape/lib/apelib/sql/sqlbase.py:1.9 Wed Jul 30 17:33:05 2003
+++ Products/Ape/lib/apelib/sql/sqlbase.py Sat Dec 20 02:31:05 2003
@@ -31,13 +31,8 @@
def __init__(self, conn_name='db'):
self.conn_name = conn_name
- if self.column_defs is None:
- schema = self.getSchema()
- if schema is not None:
- self.column_defs = tuple(schema.getColumnDefs())
-
- def getSchema(self):
- return self.schema
+ if self.column_defs is None and self.schema is not None:
+ self.column_defs = tuple(self.schema.getColumnDefs())
def init(self, event):
conn = event.getConnection(self.conn_name)
@@ -53,7 +48,7 @@
conn.db.commit()
def execute(self, event, operation, *args, **kw):
- conn = event.getConnection(self.conn_name)
+ conn = event.connections[self.conn_name]
query = conn.getQuery(
self.table_base_name, self.column_defs, operation)
if query == '':
@@ -67,5 +62,5 @@
def store(self, event, obj):
raise NotImplementedError, "abstract method"
- def getSources(self, event):
+ def getPollSources(self, event):
return None
=== Products/Ape/lib/apelib/sql/structure.py 1.5 => 1.5.6.1 ===
--- Products/Ape/lib/apelib/sql/structure.py:1.5 Mon May 19 15:32:34 2003
+++ Products/Ape/lib/apelib/sql/structure.py Sat Dec 20 02:31:05 2003
@@ -34,8 +34,7 @@
)
def load(self, event):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
if items:
state = items[0][0]
else:
@@ -43,11 +42,10 @@
return state, state
def store(self, event, state):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
col_name = self.column_defs[0][0]
conn = event.getConnection(self.conn_name)
- kw = {'key': key, col_name: conn.asBinary(state)}
+ kw = {'oid': event.oid, col_name: conn.asBinary(state)}
if items:
# update.
self.execute(event, 'update', **kw)
@@ -64,51 +62,41 @@
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
- schema.addField('keychain', 'keychain')
+ schema.addField('oid', 'string')
table_base_name = 'folder_items'
column_defs = (
('name', 'string', 1),
- ('child_key', 'int', 0),
+ ('child_oid', 'int', 0),
)
def load(self, event):
- keychain = event.getKeychain()
- key = long(keychain[-1])
- prefix = keychain[:-1]
- rows = self.execute(event, 'read', 1, key=key)
+ rows = self.execute(event, 'read', 1, oid=event.oid)
rows.sort()
- res = [(row[0], prefix + (long(row[1]),)) for row in rows]
+ res = [(row[0], long(row[1])) for row in rows]
return res, tuple(res)
def store(self, event, state):
- keychain = event.getKeychain()
- keychain1 = keychain[:-1]
- key = long(keychain[-1])
state_dict = {}
- for name, child_keychain in state:
+ for name, child_oid in state:
state_dict[name] = 1
- rows = self.execute(event, 'read', 1, key=key)
+ rows = self.execute(event, 'read', 1, oid=event.oid)
db_dict = {}
- for name, child_key in rows:
+ for name, child_oid in rows:
if state_dict.has_key(name):
- db_dict[name] = child_key
+ db_dict[name] = child_oid
else:
# Remove this item from the database.
- self.execute(event, 'delete', key=key, name=name)
+ self.execute(event, 'delete', oid=event.oid, name=name)
state = list(state)
state.sort()
- for name, child_keychain in state:
- if child_keychain[:-1] != keychain1:
- raise ValueError(
- "SQLFolderItems cannot store cross-domain references")
- child_key = long(child_keychain[-1])
- kw = {'key': key, 'name': name, 'child_key': child_key}
+ for name, child_oid in state:
+ kw = {'oid': event.oid, 'name': name, 'child_oid': child_oid}
if db_dict.has_key(name):
- if db_dict[name] != child_key:
+ if db_dict[name] != child_oid:
# Change this item to point to a different OID.
self.execute(event, 'update', **kw)
else:
@@ -130,15 +118,16 @@
table_base_name = 'folder_items'
- column_defs = (('child_key', 'int', 1),
- ('name', 'string', 0),)
+ column_defs = (
+ ('child_oid', 'int', 1),
+ ('name', 'string', 0),
+ )
def init(self, event):
pass
def load(self, event):
- key = long(event.getKey())
- rows = self.execute(event, 'simple_search', 1, child_key=key)
+ rows = self.execute(event, 'simple_search', 1, child_oid=event.oid)
assert len(rows) >= 1
name = rows[0][1] # Accept only the first result
return name, None
@@ -173,8 +162,7 @@
)
def load(self, event):
- key = long(event.getKey())
- items = self.execute(event, 'read', 1, key=key)
+ items = self.execute(event, 'read', 1, oid=event.oid)
if items:
state = long(items[0][0])
else:
@@ -182,10 +170,9 @@
return state, state
def store(self, event, state):
- key = long(event.getKey())
state = long(state)
- items = self.execute(event, 'read', 1, key=key)
- kw = {'key': key, 'mtime': state}
+ items = self.execute(event, 'read', 1, oid=event.oid)
+ kw = {'oid': event.oid, 'mtime': state}
if items:
# update.
self.execute(event, 'update', **kw)
=== Removed File Products/Ape/lib/apelib/sql/keygen.py ===
More information about the Zope-CVS
mailing list