use crate::use_cases::export_latex_uc::{
ExportLatexUnitOfWorkFactoryTrait, ExportLatexUnitOfWorkTrait,
};
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, InlineElement, List, Root, Table, TableCell};
#[allow(unused_imports)]
use common::types;
#[allow(unused_imports)]
use common::types::EntityId;
use std::cell::RefCell;
pub struct ExportLatexUnitOfWork {
context: DbContext,
transaction: RefCell<Option<Transaction>>,
}
impl ExportLatexUnitOfWork {
pub fn new(db_context: &DbContext) -> Self {
ExportLatexUnitOfWork {
context: db_context.clone(),
transaction: RefCell::new(None),
}
}
}
impl QueryUnitOfWork for ExportLatexUnitOfWork {
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(())
}
}
#[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 = "GetRelationshipRO")]
#[macros::uow_action(entity = "Block", action = "GetMultiRO")]
#[macros::uow_action(entity = "Block", action = "GetRelationshipRO")]
#[macros::uow_action(entity = "InlineElement", action = "GetMultiRO")]
#[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 ExportLatexUnitOfWorkTrait for ExportLatexUnitOfWork {}
pub struct ExportLatexUnitOfWorkFactory {
context: DbContext,
}
impl ExportLatexUnitOfWorkFactory {
pub fn new(db_context: &DbContext) -> Self {
ExportLatexUnitOfWorkFactory {
context: db_context.clone(),
}
}
}
impl ExportLatexUnitOfWorkFactoryTrait for ExportLatexUnitOfWorkFactory {
fn create(&self) -> Box<dyn ExportLatexUnitOfWorkTrait> {
Box::new(ExportLatexUnitOfWork::new(&self.context))
}
}