[FIX] add index on field of task and task work see bug 771941
[odoo/odoo.git] / openerp / pooler.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 """ Functions kept for backward compatibility.
23
24     They are simple wrappers around a global RegistryManager methods.
25
26 """
27
28 from openerp.modules.registry import RegistryManager
29
30 _Registries = None
31
32
33 def ensure_registries():
34     global _Registries
35     if _Registries is None:
36         _Registries = RegistryManager()
37
38
39 def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False, pooljobs=True):
40     """Create and return a database connection and a newly initialized registry."""
41     ensure_registries()
42     bound_registry = _Registries.get(db_name, force_demo, status, update_module, pooljobs)
43     return bound_registry.db, bound_registry.registry
44
45
46 def delete_pool(db_name):
47     """Delete an existing registry."""
48     ensure_registries()
49     _Registries.delete(db_name)
50
51
52 def restart_pool(db_name, force_demo=False, status=None, update_module=False):
53     """Delete an existing registry and return a database connection and a newly initialized registry."""
54     ensure_registries()
55     bound_registry = _Registries.new(db_name, force_demo, status, update_module, True)
56     return bound_registry.db, bound_registry.registry
57
58
59 def get_db(db_name):
60     """Return a database connection. The corresponding registry is initialized."""
61     return get_db_and_pool(db_name)[0]
62
63
64 def get_pool(db_name, force_demo=False, status=None, update_module=False):
65     """Return a model registry."""
66     return get_db_and_pool(db_name, force_demo, status, update_module)[1]
67
68 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: