use crate::use_cases::export_docx_uc::{
ExportDocxUnitOfWorkFactoryTrait, ExportDocxUnitOfWorkTrait,
};
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, Resource, Root, Table, TableCell};
#[allow(unused_imports)]
use common::types;
#[allow(unused_imports)]
use common::types::EntityId;
use parking_lot::Mutex;
pub struct ExportDocxUnitOfWork {
context: DbContext,
transaction: Mutex<Option<Transaction>>,
}
impl ExportDocxUnitOfWork {
pub fn new(db_context: &DbContext) -> Self {
ExportDocxUnitOfWork {
context: db_context.clone(),
transaction: Mutex::new(None),
}
}
}
impl QueryUnitOfWork for ExportDocxUnitOfWork {
fn begin_transaction(&self) -> Result<()> {
let mut transaction = self.transaction.lock();
*transaction = Some(Transaction::begin_read_transaction(&self.context)?);
Ok(())
}
fn end_transaction(&self) -> Result<()> {
let mut transaction = self.transaction.lock();
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", thread_safe = true)]
#[macros::uow_action(entity = "Root", action = "GetRelationshipRO", thread_safe = true)]
#[macros::uow_action(entity = "Document", action = "GetRO", thread_safe = true)]
#[macros::uow_action(entity = "Document", action = "GetRelationshipRO", thread_safe = true)]
#[macros::uow_action(entity = "Frame", action = "GetRO", thread_safe = true)]
#[macros::uow_action(entity = "Frame", action = "GetRelationshipRO", thread_safe = true)]
#[macros::uow_action(entity = "Block", action = "GetRO", thread_safe = true)]
#[macros::uow_action(entity = "Block", action = "GetMultiRO", thread_safe = true)]
#[macros::uow_action(entity = "Block", action = "GetRelationshipRO", thread_safe = true)]
#[macros::uow_action(entity = "List", action = "GetRO", thread_safe = true)]
#[macros::uow_action(entity = "Table", action = "GetRO", thread_safe = true)]
#[macros::uow_action(entity = "Table", action = "GetRelationshipRO", thread_safe = true)]
#[macros::uow_action(entity = "TableCell", action = "GetMultiRO", thread_safe = true)]
impl ExportDocxUnitOfWorkTrait for ExportDocxUnitOfWork {}
pub struct ExportDocxUnitOfWorkFactory {
context: DbContext,
}
impl ExportDocxUnitOfWorkFactory {
pub fn new(db_context: &DbContext) -> Self {
ExportDocxUnitOfWorkFactory {
context: db_context.clone(),
}
}
}
impl ExportDocxUnitOfWorkFactoryTrait for ExportDocxUnitOfWorkFactory {
fn create(&self) -> Box<dyn ExportDocxUnitOfWorkTrait> {
Box::new(ExportDocxUnitOfWork::new(&self.context))
}
}