source: mauRepo/MolesManager/trunk/src/libs/migration/InfodbEPB.py @ 8323

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/InfodbEPB.py@8323
Revision 8323, 1.9 KB checked in by mnagni, 8 years ago (diff)

Complete - # 22434: CEDA Observation - keywords (following Gemini method)
 http://team.ceda.ac.uk/trac/ceda/ticket/22434
Removed the SA session from all but the EPBxx instances

Line 
1'''
2Created on 10 Jan 2012
3
4@author: mnagni
5'''
6from libs.epb import EPB
7from libs.migration.exception.exceptions import NoDBManager
8from sqlalchemy.sql.expression import text, bindparam
9from sqlalchemy.types import String
10
11
12class InfodbEPB(EPB):
13   
14    _infoDB = None
15   
16    @classmethod
17    def overrrideDBManager(self, dbManager):
18        """
19            Sets the infodbEPB libs.commons_db.DbManager
20        """
21        InfodbEPB._infoDB = dbManager
22
23    @classmethod
24    def getCedaInfoApp_dataentityByDE_ID(self, de_id, session = None):
25        """
26            Returns a dictionary representing the cedainfoapp_dataentity table in the cedainfo DB.
27            The dictionary has the following keys:
28               logical_path, category, name
29            @param de_id: the cedainfoapp_dataentity.dataentity_id to look for             
30        """
31        query_string = text("SELECT cedainfoapp_dataentity.logical_path AS logical_path, \
32            cedainfoapp_curationcategory.category AS category,\
33            cedainfoapp_person.name AS name \
34            FROM cedainfoapp_dataentity \
35                LEFT JOIN cedainfoapp_curationcategory \
36                    ON cedainfoapp_dataentity.curation_category_id=cedainfoapp_curationcategory.id \
37                LEFT JOIN cedainfoapp_person \
38                    ON cedainfoapp_dataentity.responsible_officer_id=cedainfoapp_person.id \
39            WHERE cedainfoapp_dataentity.dataentity_id=:i_id")
40        records = InfodbEPB._infoDB.engine.execute(query_string, i_id=de_id)
41        ret = records.fetchone()
42        records.close()
43        return ret
44
45
46    @classmethod
47    def getNewInfoConnection(self):
48        return InfodbEPB._getConnection()
49
50    @classmethod
51    def _getConnection(self, session = None):
52        if InfodbEPB._infoDB is None:
53            raise NoDBManager("InfodbEPB")
54        return EPB._getSession(InfodbEPB._infoDB, session)
Note: See TracBrowser for help on using the repository browser.