I'm trying to understand the whole transaction mechanism in WebKit.

I attempted to subclass page calling it DatabasePage with methods
for connection management and hook a hook around sleep to manage
the commit/rollback for the page.  This works well for pages
without errors. The commit is called for the conenction that was
used on the page.  The problem occurrs if an error is introduced. 
The awake respond sleep cycle is broken and my rollback never gets
called.

Where would be the right place to hook into the transaction to
support automatic commit/rollback?

--Karl

Here is the DatabasePage prototype.  Keep in mind that this is just
an experiment.



#!/usr/bin/env python

from ConnectionPool import ConnectionPool
from WebKit.Page import Page

class DatabasePage(Page):
    """Manage database connections in the pool."""
    # XXX - What if we want to have more than one connection?
    #       eg. one to PostgreSQL and one to Oracle?
    #
    # XXX - Is this the right place to be creating and managing 
    #       database connections?
    #
    # XXX - Do we want to hold a database connection for the 
    #       duration of the page?  How will this affect the
    #       total numer of connections allowed if we increase
    #       the MAX_THREADS?

    def getConnection(self):
        connectionPool = ConnectionPool()
        conn = connectionPool.get()
        self._connections.append(conn)
        return conn

    def putConnection(self, conn):
        connectionPool = ConnectionPool()
        connectionPool.put(conn)

    def awake(self, transaction):
        print 'awake called in DatabasePage'
        Page.awake(self, transaction)
        self._connections = []
        assert self._connections is not None

    def sleep(self, transaction):
        print 'sleep called in DatabasePage'
        if transaction.errorOccurred():
            for conn in self._connections:
                print 'rollback'
                conn.rollback()
                self.putConnection(conn)
        else:
            for conn in self._connections:
                print 'commit'
                conn.commit()
                self.putConnection(conn)
        self._connections = None
        Page.sleep(self, transaction)


__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://http://taxes.yahoo.com/

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to