Conjunto de mudanças 5454 no repositório publico


Ignorar:
Timestamp:
30/10/2011 00:22:53 (9 anos atrás)
Autor:
fabianosantos
Mensagem:

Reescrito configuracao de conexao com o banco de dados para utilizar configuracao por site.

Arquivo:
1 editado

Legenda:

Não Modificado
Adicionado
Removido
  • il.spdo/trunk/il/spdo/saconfig.py

    r5453 r5454  
    1 from zope.component import provideUtility, queryAdapter
     1from z3c.saconfig import EngineFactory, GloballyScopedSession, SiteScopedSession
     2from zope.component import provideUtility
     3from z3c.saconfig.interfaces import IEngineFactory, IScopedSession
     4from il.spdo.history_meta import ZopeVersionedExtension
     5from collective.saconnect.interfaces import ISQLAlchemyConnectionStrings
    26from zope.app.component.hooks import getSite
    37from zope.component.interfaces import ComponentLookupError
    4 from z3c.saconfig.interfaces import IScopedSession, IEngineFactory
    5 from z3c.saconfig import GloballyScopedSession, EngineFactory
    6 from collective.saconnect.interfaces import ISQLAlchemyConnectionStrings
    78from il.spdo.config import DEFAULT_DSN
    8 from il.spdo.history_meta import ZopeVersionedExtension
    9 
    10 SessionUtility = GloballyScopedSession(u'spdo_engine', extension=ZopeVersionedExtension)
    11 provideUtility(SessionUtility, provides=IScopedSession, name=u'spdo_session')
    129
    1310class SPDOEngineFactory(EngineFactory):
    1411
    1512    def configuration(self):
    16         #TODO:fazer logging da conexao usada.
    1713        try:
    1814            saconnect = ISQLAlchemyConnectionStrings(getSite())
    1915            dsn = saconnect['spdo']
    20             print 'SAConnect engine config'
    2116        except (ComponentLookupError, KeyError), e:
    22             print 'Fallback engine config: ' + str(e)
    23             dsn = DEFAULT_DSN #fallback to default DSN
    24 
     17            dsn = DEFAULT_DSN
    2518        return (dsn,),{}
    2619
    27 #registra um engine global de fallback
    28 SPDOGlobalEngine = EngineFactory(DEFAULT_DSN)
    29 provideUtility(SPDOGlobalEngine, provides=IEngineFactory, name=u'spdo_engine')
     20SPDOEngineGlobalUtility = EngineFactory(DEFAULT_DSN)
     21provideUtility(SPDOEngineGlobalUtility, provides=IEngineFactory, name=u'spdo_engine')
    3022
     23## GloballyScopedSession - um banco de dados por instancia
     24#SPDOGloballyScopedSession = GloballyScopedSession(u'spdo_engine', extension=ZopeVersionedExtension)
     25#provideUtility(SPDOGloballyScopedSession, provides=IScopedSession, name=u'spdo_session')
     26
     27# SiteScopedSession - um banco de dados por site
     28class SPDOSiteScopedSession(SiteScopedSession):
     29    def siteScopeFunc(self):
     30        return getSite().id
     31provideUtility(SPDOSiteScopedSession(u'spdo_engine', extension=ZopeVersionedExtension), provides=IScopedSession, name=u'spdo_session')
     32
Note: Veja TracChangeset para ajuda no uso do visualizador de conjunto de mudanças.
 

The contents and data of this website are published under license:
Creative Commons 4.0 Brasil - Atribuir Fonte - Compartilhar Igual.