CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
o2o_db_manager.DbManager Class Reference
Inheritance diagram for o2o_db_manager.DbManager:

Public Member Functions

def __init__
 
def check_table
 
def connect
 
def get_url
 

Public Attributes

 authPath
 
 db_service
 
 engine
 
 schema
 
 session
 

Detailed Description

Definition at line 29 of file o2o_db_manager.py.

Constructor & Destructor Documentation

def o2o_db_manager.DbManager.__init__ (   self,
  db,
  authPath = None 
)

Definition at line 30 of file o2o_db_manager.py.

30 
31  def __init__(self, db, authPath=None):
32  self.authPath = authPath
33  if db == 'prod':
34  self.db_service = prod_db_service
35  elif db == 'dev':
36  self.db_service = dev_db_service
37  elif db == 'private':
38  self.db_service = None
39  else:
40  raise RuntimeError('Option db(=%s) is not in the supported database list: [prod, dev, private]' % db)
41 
42  logging.info('Connecting to %s database' % self.db_service[0] if self.db_service else private_db)
43 
44  self.schema = schema_dict[self.db_service[0]] if self.db_service else None

Member Function Documentation

def o2o_db_manager.DbManager.check_table (   self,
  table_def,
  table_class 
)

Definition at line 56 of file o2o_db_manager.py.

Referenced by o2o_db_cfgmap.DbManagerDAQ.update_hashmap().

56 
57  def check_table(self, table_def, table_class):
58  self.engine = sqlalchemy.create_engine(self.get_url())
59  if not self.engine.has_table(table_def.__tablename__, self.schema):
60  logging.info('Creating table %s on %s' % (table_def.__tablename__,
61  self.db_service[0] if self.db_service else private_db))
62  self.engine = sqlalchemy.create_engine(self.get_url(True))
63  table_class.__table__.create(bind=self.engine)
64  self.session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
def o2o_db_manager.DbManager.connect (   self,
  url = None 
)

Definition at line 65 of file o2o_db_manager.py.

References querying.connection.engine, o2o_db_manager.DbManager.engine, and conddblib.Connection.engine.

Referenced by o2o_db_cfgmap.DbManagerDAQ.update_hashmap().

65 
66  def connect(self, url=None):
67  engine = sqlalchemy.create_engine(url) if url else self.engine
68  session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=engine))
69  return session
70 
def o2o_db_manager.DbManager.get_url (   self,
  force_schema = False 
)

Definition at line 45 of file o2o_db_manager.py.

References o2o_db_manager.DbManager.authPath, o2o_db_manager.DbManager.db_service, o2o_db_manager.DbManager.schema, and querying.connection.schema.

45 
46  def get_url(self, force_schema=False):
47  if self.db_service == None:
48  url = private_db
49  else:
50  authEntry = self.db_service[1]
51  if force_schema and self.schema:
52  authEntry = '%s/%s' % (self.db_service[0], self.schema)
53  username, _, pwd = auth.get_credentials( authEntry, self.authPath)
54  url = sqlalchemy_tpl % (username, pwd, self.db_service[0])
55  return url

Member Data Documentation

o2o_db_manager.DbManager.authPath

Definition at line 31 of file o2o_db_manager.py.

Referenced by o2o_db_manager.DbManager.get_url().

o2o_db_manager.DbManager.db_service

Definition at line 33 of file o2o_db_manager.py.

Referenced by o2o_db_manager.DbManager.get_url().

o2o_db_manager.DbManager.engine

Definition at line 57 of file o2o_db_manager.py.

Referenced by o2o_db_manager.DbManager.connect().

o2o_db_manager.DbManager.schema

Definition at line 43 of file o2o_db_manager.py.

Referenced by o2o_db_manager.DbManager.get_url().

o2o_db_manager.DbManager.session

Definition at line 63 of file o2o_db_manager.py.