<commit_before>from app.model.pgadapter import PgAdapter
from app.config import get_db_config


class Category():
    db = PgAdapter(get_db_config('develop'))
    MAX_ADDABLE_DATA = 10

    def __init__(self, id=None, name=''):
        self.__id = id
        self.__name = name
        self.__errors = {}

    @property
    def errors(self):
        return self.__errors

    def validate(self):
        # ToDo: decorator化
        isValid = True
        if not self.__name:
            self.__set_error('name', '商品カテゴリ名は必須です')
            isValid = False

        saved_rows = Category.db.fetch_rowcount('categories')
        if self.MAX_ADDABLE_DATA <= saved_rows:
            self.__set_error('maximum row', '商品カテゴリの上限に達しています')
            isValid = False
        return isValid

    def save(self):
        if not self.validate():
            return False
        saved = False
        try:
            Category.db.save('save_category', (self.__id, self.__name))
            saved = True if Category.db.affected_rows == 1 else False
            if saved:
                Category.db.commit()
            else:
                Category.db.rollback()
        except Exception as e:
            Category.db.rollback()
            print(e)
            raise e
        return saved

    def delete(self):
        if self.__id is None:
            return False
        deleted = False
        try:
            Category.db.remove('delete_category', (self.__id,))
            deleted = True if Category.db.affected_rows == 1 else False
            if deleted:
                Category.db.commit()
            else:
                Category.db.rollback()
        except Exception as e:
            Category.db.rollback()
            print(e)
            raise e
        return deleted

    @classmethod
    def find_all(cls):
        categories = []<commit_msg>#78 リファクタの影響を修正<commit_after>from app.model.pgadapter import PgAdapter
from app.config import get_db_config


class Category():
    db = PgAdapter(get_db_config('develop'))
    MAX_ADDABLE_DATA = 10

    def __init__(self, id=None, name=''):
        self.__id = id
        self.__name = name
        self.__errors = {}

    @property
    def errors(self):
        return self.__errors

    def validate(self):
        # ToDo: decorator化
        isValid = True
        if not self.__name:
            self.__set_error('name', '商品カテゴリ名は必須です')
            isValid = False

        saved_rows = Category.db.fetch_rowcount('categories')
        if self.MAX_ADDABLE_DATA <= saved_rows:
            self.__set_error('maximum row', '商品カテゴリの上限に達しています')
            isValid = False
        return isValid

    def save(self):
        if not self.validate():
            return False
        saved = False
        try:
            affected = Category.db.save('save_category', (self.__id, self.__name))
            saved = True if affected == 1 else False
            if saved:
                Category.db.commit()
            else:
                Category.db.rollback()
        except Exception as e:
            Category.db.rollback()
            print(e)
            raise e
        return saved

    def delete(self):
        if self.__id is None:
            return False
        deleted = False
        try:
            affected = Category.db.remove('delete_category', (self.__id,))
            deleted = True if affected == 1 else False
            if deleted:
                Category.db.commit()
            else:
                Category.db.rollback()
        except Exception as e:
            Category.db.rollback()
            print(e)
            raise e
        return deleted

    @classmethod
    def find_all(cls):
        categories = []
{'fraction_non_alphanumeric': 0.08945945945945946, 'fraction_numerical': 0.002702702702702703, 'mean_word_length': 1.6211048158640227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6775097', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1032, 'n_words': 257}