text-document-io 1.8.0

Import/export for text-document: plain text, Markdown, HTML, LaTeX, DOCX
Documentation
// Generated by Qleany v1.4.8 from feature_use_case_uow.tera

use crate::use_cases::export_djot_uc::{
    ExportDjotUnitOfWorkFactoryTrait, ExportDjotUnitOfWorkTrait,
};
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, List, Root, Table, TableCell};
#[allow(unused_imports)]
use common::types;
#[allow(unused_imports)]
use common::types::EntityId;
use std::cell::RefCell;

// Unit of work for ExportDjot

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

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

impl QueryUnitOfWork for ExportDjotUnitOfWork {
    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 = "GetRO")]
#[macros::uow_action(entity = "Document", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Frame", action = "GetRO")]
#[macros::uow_action(entity = "Frame", action = "GetMultiRO")]
#[macros::uow_action(entity = "Frame", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "Block", action = "GetRO")]
#[macros::uow_action(entity = "Block", action = "GetMultiRO")]
#[macros::uow_action(entity = "Block", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "List", action = "GetRO")]
#[macros::uow_action(entity = "Table", action = "GetRO")]
#[macros::uow_action(entity = "Table", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "TableCell", action = "GetMultiRO")]
impl ExportDjotUnitOfWorkTrait for ExportDjotUnitOfWork {}

pub struct ExportDjotUnitOfWorkFactory {
    context: DbContext,
}

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

impl ExportDjotUnitOfWorkFactoryTrait for ExportDjotUnitOfWorkFactory {
    fn create(&self) -> Box<dyn ExportDjotUnitOfWorkTrait> {
        Box::new(ExportDjotUnitOfWork::new(&self.context))
    }
}