def setup(cls): """Setup the object persistance system. Perform initialization, which in this case means creating the database if it does not exist. """ assert (cls.connection_info is not None) conn = _server_utils.create_mysql_connection(autocommit=True, use_unicode=True, **cls.connection_info) _server_utils.exec_mysql_stmt(conn, "CREATE DATABASE %s" % (cls.database, ))
def teardown(cls): """Tear down the object persistance system. This should only be called if the persistance database should be removed from the persistance server since it will delete all object tables. """ assert (cls.connection_info is not None) conn = _server_utils.create_mysql_connection(autocommit=True, use_unicode=True, **cls.connection_info) _server_utils.exec_mysql_stmt( conn, "DROP DATABASE IF EXISTS %s" % (cls.database, ))
def setup(cls): """Setup the object persistance system. Perform initialization, which in this case means creating the database if it does not exist. """ assert (cls.connection_info is not None) conn = _server_utils.create_mysql_connection( autocommit=True, use_unicode=False, **cls.connection_info ) _server_utils.exec_mysql_stmt( conn, "CREATE DATABASE %s" % (cls.database, ) )
def teardown(cls): """Tear down the object persistance system. This should only be called if the persistance database should be removed from the persistance server since it will delete all object tables. """ assert (cls.connection_info is not None) conn = _server_utils.create_mysql_connection( autocommit=True, use_unicode=False, **cls.connection_info ) _server_utils.exec_mysql_stmt( conn, "DROP DATABASE IF EXISTS %s" % (cls.database, ) )
def _try_to_fix_connection(self): """Try to get a new connection if the current one is stale. """ for attempt in range(0, self.connection_attempts): try: if self.__cnx: _server_utils.reestablish_mysql_connection( self.__cnx, attempt=1, delay=0 ) else: self.__cnx = _server_utils.create_mysql_connection( autocommit=True, use_unicode=False, database=self.database, **self.connection_info ) return except _errors.DatabaseError as error: _LOGGER.debug("Error accessing backing store (%s). " "Attempt (%s).", error, attempt) time.sleep(self.connection_delay)
def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = _server_utils.create_mysql_connection( autocommit=True, use_unicode=True, database=self.database, **self.connection_info) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID).")
def __init__(self): """Constructor for MySQLPersister. """ self.__cnx = None self.__check_connection = True assert (self.connection_info is not None) try: self.__cnx = _server_utils.create_mysql_connection( autocommit=True, use_unicode=False, database=self.database, **self.connection_info ) except _errors.DatabaseError: pass if self.uuid is None and self.__cnx is not None: _LOGGER.warning( "Backing store does not support UUID (or not configured " "with UUID)." )
def _try_to_fix_connection(self): """Try to get a new connection if the current one is stale. """ for attempt in range(0, self.connection_attempts): try: if self.__cnx: _server_utils.reestablish_mysql_connection(self.__cnx, attempt=1, delay=0) else: self.__cnx = _server_utils.create_mysql_connection( autocommit=True, use_unicode=True, database=self.database, **self.connection_info) return except _errors.DatabaseError as error: _LOGGER.debug( "Error accessing backing store (%s). Attempt (%s).", error, attempt) time.sleep(self.connection_delay)