public DocumentStorageActions( JET_INSTANCE instance, string database, TableColumnsCache tableColumnsCache, OrderedPartCollection <AbstractDocumentCodec> documentCodecs, IUuidGenerator uuidGenerator, IDocumentCacher cacher, EsentTransactionContext transactionContext, TransactionalStorage transactionalStorage) { this.tableColumnsCache = tableColumnsCache; this.documentCodecs = documentCodecs; this.uuidGenerator = uuidGenerator; this.cacher = cacher; this.transactionalStorage = transactionalStorage; this.transactionContext = transactionContext; try { if (transactionContext == null) { session = new Session(instance); transaction = new Transaction(session); sessionAndTransactionDisposer = () => { if (transaction != null) { transaction.Dispose(); } if (session != null) { session.Dispose(); } }; } else { session = transactionContext.Session; transaction = transactionContext.Transaction; var disposable = transactionContext.EnterSessionContext(); sessionAndTransactionDisposer = disposable.Dispose; } Api.JetOpenDatabase(session, database, null, out dbid, OpenDatabaseGrbit.None); } catch (Exception ex) { logger.WarnException("Error when trying to open a new DocumentStorageActions", ex); try { Dispose(); } catch (Exception e) { logger.WarnException("Error on dispose when the ctor threw an exception, resources may have leaked", e); } throw; } }
public IDisposable SetTransactionContext(EsentTransactionContext context) { dtcTransactionContext.Value = context; return(new DisposableAction(() => { dtcTransactionContext.Value = null; })); }
//[DebuggerHidden, DebuggerNonUserCode, DebuggerStepThrough] private Action ExecuteBatch(Action <IStorageActionsAccessor> action, EsentTransactionContext transactionContext) { var txMode = configuration.TransactionMode == TransactionMode.Lazy ? CommitTransactionGrbit.LazyFlush : CommitTransactionGrbit.None; bool lockTaken = false; if (transactionContext != null) { Monitor.Enter(transactionContext, ref lockTaken); } try { using (var pht = new DocumentStorageActions(instance, database, tableColumnsCache, DocumentCodecs, generator, documentCacher, transactionContext, this)) { var dtcSnapshot = inFlightTransactionalState != null? // might be not already initialized yet, during database creation inFlightTransactionalState.GetSnapshot() : EmptyInFlightStateSnapshot.Instance; var storageActionsAccessor = new StorageActionsAccessor(pht, dtcSnapshot); if (disableBatchNesting.Value == null) { current.Value = storageActionsAccessor; } action(storageActionsAccessor); storageActionsAccessor.SaveAllTasks(); pht.ExecuteBeforeStorageCommit(); if (pht.UsingLazyCommit) { txMode = CommitTransactionGrbit.None; } try { return(pht.Commit(txMode)); } finally { pht.ExecuteAfterStorageCommit(); } } } finally { if (lockTaken) { Monitor.Exit(transactionContext); } } }
//[DebuggerHidden, DebuggerNonUserCode, DebuggerStepThrough] private Action ExecuteBatch(Action <IStorageActionsAccessor> action, EsentTransactionContext transactionContext) { var txMode = configuration.TransactionMode == TransactionMode.Lazy ? CommitTransactionGrbit.LazyFlush : CommitTransactionGrbit.None; bool lockTaken = false; if (transactionContext != null) { Monitor.Enter(transactionContext, ref lockTaken); } try { using (var pht = new DocumentStorageActions(instance, database, tableColumnsCache, DocumentCodecs, generator, documentCacher, transactionContext, this)) { var storageActionsAccessor = new StorageActionsAccessor(pht); if (disableBatchNesting.Value == null) { current.Value = storageActionsAccessor; } action(storageActionsAccessor); storageActionsAccessor.SaveAllTasks(); if (pht.UsingLazyCommit) { txMode = CommitTransactionGrbit.None; } return(pht.Commit(txMode)); } } finally { if (lockTaken) { Monitor.Exit(transactionContext); } } }