Hi folks,
In my current implementation, there are a core module and a models module.
Core module handles all the database stuff, start a session, issue sql
operation, then end a session. Models module invokes methods in core module
to access database, as showed below:
model.py
def get_site(site_id):
core.get_resource(Site, site_id)
core.py
def get_resource(model, pk_value):
# code to access database
To add context, I am going to implement like this:
model.py
def get_site(context, site_id):
policy_check(context)
core.get_resource(Site, site_id)
core.py
def get_resource(model, pk_value):
# code to access database
So there is no need to embed session into context.
One advantage of embedding session into context is that you can combine
more than one method calls in one session, like:
model.py
def complex_operation(context):
policy_check(context)
with context.session.begin():
core.operation1(context)
core.operation2(context)
But this approach moves session handling from core module to models module
and core module just provides some utility methods.
I'm not sure which one is better.
BR
Zhiyuan
__________________________________________________________________________
OpenStack Development Mailing List (not for usage questions)
Unsubscribe: [email protected]?subject:unsubscribe
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev