コード例 #1
0
 def get_db_engine(self, key: EnumDbEngineType):
     """
     Method for get db engine by key. If key is None or dont find engine return None
     :param key: for get db engine
     :return: db engine if found else return None
     """
     RFContext.get_db_engine(key)
コード例 #2
0
    def create_transaction(
            self,
            enum_transaction_type: EnumTransactionType = EnumTransactionType.
        PROPAGATED,
            params=None,
            db_engine_type: EnumDbEngineType = EnumDbEngineType.RF_MYSQL_POOL):
        """
        Method for create transaction
        :param enum_transaction_type:  type for transaction to create
        :param params
        :param db_engine_type engine for db
        :return: response for transaction create
        """
        from rfpyweb.context.rf_context import RFContext

        # set default transaction propagated
        enum_transaction_type = enum_transaction_type if not None else EnumTransactionType.PROPAGATED
        response = None
        if self.function_create_transaction is not None:
            response = self.function_create_transaction(
                enum_transaction_type,
                params=params,
                db_engine_type=db_engine_type)
        else:
            rf_mysql_engine = RFContext.get_db_engine(db_engine_type)

            if db_engine_type == EnumDbEngineType.RF_MYSQL_POOL:
                response = RFTransaction(enum_transaction_type,
                                         transaction_database=rf_mysql_engine.
                                         connection.get_connection())
            elif db_engine_type == EnumDbEngineType.RF_MYSQL:
                # No pool
                response = RFTransaction(
                    enum_transaction_type,
                    transaction_database=rf_mysql_engine.get_db())

        return response