Changeset 8356 for mauRepo


Ignore:
Timestamp:
17/06/12 15:01:51 (7 years ago)
Author:
mnagni
Message:

Integrated a connection pool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mauRepo/HPFos/trunk/src/libs/commons_db.py

    r8355 r8356  
    3232''' 
    3333from sqlalchemy import MetaData, create_engine 
    34 from sqlalchemy.orm import sessionmaker, scoped_session 
     34from sqlalchemy.orm import sessionmaker 
    3535from sqlalchemy.sql.expression import text 
    3636class DbManagerCollection(object): 
     
    5252        Represents a database instance managed by an SQLAlchemy engine.         
    5353    """ 
    54     def __init__(self, connection, script = None, sql_echo=False, session_event_manager = None): 
     54    def __init__(self, connection, script = None, sql_echo=False, session_event_manager = None, ipool_size = 10): 
    5555        """ 
    5656          @param connection: the URL used to open a connection to the database 
     
    5858          @param sql_echo: sets the SQLalchemy create_engine.echo param. Default is False  
    5959          @param session_event_manager: a python method defining session events \ 
    60           (see http://docs.sqlalchemy.org/en/latest/orm/events.html?highlight=session%20events#sqlalchemy.orm.events.SessionEvents)      
     60          (see http://docs.sqlalchemy.org/en/latest/orm/events.html?highlight=session%20events#sqlalchemy.orm.events.SessionEvents) 
     61          @param ipool_size: sets the connections pool size (note that this is the maximum size not the number of the pre-allocated ones)                
    6162        """ 
    6263        self._connection = connection         
     
    6465        self.engine = None 
    6566        try: 
    66             self.engine = create_engine(self._connection, echo=sql_echo) 
     67            self.engine = create_engine(self._connection, pool_size = ipool_size, pool_recycle=3600, echo=sql_echo) 
    6768        except Exception as e: 
    6869            print e 
     
    7374            self._script(self.metadata) 
    7475            self.metadata.create_all(bind=self.engine) 
    75             #self._session = scoped_session(sessionmaker()) 
    7676        if self.engine: 
    7777            self.engine.connect() 
Note: See TracChangeset for help on using the changeset viewer.