[Zope-CVS] CVS: Products/AdaptableStorage/gateway_sql - SQLProperties.py:1.1 public.py:1.3
Shane Hathaway
shane@zope.com
Fri, 3 Jan 2003 17:04:52 -0500
Update of /cvs-repository/Products/AdaptableStorage/gateway_sql
In directory cvs.zope.org:/tmp/cvs-serv20380/gateway_sql
Modified Files:
public.py
Added Files:
SQLProperties.py
Log Message:
Added PropertyManager support.
=== Added File Products/AdaptableStorage/gateway_sql/SQLProperties.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 properties gateway
$Id: SQLProperties.py,v 1.1 2003/01/03 22:04:19 shane Exp $
"""
from mapper_public import IGateway, RowSequenceSchema
from SQLGatewayBase import SQLGatewayBase
class SQLProperties (SQLGatewayBase):
__implements__ = IGateway
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
schema.addField('type', 'string')
schema.addField('data', 'string')
table_base_name = 'properties'
checkexist_sql = '''SELECT key FROM %(table)s LIMIT 1'''
create_sql = '''CREATE TABLE %(table)s (
key int,
id character varying(255),
type character varying(255),
data bytea
)'''
read_sql = '''SELECT id, type, data from %(table)s
WHERE key = %(key)s'''
update_sql = '''UPDATE %(table)s
SET type = %(type)s, data = %(data)s
WHERE key = %(key)s and id = %(id)s'''
insert_sql = '''INSERT INTO %(table)s
(key, id, type, data)
VALUES (%(key)s, %(id)s, %(type)s, %(data)s)'''
delete_sql = '''DELETE FROM %(table)s
WHERE key = %(key)s and id = %(id)s'''
def getSchema(self):
return self.schema
def load(self, event):
key = int(event.getKeychain()[-1])
items = self.execute(self.read_sql, 1, key=key)
items.sort()
return items, tuple(items)
def store(self, event, state):
key = int(event.getKeychain()[-1])
items = self.execute(self.read_sql, 1, key=key)
state_dict = {}
for row in state:
id = row[0]
state_dict[id] = row
items_dict = {}
for old_row in items:
id = old_row[0]
items_dict[id] = old_row
state_row = state_dict.get(id)
if state_row is None:
# Remove a property
self.execute(self.delete_sql, key=key, id=id)
elif old_row != state_row:
# Update a property
id, t, v = state_row
data = self.conn.asBinary(v)
self.execute(self.update_sql,
key=key, id=id, type=t, data=data)
for row in state:
if not items_dict.has_key(row[0]):
# Add a property
id, t, v = row
data = self.conn.asBinary(v)
self.execute(self.insert_sql,
key=key, id=id, type=t, data=data)
state = list(state)
state.sort()
return tuple(state)
=== Products/AdaptableStorage/gateway_sql/public.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/gateway_sql/public.py:1.2 Mon Dec 23 23:29:32 2002
+++ Products/AdaptableStorage/gateway_sql/public.py Fri Jan 3 17:04:19 2003
@@ -23,5 +23,5 @@
from SQLItemId import SQLItemId
from SQLKeychainGenerator import SQLKeychainGenerator
from SQLObjectData import SQLObjectData
+from SQLProperties import SQLProperties
from SQLRemainder import SQLRemainder
-