use crate::use_cases::export_odt_uc::{ExportOdtUnitOfWorkFactoryTrait, ExportOdtUnitOfWorkTrait};
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 ExportOdtUnitOfWork {
context: DbContext,
transaction: Mutex<Option<Transaction>>,
}
impl ExportOdtUnitOfWork {
pub fn new(db_context: &DbContext) -> Self {
ExportOdtUnitOfWork {
context: db_context.clone(),
transaction: Mutex::new(None),
}
}
}
impl QueryUnitOfWork for ExportOdtUnitOfWork {
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 ExportOdtUnitOfWorkTrait for ExportOdtUnitOfWork {}
pub struct ExportOdtUnitOfWorkFactory {
context: DbContext,
}
impl ExportOdtUnitOfWorkFactory {
pub fn new(db_context: &DbContext) -> Self {
ExportOdtUnitOfWorkFactory {
context: db_context.clone(),
}
}
}
impl ExportOdtUnitOfWorkFactoryTrait for ExportOdtUnitOfWorkFactory {
fn create(&self) -> Box<dyn ExportOdtUnitOfWorkTrait> {
Box::new(ExportOdtUnitOfWork::new(&self.context))
}
}