Changeset 8326 for mauRepo


Ignore:
Timestamp:
06/06/12 11:39:29 (7 years ago)
Author:
mnagni
Message:

Other improvement on how SA alchemy session is managed (infoDB)

Location:
mauRepo/MolesManager/trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/MolesManager/trunk/src/MolesManager/molesSessionMiddleware.py

    r8325 r8326  
    1010    MOLES3_DB_SCRIPT, EVENTS_DB, INFO_DB_CONNECTION 
    1111from libs.commons_db import DbManager 
    12 from libs.migration.InfodbEPB import InfodbEPB 
     12from libs.migration.InfodbEPB import InfodbEPBFactory 
    1313from libs.migration.MigrationEPB import MigrationEPBFactory 
    1414 
     
    2121    #_migrationThread = MigrationThread(interval = MIGRATION_INTERVAL) 
    2222    _epbInitialized = False 
     23    _infodbEPBFactory = None     
    2324    _moles3EPBFactory = None 
    2425    _migrationEPBFactory = None 
     
    2627    def _doInitialization(self): 
    2728        infoDB = DbManager(INFO_DB_CONNECTION) 
    28         InfodbEPB.overrrideDBManager(infoDB) 
     29        MolesSessionMiddleware._infodbEPBFactory = InfodbEPBFactory(infoDB) 
     30        #InfodbEPB.overrrideDBManager(infoDB) 
    2931            
    3032        migrationDB = DbManager(MIGRATION_DB_CONNECTION, MIGRATION_DB_SCRIPT) 
  • mauRepo/MolesManager/trunk/src/libs/migration/InfodbEPB.py

    r8323 r8326  
    55''' 
    66from libs.epb import EPB 
    7 from libs.migration.exception.exceptions import NoDBManager 
    8 from sqlalchemy.sql.expression import text, bindparam 
    9 from sqlalchemy.types import String 
     7from sqlalchemy.sql.expression import text 
    108 
     9class InfodbEPBFactory(EPB): 
     10     
     11    def __init__(self, dbManager): 
     12        self._dbManager = dbManager 
     13 
     14    def _getSession(self): 
     15        if self._dbManager is not None: 
     16            return self._dbManager.createDbSession()                 
     17        return None 
     18         
     19    def createMigrationEPB(self): 
     20        return InfodbEPB(self._getSession()) 
    1121 
    1222class InfodbEPB(EPB): 
    1323     
    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 
     24    def __init__(self, session): 
     25        self._session = session             
    2226 
    23     @classmethod 
    24     def getCedaInfoApp_dataentityByDE_ID(self, de_id, session = None): 
     27    def close(self): 
     28        return self._session.close() 
     29 
     30    def getCedaInfoApp_dataentityByDE_ID(self, de_id): 
    2531        """ 
    2632            Returns a dictionary representing the cedainfoapp_dataentity table in the cedainfo DB. 
     
    3844                    ON cedainfoapp_dataentity.responsible_officer_id=cedainfoapp_person.id \ 
    3945            WHERE cedainfoapp_dataentity.dataentity_id=:i_id") 
    40         records = InfodbEPB._infoDB.engine.execute(query_string, i_id=de_id) 
     46        records = self._session.execute(query_string, params={'i_id':de_id}) 
    4147        ret = records.fetchone() 
    4248        records.close() 
    4349        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) 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/EPBRepo.py

    r8325 r8326  
    77    moles3EPB = None 
    88    migrationEPB = None 
     9    infodbEPB = None 
  • mauRepo/MolesManager/trunk/src/libs/migration/processor/deployment.py

    r8325 r8326  
    311311        dataentity_id = '%s__ATOM__%s' % (self._dataEntityMigration.doc_owner, self._dataEntityMigration.doc_name) 
    312312        dataentity_id = dataentity_id.replace('.atom', '')            
    313         infodb_de = InfodbEPB.getCedaInfoApp_dataentityByDE_ID(dataentity_id) 
     313        infodb_de = EPBRepo.infodbEPB.getCedaInfoApp_dataentityByDE_ID(dataentity_id) 
    314314        i_logical_path = '/dummy' 
    315315        if infodb_de is None: 
  • mauRepo/MolesManager/trunk/src/libs/migration/tests/migrationprocess.py

    r8325 r8326  
    66from unittest import TestCase 
    77from libs.commons_db import DbManager 
    8 from libs.migration.MigrationEPB import MigrationEPB, MigrationEPBFactory 
     8from libs.migration.MigrationEPB import MigrationEPBFactory 
    99from libs.migration.processor.loadResources import LoadResources 
    1010from libs.migration.db.classes import MigrationObject 
    1111from libs.migration.processor.commons import DO_BADC, DS_pUBLISHED, DS_PUBLISHED 
    12 from MolesManager.moles3epb import Moles3EPB, Moles3EPBFactory 
     12from MolesManager.moles3epb import Moles3EPBFactory 
    1313from libs.migration.processor.migrationProcess import MigrationProcess 
    1414from testconfig import MIGRATION_DB_CONNECTION,\ 
    1515    MIGRATION_DB_SCRIPT, MOLES3_DB_SCRIPT, MOLES3_DB_CONNECTION, INFO_DB_CONNECTION  
    16 from libs.migration.InfodbEPB import InfodbEPB 
     16from libs.migration.InfodbEPB import InfodbEPBFactory 
    1717from MolesManager.settings import EVENTS_DB 
    1818from libs.migration.client import EPBRepo 
     
    3434        #infoDB = DbManager(INFO_DB_CONNECTION, sql_echo=True) 
    3535        infoDB = DbManager(INFO_DB_CONNECTION)         
    36         InfodbEPB.overrrideDBManager(infoDB) 
     36        infoFactory = InfodbEPBFactory(infoDB) 
    3737         
    3838        moles3Factory = Moles3EPBFactory(molesDB) 
     
    4141        EPBRepo.moles3EPB = moles3Factory.createMoles3EPB()  
    4242        EPBRepo.migrationEPB = migrationFactory.createMigrationEPB() 
    43          
     43        EPBRepo.infodbEPB = infoFactory.createMigrationEPB() 
     44 
    4445        lr = LoadResources() 
    4546        ex = lr.process() 
     
    7172            print e 
    7273        #self._dropAllTables() 
    73          
     74 
     75    """         
    7476    def _dropAllTables(self): 
    7577        session = Moles3EPB.getNewMolesSession() 
     
    8183        session.commit() 
    8284        session.close()         
     85    """     
    8386         
    8487         
    85          
Note: See TracChangeset for help on using the changeset viewer.