def call_direct_multiple(self, sp_name, params, db_type='R'):
     """
     :description: This function facilitates to call the sp directly
                   Function requires sp_name as string and params as list
                   It does not provide the transaction
                   THis should be used only for multiple result set
     :param sp_name: Procedure name to call
     :param params: list of parameters to call the sp
     :param db_type: Type of database (Read or write)
     :return: List of dictionary (Whatever coming from the database directly)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, sp_name, params)
         LoggingHelper().log_debug(self.__class__, sp_name, params)
     try:
         self.get_cursor(db_type).callproc(sp_name, params)
         self.data_as_dict_multiple_rs()
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", self.data)
     return self.data
示例#2
0
 def call_direct_with_transaction(self, sp_name, params, db_type='W'):
     """
     :description: This function facilitates to call the sp directly  (For add/update/delete)
                   Function requires sp_name as string and params as list
                   It does not provide the transaction and it does not closes the cursor
                   Returns the data object to the data layer
     :param sp_name: Procedure name to call
     :param params: list of parameters to call the sp
     :param db_type: Type of database (Read or write)
     :return: List of dictionary (Whatever comes from the database directly)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, sp_name, params)
     try:
         # transaction.set_autocommit(autocommit=False)
         self.get_cursor(db_type).callproc(sp_name, params)
         self.data_as_dict_transactional()
         # transaction.commit()
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     ex.error_object)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", self.data)
     return self.data
示例#3
0
    def data_as_dict_transactional(self):
        """
        :description: This function should be user for all the transactional procedures i.e add/update/delete
                      This will catch the errors raised by the procedures
                      If there are any errors then it will raise the exception with the error message given                        by the procedure
        :return: data as list
        """
        data = self.cursor.fetchall()
        if len(data) > 0:
            column_names_list = [x[0] for x in self.cursor.description]
            self.data = [dict(zip(column_names_list, row)) for row in data]
        self.cursor.nextset()

        if len(data) > 0:
            dict_ = self.data[0]

            if dict_.get(AppConstants.DB_SUCCESS_KEY) == 1:
                return self.data
            else:
                raise DatabaseException(dict_.get("DB_RESPONSE_CODE"),
                                        dict_.get("DB_RESPONSE_MESSAGE"),
                                        self.data)
        else:
            raise DatabaseException(ErrorCodes.DATABASE_ERROR,
                                    "Did not receive status from database",
                                    self.data)
示例#4
0
 def execute_raw_sql_multiple(self, sql_query):
     try:
         self.get_cursor(db_type="W").excecute(sql_query)
         self.data_as_dict_multiple_rs()
     except Exception as ex:
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     return self.data
示例#5
0
 def call_direct_multiple(self, sp_name, params, db_type='R'):
     try:
         self.get_cursor(db_type).callproc(sp_name, params)
         self.data_as_dict_multiple_rs()
     except Exception as ex:
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
     return self.data
示例#6
0
 def get_data_list_object_paginated(self, params):
     try:
         self.pre_get_data_list_object_paginated(params)
         self.get_cursor(db_type="R").callproc(self.sp_name,
                                               self.params_list)
         list_cursor_object = self.data_as_cursor_list_multiple_rs()
         return self.post_get_data_list_object_paginated(list_cursor_object)
     except Exception as ex:
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
示例#7
0
 def delete_data(self, object):
     try:
         self.pre_delete(object)
         self.get_cursor(db_type="W").callproc(self.sp_name,
                                               self.params_list)
         returned_data = self.data_as_dict_transactional()
         return self.post_delete(object, returned_data[0])
     except Exception as ex:
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     ex.error_object)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
示例#8
0
 def add_data(self, object):
     """
     :description: To add the data into the system using the object
     :param object: Actual Object (Model)
     :return: Actual Added object (Model)
     """
     try:
         self.pre_add(object)
         self.get_cursor(db_type="W").callproc(self.sp_name,
                                               self.params_list)
         returned_dict = self.data_as_dict_transactional()
         return self.post_add(object, returned_dict[0])
     except Exception as ex:
         if isinstance(ex, DatabaseException) or isinstance(
                 ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message,
                                     ex.error_object)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
 def execute_raw_sql_multiple(self, sql_query):
     """
     :description: This executes the raw sql and returns the data object to the business layer
                   This should be used only for multiple result set
     :param sql_query: raw sql query
     :return: list of dictionary (Whatever coming from the database as is)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", sql_query)
     try:
         self.get_cursor(db_type="W").excecute(sql_query)
         self.data_as_dict_multiple_rs()
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", self.data)
     return self.data
 def get_data_list_object_any_paginated(self, sp_name, params: ParamsObject):
     """
     :description: This method allows user to get the data list object for any procedure which always                            returns the model object with pagination
     :param sp_name: Procedure name to call
     :param params: list of parameters
     :return: List of model object
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", params)
     try:
         self.get_cursor(db_type="R").callproc(sp_name, params.get_params_list())
         list_cursor_object = self.data_as_cursor_list_multiple_rs()
         return self.post_get_data_list_object_paginated(list_cursor_object)
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
         if base.DEBUG_ENABLED:
             LoggingHelper().log_debug(self.__class__, "", self.data)
 def get_data_list_object_paginated(self, params):
     """
     :description: To get the list of data from the system for any context for the transactional object with pagination
     :param object: ParamsObject
     :return: List of Actual object (Model)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", params)
     try:
         self.pre_get_data_list_object_paginated(params)
         self.get_cursor(db_type="R").callproc(self.sp_name, self.params_list)
         list_cursor_object = self.data_as_cursor_list_multiple_rs()
         return self.post_get_data_list_object_paginated(list_cursor_object)
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
         if base.DEBUG_ENABLED:
             LoggingHelper().log_debug(self.__class__, "", self.data)
 def get_data(self, params):
     """
     :description: To get the data from the system using id
     :param params: Actual Object (Model)
     :return: Actual object (Model)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", params)
     try:
         self.pre_get(params)
         self.get_cursor(db_type="R").callproc(self.sp_name, self.params_list)
         cursor_object = self.get_data_from_cursor()
         return self.post_get(cursor_object)
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, self.data)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
         if base.DEBUG_ENABLED:
             LoggingHelper().log_debug(self.__class__, "", self.data)
 def delete_data(self, object):
     """
     :description: To delete the data from the system using the object
     :param object: Actual Object (Model)
     :return: Actual object (Model)
     """
     if base.DEBUG_ENABLED:
         LoggingHelper().log_debug(self.__class__, "", object)
     try:
         self.pre_delete(object)
         self.get_cursor(db_type="W").callproc(self.sp_name, self.params_list)
         returned_data = self.data_as_dict_transactional()
         return self.post_delete(object, returned_data[0])
     except Exception as ex:
         if base.DEBUG_ENABLED:
             LoggingHelper().log_error(self.__class__, "", str(ex))
         if isinstance(ex, DatabaseException) or isinstance(ex, KaroException):
             raise DatabaseException(self.db_error_code, ex.error_message, ex.error_object)
         else:
             raise DatabaseException(self.db_error_code, str(ex), self.data)
     finally:
         self.close_cursor()
         if base.DEBUG_ENABLED:
             LoggingHelper().log_debug(self.__class__, "", self.data)