Hi, Vega, Thanks for your response. I think we can include the session in the context.
Best Regards Chaoyi Huang ( Joe Huang ) From: Vega Cai [mailto:[email protected]] Sent: Friday, July 31, 2015 9:44 AM To: OpenStack Development Mailing List (not for usage questions) Subject: Re: [openstack-dev] [tricircle] DAL implementation Hi Joe, I think one independent job is finished in one session. The job is responsible to start a session, query or modify database then end the session. Like port creating job in neutron, it starts a session, queries network, adds port, allocates ip address, then ends the session at the end. BR Zhiyuan On 31 July 2015 at 09:05, joehuang <[email protected]<mailto:[email protected]>> wrote: Hi, Vega, Multiple DB access will be a use case for one session , especially for DB data insertion, multiple table will be involved. To embed the session in Context, it’s ok to start a session if the session is empty, but how to decide when to commit the data, end a session? Best Regards Chaoyi Huang ( Joe Huang ) From: Vega Cai [mailto:[email protected]<mailto:[email protected]>] Sent: Thursday, July 30, 2015 3:03 PM To: [email protected]<mailto:[email protected]> Subject: [openstack-dev] [tricircle] DAL implementation 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://[email protected]?subject:unsubscribe> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
__________________________________________________________________________ OpenStack Development Mailing List (not for usage questions) Unsubscribe: [email protected]?subject:unsubscribe http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
