Package bazaar :: Module core :: Class Bazaar
[show private | hide private]
[frames | no frames]

Class Bazaar


The interface to get, modify, find and perform other tasks on application objects.

See Also: Broker bazaar.motor.Motor

Method Summary
  __init__(self, cls_list, config, dsn, dbmod, seqpattern)
Start the Bazaar layer.
  add(self, obj)
Add object to database.
  closeDBConn(self)
Close database connection.
  commit(self)
Commit pending database transactions.
  connectDB(self, dsn)
Make new database connection.
  delete(self, obj)
Delete object from database.
  find(self, cls, query, param, field)
Find objects of given class in database.
  getObjects(self, cls)
Get list of application objects.
  init(self)
Initialize the Bazaar layer.
  parseConfig(self, config)
Parse Bazaar configuration.
  reloadObjects(self, cls, now)
Reload objects from database.
  rollback(self)
Rollback database transactions.
  setConfig(self, config)
Set Bazaar configuration.
  update(self, obj)
Update object in database.

Instance Variable Summary
  brokers: Dictionary of brokers.
  cls_list: List of application classes.
  dbmod: Python DB API module.
  dsn: Python DB API database source name.
  motor: Database access object.

Method Details

__init__(self, cls_list, config=None, dsn='', dbmod=None, seqpattern=None)
(Constructor)

Start the Bazaar layer.

If database source name is not empty, then database connection is created.
Parameters:
cls_list - List of application classes.
config - Configuration object.
dsn - Database source name.
dbmod - Python DB API module.
seqpattern - Sequence command pattern.

See Also: bazaar.core.Bazaar.connectDB, bazaar.config

add(self, obj)

Add object to database.
Parameters:
obj - Object to add.

closeDBConn(self)

Close database connection.

See Also: bazaar.core.Bazaar.connectDB

commit(self)

Commit pending database transactions.

connectDB(self, dsn=None)

Make new database connection.

New database connection is created with specified database source name, which must conform to Python DB API Specification, i.e.:
   bazaar.connectDB('dbname=addressbook host=localhost port=5432 user=bird')
It is possible to reconnect with previous database source name, too:
   bazaar.connectDB()
Parameters:
dsn - Database source name.

See Also: bazaar.core.Bazaar.closeDBConn

delete(self, obj)

Delete object from database.

Object's primary key value is set to None.
Parameters:
obj - Object to delete.

find(self, cls, query, param=None, field=0)

Find objects of given class in database.

The method can be used in two ways.

First, simple dictionary can be passed as query:
   # iterator is returned, so its next() method is used to get
   # the object
   apple = bazaar.find(Article, {'name': 'apple'}).next()
Dictionary can contain objects as values, i.e.:
   bazaar.find(OrderItem, {'article': art})
Second, it is possible to use full power of SQL language:
   # find orders and their articles if order amount is greater
   # than 50$

   # find orders with the query
   query = """
       select O.__key__ from "order" O
       left outer join order_item OI on O.__key__ = OI.order_fkey
       left outer join article A on OI.article_fkey = A.__key__
       group by O.__key__ having sum(A.price) > 50
   """

   for ord in  bzr.find(Order, query):
       print ord                     # show order
       for oi in ord.items:          # show order's articles
           print oi.article
Parameters:
cls - Application class.
query - SQL query or dictionary.
param - SQL query parameters.
field - SQL column number which describes found objects' primary key values.
Returns:
Iterator of found objects.

getObjects(self, cls)

Get list of application objects.

Only objects of specified class are returned.
Parameters:
cls - Application class.

See Also: bazaar.core.Bazaar.reloadObjects

init(self)

Initialize the Bazaar layer.

parseConfig(self, config)

Parse Bazaar configuration.
Parameters:
config - Bazaar configuration.

See Also: setConfig bazaar.config.Config bazaar.config.CPConfig

reloadObjects(self, cls, now=False)

Reload objects from database.
Parameters:
cls - Application class.
now - Reload objects immediately.

See Also: bazaar.core.Bazaar.getObjects

rollback(self)

Rollback database transactions.

setConfig(self, config)

Set Bazaar configuration.

See Also: parseConfig init bazaar.config.Config bazaar.config.CPConfig

update(self, obj)

Update object in database.
Parameters:
obj - Object to update.

Instance Variable Details

brokers

Dictionary of brokers. Brokers are mapped with its class application.

cls_list

List of application classes.

dbmod

Python DB API module.

dsn

Python DB API database source name.

motor

Database access object.

Generated by Epydoc 2.0 on Tue Mar 23 14:53:30 2004 http://epydoc.sf.net