示例#1
0
    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, ))
示例#2
0
    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, ))
示例#3
0
    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, )
        )
示例#4
0
    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, )
        )
示例#5
0
 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)
示例#6
0
    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).")
示例#7
0
    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)."
            )
示例#8
0
 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)