Exemplo n.º 1
0
		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;
			}
		}
Exemplo n.º 2
0
        //[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();
                    pht.ExecuteBeforeStorageCommit();

                    if (pht.UsingLazyCommit)
                        txMode = CommitTransactionGrbit.None;

                    try
                    {
                        return pht.Commit(txMode);
                    }
                    finally
                    {
                        pht.ExecuteAfterStorageCommit();
                    }
                }
            }
            finally
            {
                if (lockTaken)
                    Monitor.Exit(transactionContext);
            }
        }
Exemplo n.º 3
0
        public IDisposable SetTransactionContext(EsentTransactionContext context)
        {
            dtcTransactionContext.Value = context;

            return new DisposableAction(() =>
            {
                dtcTransactionContext.Value = null;
            });
        }
Exemplo n.º 4
0
        //[DebuggerHidden, DebuggerNonUserCode, DebuggerStepThrough]
        private Action ExecuteBatch(Action<IStorageActionsAccessor> action, EsentTransactionContext transactionContext)
        {
            var txMode = configuration.TransactionMode == TransactionMode.Lazy
                ? CommitTransactionGrbit.LazyFlush
                : CommitTransactionGrbit.None;
            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);
            }
        }