CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
conddblib.Connection Class Reference
Inheritance diagram for conddblib.Connection:

Public Member Functions

def __init__ (self, url)
 
def get_dbtype (self, theType)
 
def init (self, drop=False)
 
def is_frontier (self)
 
def is_official (self)
 
def is_oracle (self)
 
def is_read_only (self)
 
def is_sqlite (self)
 
def is_valid (self)
 
def metadata (self)
 
def session (self)
 

Public Attributes

 engine
 

Private Attributes

 _backendName
 
 _is_frontier
 
 _is_official
 
 _is_oracle
 
 _is_read_only
 
 _is_sqlite
 
 _is_valid
 
 _schemaName
 
 _session
 
 _url
 

Detailed Description

Definition at line 321 of file conddblib.py.

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 323 of file conddblib.py.

323  def __init__(self, url):
324  # Workaround to avoid creating files if not present.
325  # Python's sqlite3 module does not use sqlite3_open_v2(),
326  # and therefore we cannot disable SQLITE_OPEN_CREATE.
327  # Only in the case of creating a new database we skip the check.
328  if url.drivername == 'sqlite':
329 
330  self.engine = sqlalchemy.create_engine(url)
331 
332  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
333  supports_foreign_keys = enabled_foreign_keys is not None
334  if not supports_foreign_keys:
335  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
336  elif not enabled_foreign_keys:
337  self.engine.execute('pragma foreign_keys = on')
338 
339  else:
340  self.engine = sqlalchemy.create_engine(url)
341 
342  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
343 
344  self._is_frontier = url.drivername == 'oracle+frontier'
345  self._is_oracle = url.drivername == 'oracle'
346  self._is_sqlite = url.drivername == 'sqlite'
347 
348  self._is_read_only = self._is_frontier or url.host in {
349  'cms_orcon_adg',
350  'cmsarc_lb',
351  }
352 
353  self._is_official = self._is_frontier or url.host in {
354  'cms_orcon_adg',
355  'cmsarc_lb',
356  'cms_orcoff_int',
357  'cms_orcoff_prep',
358  'cms_orcon_prod',
359  'cmsintr_lb',
360  }
361  self._url = url
362  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
363  self._schemaName = ( None if self._is_sqlite else schema_name )
364  logging.debug(' ... using db "%s", schema "%s"' % (url, self._schemaName) )
365  logging.debug('Loading db types...')
366  self.get_dbtype(Tag).__name__
367  self.get_dbtype(Payload)
368  self.get_dbtype(IOV)
369  self.get_dbtype(TagLog)
370  self.get_dbtype(GlobalTag)
371  self.get_dbtype(GlobalTagMap)
372  self.get_dbtype(RunInfo)
373  self._is_valid = self.is_valid()
374 
def is_valid(self)
Definition: conddblib.py:413
def __init__(self, url)
Definition: conddblib.py:323
def get_dbtype(self, theType)
Definition: conddblib.py:375
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:183

Member Function Documentation

def conddblib.Connection.get_dbtype (   self,
  theType 
)

Definition at line 375 of file conddblib.py.

References conddblib.Connection._backendName, conddblib.Connection._schemaName, relativeConstraints.keys, and conddblib.make_dbtype().

Referenced by conddblib.Connection.init(), conddblib.Connection.is_valid(), and conddblib.Connection.session().

375  def get_dbtype(self,theType):
376  basename = theType.__name__
377  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
378  return make_dbtype( self._backendName, self._schemaName, theType )
379  else:
380  return db_models[self._backendName][basename]
381 
def make_dbtype(backendName, schemaName, baseType)
Definition: conddblib.py:215
def get_dbtype(self, theType)
Definition: conddblib.py:375
def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 425 of file conddblib.py.

References conddblib.Connection._is_valid, querying.connection.engine, conddblib.Connection.engine, and conddblib.Connection.get_dbtype().

425  def init(self, drop=False):
426  '''Initializes a database.
427  '''
428  logging.info('Initializing database...')
429  if drop:
430  logging.debug('Dropping tables...')
431  self.metadata.drop_all(self.engine)
432  self._is_valid = False
433  else:
434  if not self._is_valid:
435  logging.debug('Creating tables...')
436  self.get_dbtype(Tag).__table__.create(bind = self.engine)
437  self.get_dbtype(Payload).__table__.create(bind = self.engine)
438  self.get_dbtype(IOV).__table__.create(bind = self.engine)
439  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
440  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
441  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
442  self._is_valid = True
443 
def init(self, drop=False)
Definition: conddblib.py:425
def get_dbtype(self, theType)
Definition: conddblib.py:375
def conddblib.Connection.is_frontier (   self)

Definition at line 394 of file conddblib.py.

References conddblib.Connection._is_frontier.

394  def is_frontier(self):
395  return self._is_frontier
396 
def is_frontier(self)
Definition: conddblib.py:394
def conddblib.Connection.is_official (   self)

Definition at line 410 of file conddblib.py.

References conddblib.Connection._is_official.

410  def is_official(self):
411  return self._is_official
412 
def is_official(self)
Definition: conddblib.py:410
def conddblib.Connection.is_oracle (   self)

Definition at line 398 of file conddblib.py.

References conddblib.Connection._is_oracle.

398  def is_oracle(self):
399  return self._is_oracle
400 
def is_oracle(self)
Definition: conddblib.py:398
def conddblib.Connection.is_read_only (   self)

Definition at line 406 of file conddblib.py.

References conddblib.Connection._is_read_only.

406  def is_read_only(self):
407  return self._is_read_only
408 
def is_read_only(self)
Definition: conddblib.py:406
def conddblib.Connection.is_sqlite (   self)

Definition at line 402 of file conddblib.py.

References conddblib.Connection._is_sqlite.

402  def is_sqlite(self):
403  return self._is_sqlite
404 
def is_sqlite(self)
Definition: conddblib.py:402
def conddblib.Connection.is_valid (   self)
Tests whether the current DB looks like a valid CMS Conditions one.

Definition at line 413 of file conddblib.py.

References Vispa.Plugins.EdmBrowser.EdmDataAccessor.all(), conddblib.Connection.get_dbtype(), and conddblib.getSchema().

413  def is_valid(self):
414  '''Tests whether the current DB looks like a valid CMS Conditions one.
415  '''
416  engine_connection = self.engine.connect()
417  # temporarely avoid the check on the GT tables - there are releases in use where C++ does not create these tables.
418  _Tag = self.get_dbtype(Tag)
419  _IOV = self.get_dbtype(IOV)
420  _Payload = self.get_dbtype(Payload)
421  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__,getSchema(table)) for table in [_Tag, _IOV, _Payload]])
422  engine_connection.close()
423  return ret
424 
def is_valid(self)
Definition: conddblib.py:413
def getSchema(tp)
Definition: conddblib.py:249
def get_dbtype(self, theType)
Definition: conddblib.py:375
def conddblib.Connection.metadata (   self)

Definition at line 390 of file conddblib.py.

390  def metadata(self):
391  return _Base.metadata
392 
def metadata(self)
Definition: conddblib.py:390
def conddblib.Connection.session (   self)

Definition at line 382 of file conddblib.py.

References conddblib.Connection._is_sqlite, conddblib.Connection._session, url_query.url_query._url, conddblib.Connection._url, and conddblib.Connection.get_dbtype().

382  def session(self):
383  s = self._session()
384  s.get_dbtype = self.get_dbtype
385  s._is_sqlite = self._is_sqlite
386  s._url = self._url
387  return s
388 
def get_dbtype(self, theType)
Definition: conddblib.py:375

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 362 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 344 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 353 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 345 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 348 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 346 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite(), and conddblib.Connection.session().

conddblib.Connection._is_valid
private

Definition at line 373 of file conddblib.py.

Referenced by conddblib.Connection.init().

conddblib.Connection._schemaName
private

Definition at line 363 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 342 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection._url
private

Definition at line 361 of file conddblib.py.

Referenced by cmstc.TagCollector._open(), and conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 330 of file conddblib.py.

Referenced by o2o_db_manager.DbManager.connect(), and conddblib.Connection.init().