text-document-search 1.6.3

Find and replace use cases for text-document
Documentation
// Generated by Qleany v1.4.8 from feature_use_case_uow.tera

use crate::use_cases::find_all_uc::{FindAllUnitOfWorkFactoryTrait, FindAllUnitOfWorkTrait};
use anyhow::{Ok, Result};
use common::database::QueryUnitOfWork;
use common::database::{db_context::DbContext, transactions::Transaction};
#[allow(unused_imports)]
use common::entities::{Block, Document, Frame, Root};
#[allow(unused_imports)]
use common::types;
#[allow(unused_imports)]
use common::types::EntityId;
use std::cell::RefCell;

// Unit of work for FindAll

pub struct FindAllUnitOfWork {
    context: DbContext,
    transaction: RefCell<Option<Transaction>>,
}

impl FindAllUnitOfWork {
    pub fn new(db_context: &DbContext) -> Self {
        FindAllUnitOfWork {
            context: db_context.clone(),
            transaction: RefCell::new(None),
        }
    }
}

impl QueryUnitOfWork for FindAllUnitOfWork {
    fn begin_transaction(&self) -> Result<()> {
        self.transaction
            .replace(Some(Transaction::begin_read_transaction(&self.context)?));
        Ok(())
    }

    fn end_transaction(&self) -> Result<()> {
        self.transaction.take().unwrap().end_read_transaction()?;
        Ok(())
    }

    fn store(&self) -> std::sync::Arc<common::database::Store> {
        self.context.get_store().clone()
    }
}

#[macros::uow_action(entity = "Root", action = "GetRO")]
#[macros::uow_action(entity = "Root", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Document", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Frame", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Block", action = "GetMultiRO")]
impl FindAllUnitOfWorkTrait for FindAllUnitOfWork {}

pub struct FindAllUnitOfWorkFactory {
    context: DbContext,
}

impl FindAllUnitOfWorkFactory {
    pub fn new(db_context: &DbContext) -> Self {
        FindAllUnitOfWorkFactory {
            context: db_context.clone(),
        }
    }
}

impl FindAllUnitOfWorkFactoryTrait for FindAllUnitOfWorkFactory {
    fn create(&self) -> Box<dyn FindAllUnitOfWorkTrait> {
        Box::new(FindAllUnitOfWork::new(&self.context))
    }
}