[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/RDB - ResultSet.py:1.1 Row.py:1.1 Util.py:1.1 ZopeConnection.py:1.1 ZopeCursor.py:1.1 ZopeDBTransactionManager.py:1.1 IDBIConnection.py:1.2 IDBICursor.py:1.2 IResultSet.py:1.3 IZopeConnection.py:1.2 IZopeCursor.py:1.2 IZopeDatabaseAdapter.py:1.2 ZopeDatabaseAdapter.py:1.2 Connection.stx:NONE IConnection.py:NONE IDatabaseAdapter.py:NONE SQLQuery.stx:NONE
Kapil Thangavelu
kvthan@wm.edu
Tue, 25 Jun 2002 11:41:46 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB
In directory cvs.zope.org:/tmp/cvs-serv5574
Modified Files:
IDBIConnection.py IDBICursor.py IResultSet.py
IZopeConnection.py IZopeCursor.py IZopeDatabaseAdapter.py
ZopeDatabaseAdapter.py
Added Files:
ResultSet.py Row.py Util.py ZopeConnection.py ZopeCursor.py
ZopeDBTransactionManager.py
Removed Files:
Connection.stx IConnection.py IDatabaseAdapter.py SQLQuery.stx
Log Message:
lots of work on rdb :-) almost there.
=== Added File Zope3/lib/python/Zope/App/RDB/ResultSet.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.
#
##############################################################################
"""XXX short summary goes here.
XXX longer description goes here.
$Id: ResultSet.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
class ResultSet(list):
def __init__(self, names, data, row_klass):
self.names = names
self.row_klass = row_klass
super(ResultSet).__init__(self, data)
def __getitem__(self, idx):
return self.row_klass(list.__getitem__(idx))
=== Added File Zope3/lib/python/Zope/App/RDB/Row.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.
#
##############################################################################
"""XXX short summary goes here.
XXX longer description goes here.
$Id: Row.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
from Zope.Security import Checker
class row(object):
def __init__(self, data):
for k, v in zip(self.__slots__, data):
setattr(self, k, v)
def row_class_factory(columns):
klass_namespace = {}
klass_namespace['__Security_checker__']=Checker.NamesChecker(columns)
klass_namespace['__slots__']=tuple(columns)
return type('row class', (row,), klass_namespace)
=== Added File Zope3/lib/python/Zope/App/RDB/Util.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.
#
##############################################################################
"""XXX short summary goes her
XXX longer description goes here.
$Id: Util.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
import Row
import ResultSet
def query_for_results(conn, query):
# need to typing
cursor = conn.cursor()
cursor.execute(query)
columns = [c[0] for c in cursor.description]
row_klass = Row.row_class_factory(columns)
return ResultSet(columns,
cursor.fetchall(),
row_klass)
=== Added File Zope3/lib/python/Zope/App/RDB/ZopeConnection.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.
#
##############################################################################
"""
$Id: ZopeConnection.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
from IZopeConnection import IZopeConnection
from IZopeCursor import IZopeCursor
from ZopeCursor import ZopeCursor
from ZopeDBTransactionManager import ZopeDBTransactionManager
from Transaction import get_transaction
class ZopeConnection:
__implements__ = IZopeConnection
def __init__(self, conn):
self.conn = conn
# flag for txn registration status
self._txn_registered = 0
def cursor(self):
"""Returns an IZopeCursor"""
return ZopeCursor(self.conn.cursor(), self)
def registerForTxn(self):
if self._txn_registered:
return
tm = ZopeDBTransactionManager(self)
t = get_transaction()
t.register(tm)
self._txn_registered = 1
def unregisterFromTxn(self):
self._txn_registered = 0
def __getattr__(self, key):
return getattr(self.conn, key)
def getTypeInfo(self):
# Stubbed for now
pass
=== Added File Zope3/lib/python/Zope/App/RDB/ZopeCursor.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.
#
##############################################################################
"""
$Id: ZopeCursor.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
from IZopeCursor import IZopeCursor
class ZopeCursor:
__implements__ = IZopeCursor
def __init__(self, cursor, connection):
self.cursor = cursor
self.connection = connection
def execute(self, operation, parameters=None):
"""Executes an operation, registering the underlying
connection with the transaction system. """
self.connection.registerForTxn()
return self.cursor.execute(operation, parameters)
def __getattr__(self, key):
return getattr(self.cursor, key)
=== Added File Zope3/lib/python/Zope/App/RDB/ZopeDBTransactionManager.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.
#
##############################################################################
""" Zope RDBMS Transaction Integration.
Provides a proxy for interaction between the zope transaction
framework and the db-api connection. Databases which
want to support sub transactions need to implement their own
proxy.
$Id: ZopeDBTransactionManager.py,v 1.1 2002/06/25 15:41:45 k_vertigo Exp $
"""
from Transaction.IDataManager import IDataManager
class ZopeDBTransactionManager:
__implements__ = IDataManager
############################################################
# Implementation methods for interface
# IDataManager.py
###
# Subtransactions methods moved.
#
def __init__(self, dbconn):
"""
callback is a function invoked when the
transaction is finished.
"""
self.dbconn = dbconn
self._vote = 0
def abort(self, *ignored):
'See Transaction.IDataManager.IDataManager'
try: self.dbconn.rollback()
finally: self.dbconn.unregisterFromTxn()
def tpc_vote(self, *ignored):
'See Transaction.IDataManager.IDataManager'
self._vote = 1
def tpc_finish(self, *ignored):
'See Transaction.IDataManager.IDataManager'
if self._vote:
try: self.dbconn.commit()
finally: self.dbconn.unregisterFromTxn()
tpc_abort = abort
def tpc_begin(self, *ignored):
'See Transaction.IDataManager.IDataManager'
def commit(self, *ignored):
'See Transaction.IDataManager.IDataManager'
#
############################################################
=== Zope3/lib/python/Zope/App/RDB/IDBIConnection.py 1.1 => 1.2 ===
attempted with the connection. The same applies to all cursor objects
trying to use the connection. """
+
+
+
+
+
+
+
=== Zope3/lib/python/Zope/App/RDB/IDBICursor.py 1.1 => 1.2 ===
"""
-from Interface import Interface, Attribute
+from Interface import Interface
+from Interface.Attribute import Attribute
+
+arraysize=1 # default constant, symbolic
class IDBICursor(Interface):
"""DB API ICursor interface"""
@@ -98,7 +101,7 @@
executeXXX() did not produce any result set or no call was issued yet.
"""
- def fetchmany(size=ICursor.arraysize):
+ def fetchmany(size=arraysize):
"""Fetch the next set of rows of a query result, returning a sequence of
sequences (e.g. a list of tuples). An empty sequence is returned when
no more rows are available.
=== Zope3/lib/python/Zope/App/RDB/IResultSet.py 1.2 => 1.3 ===
-
=== Zope3/lib/python/Zope/App/RDB/IZopeConnection.py 1.1 => 1.2 ===
from IDBIConnection import IDBIConnection
from IDBITypeInfoProvider import IDBITypeInfoProvider
-from Transactions.IDataManager import IDataManager
-class IZopeConnection(IDBIConnection, IDataManager, IDBITypeInfoProvider):
+
+class IZopeConnection(IDBIConnection, IDBITypeInfoProvider):
def cursor():
- """
- return a ZopeCursor object
- """
-
+ """Return an IZopeCursor object"""
+
+ def registerForTxn():
+ """Registers the Connection with the Zope Transaction
+ framework.
+
+ This method should only be inovoked by the Zope/DB transaction
+ manager."""
+
+ def unregisterFromTxn():
+ """Unregister the connection from the Zope transaction.
+
+ This method should only be inovoked by the Zope/DB transaction
+ manager!!!."""
+
+
+
=== Zope3/lib/python/Zope/App/RDB/IZopeCursor.py 1.1 => 1.2 ===
class IZopeCursor(IDBICursor):
- """an iCursor that integrates with zope's transactions"""
+ """An ICursor that integrates with Zope's transactions"""
def execute(operation, parameters=None):
- """executes an operation, registering the underlying connection with
+ """Executes an operation, registering the underlying connection with
the transaction system.
See ICursor for more detailed execute information.
"""
def executemany(operation, seq_of_parameters=None):
- """executes an operation, registering the underlying connection with
+ """Executes an operation, registering the underlying connection with
the transaction system.
See ICursor for more detailed executemany information.
=== Zope3/lib/python/Zope/App/RDB/IZopeDatabaseAdapter.py 1.1 => 1.2 ===
def __call__():
- """return an Iconnection object"""
+ """return an IZopeConnection object"""
=== Zope3/lib/python/Zope/App/RDB/ZopeDatabaseAdapter.py 1.1 => 1.2 ===
from Zope.Configuration.name import resolve
-
+from Persistence import Persistent
+from Zope.App.RDB.IZopeDatabaseAdapter import IZopeDatabaseAdapter
class ZopeDatabaseAdapter(Persistent):
__implements__ = IZopeDatabaseAdapter
@@ -44,4 +45,5 @@
database=self.database)
return self._v_connection
-
+
+
=== Removed File Zope3/lib/python/Zope/App/RDB/Connection.stx ===
=== Removed File Zope3/lib/python/Zope/App/RDB/IConnection.py ===
=== Removed File Zope3/lib/python/Zope/App/RDB/IDatabaseAdapter.py ===
=== Removed File Zope3/lib/python/Zope/App/RDB/SQLQuery.stx ===