[Zope-CVS] CVS: Products/Ape/lib/apelib/sql - classification.py:1.4 keygen.py:1.6 properties.py:1.4 security.py:1.4 sqlbase.py:1.7 structure.py:1.5
Shane Hathaway
shane@zope.com
Mon, 19 May 2003 15:33:05 -0400
Update of /cvs-repository/Products/Ape/lib/apelib/sql
In directory cvs.zope.org:/tmp/cvs-serv1802/sql
Modified Files:
classification.py keygen.py properties.py security.py
sqlbase.py structure.py
Log Message:
Provided new machinery for initializing databases, especially creating
tables.
- Added two new interfaces, IDatabaseInitializer and
IDatabaseInitEvent. The initializer.init(event) gets called when new
connections are made to the database.
- All gateways in the sql subpackage now implement IDatabaseInitializer.
- Added methods to mappers for configuring and using initializers.
- Renamed setUp() to init(), since it's easier to spell.
- Avoided calling initializers more than once.
- Renamed 'object' to 'obj' in some places.
=== Products/Ape/lib/apelib/sql/classification.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/sql/classification.py:1.3 Sun May 18 00:16:29 2003
+++ Products/Ape/lib/apelib/sql/classification.py Mon May 19 15:32:34 2003
@@ -16,7 +16,6 @@
$Id$
"""
-from apelib.core.interfaces import IGateway
from apelib.core.schemas import FieldSchema
from apelib.core.exceptions import NoStateFoundError
from sqlbase import SQLGatewayBase
@@ -24,7 +23,7 @@
class SQLClassification (SQLGatewayBase):
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = FieldSchema('classification', 'classification')
=== Products/Ape/lib/apelib/sql/keygen.py 1.5 => 1.6 ===
--- Products/Ape/lib/apelib/sql/keygen.py:1.5 Sun May 18 00:16:29 2003
+++ Products/Ape/lib/apelib/sql/keygen.py Mon May 19 15:32:34 2003
@@ -16,20 +16,20 @@
$Id$
"""
-from apelib.core.interfaces import IKeychainGenerator, ISDEvent
-from apelib.core.schemas import FieldSchema
-from apelib.core.exceptions import ConfigurationError
-from sqlbase import SQLGatewayBase
+from apelib.core import interfaces, exceptions
+import sqlbase
-class SQLKeychainGenerator (SQLGatewayBase):
- __implements__ = IKeychainGenerator
+class SQLKeychainGenerator (sqlbase.SQLGatewayBase):
+
+ __implements__ = (interfaces.IKeychainGenerator,
+ interfaces.IDatabaseInitializer)
table_base_name = 'key_seq'
column_defs = ()
- def setUp(self, event, clear_all=0):
+ def init(self, event):
conn = event.getConnection(self.conn_name)
first_time = 0
try:
@@ -42,15 +42,15 @@
first_time = 1
if first_time:
self.execute(event, 'sequence_insert')
- if clear_all:
+ if event.clearing():
self.execute(event, 'sequence_clear')
conn.db.commit()
def makeKeychain(self, event, name, stored):
if not stored:
- raise ConfigurationError(
+ raise exceptions.ConfigurationError(
'Keychains generated by SQLKeychain must be stored')
- if ISDEvent.isImplementedBy(event):
+ if interfaces.ISDEvent.isImplementedBy(event):
# Request that the other side do the work (for ZEO)
n = event.getKeyedObjectSystem().newKey()
else:
=== Products/Ape/lib/apelib/sql/properties.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/sql/properties.py:1.3 Sun May 18 00:16:29 2003
+++ Products/Ape/lib/apelib/sql/properties.py Mon May 19 15:32:34 2003
@@ -16,7 +16,6 @@
$Id$
"""
-from apelib.core.interfaces import IGateway
from apelib.core.schemas import RowSequenceSchema
from sqlbase import SQLGatewayBase
@@ -25,7 +24,7 @@
"""SQL properties gateway
"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
=== Products/Ape/lib/apelib/sql/security.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/sql/security.py:1.3 Sun May 18 00:16:29 2003
+++ Products/Ape/lib/apelib/sql/security.py Mon May 19 15:32:34 2003
@@ -16,7 +16,6 @@
$Id$
"""
-from apelib.core.interfaces import IGateway
from apelib.core.schemas import RowSequenceSchema
from sqlbase import SQLGatewayBase
@@ -24,7 +23,7 @@
class SQLSecurityAttributes (SQLGatewayBase):
"""SQL security attribute storage"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = RowSequenceSchema()
schema.addField('declaration_type', 'string')
@@ -59,7 +58,7 @@
class SQLUserList (SQLGatewayBase):
"""Stores and retrieves all users for a folder at once."""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
@@ -77,21 +76,21 @@
}
- def setUp(self, event, clear_all=0):
+ def init(self, event):
conn = event.getConnection(self.conn_name)
try:
- self.execute(event, 'users', 'check')
+ if event.clearing():
+ self.execute(event, 'users', 'clear')
+ self.execute(event, 'user_roles', 'clear')
+ self.execute(event, 'user_domains', 'clear')
+ else:
+ self.execute(event, 'users', 'check')
except conn.error:
conn.db.rollback()
self.execute(event, 'users', 'create')
self.execute(event, 'user_roles', 'create')
self.execute(event, 'user_domains', 'create')
conn.db.commit()
- else:
- if clear_all:
- self.execute(event, 'users', 'clear')
- self.execute(event, 'user_roles', 'clear')
- self.execute(event, 'user_domains', 'clear')
def execute(self, event, table, operation, *args, **kw):
=== Products/Ape/lib/apelib/sql/sqlbase.py 1.6 => 1.7 ===
--- Products/Ape/lib/apelib/sql/sqlbase.py:1.6 Sun May 18 00:23:14 2003
+++ Products/Ape/lib/apelib/sql/sqlbase.py Mon May 19 15:32:34 2003
@@ -16,12 +16,15 @@
$Id$
"""
+from apelib.core.interfaces import IGateway, IDatabaseInitializer
from interfaces import ISQLConnection
class SQLGatewayBase:
"""SQL gateway base class"""
+ __implements__ = IGateway, IDatabaseInitializer
+
table_base_name = '(override this)'
schema = None # override
column_defs = None # optional override
@@ -36,18 +39,18 @@
def getSchema(self):
return self.schema
- def setUp(self, event, clear_all=0):
+ def init(self, event):
conn = event.getConnection(self.conn_name)
assert ISQLConnection.isImplementedBy(conn)
try:
- self.execute(event, 'check')
+ if event.clearing():
+ self.execute(event, 'clear')
+ else:
+ self.execute(event, 'check')
except conn.error:
conn.db.rollback()
self.execute(event, 'create')
conn.db.commit()
- else:
- if clear_all:
- self.execute(event, 'clear')
def execute(self, event, operation, *args, **kw):
conn = event.getConnection(self.conn_name)
@@ -57,4 +60,10 @@
# No query needed for this operation
return
return conn.execute(query, *args, **kw)
+
+ def load(self, event):
+ raise NotImplementedError, "abstract method"
+
+ def store(self, event, obj):
+ raise NotImplementedError, "abstract method"
=== Products/Ape/lib/apelib/sql/structure.py 1.4 => 1.5 ===
--- Products/Ape/lib/apelib/sql/structure.py:1.4 Sun May 18 00:16:29 2003
+++ Products/Ape/lib/apelib/sql/structure.py Mon May 19 15:32:34 2003
@@ -16,7 +16,6 @@
$Id$
"""
-from apelib.core.interfaces import IGateway
from apelib.core.schemas import FieldSchema, RowSequenceSchema
from sqlbase import SQLGatewayBase
@@ -24,7 +23,7 @@
class SQLObjectData (SQLGatewayBase):
"""SQL object data gateway"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = FieldSchema('data', 'string')
@@ -61,7 +60,7 @@
class SQLFolderItems (SQLGatewayBase):
"""SQL folder items gateway"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
@@ -121,11 +120,11 @@
class SQLItemId (SQLGatewayBase):
"""SQL item ID gateway.
- Piggybacks SQLFolderItems for setUp and store.
+ Piggybacks SQLFolderItems for init and store.
Makes the assumption that the item is stored in only one place.
"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = FieldSchema('id', 'string')
@@ -134,7 +133,7 @@
column_defs = (('child_key', 'int', 1),
('name', 'string', 0),)
- def setUp(self, event, clear_all=0):
+ def init(self, event):
pass
def load(self, event):
@@ -151,7 +150,7 @@
class SQLRemainder (SQLObjectData):
"""SQL remainder pickle gateway"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
table_base_name = 'remainder'
@@ -163,7 +162,7 @@
class SQLModTime (SQLGatewayBase):
"""SQL object mod time gateway"""
- __implements__ = IGateway
+ __implements__ = SQLGatewayBase.__implements__
schema = FieldSchema('mtime', 'int') # second