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
 public void JetSesidThrowsExceptionWhenSessionIsDisposed()
 {
     var session = new Session(this.instance);
     session.Dispose();
     JET_SESID x = session.JetSesid;
 }
Exemplo n.º 3
0
 public void EndThrowsExceptionWhenSessionIsDisposed()
 {
     var session = new Session(this.instance);
     session.Dispose();
     session.End();
 }
Exemplo n.º 4
0
        private void OpenCursor(string jetDatabase, Instance jetInstance,
            out Session jetSession,
            out JET_DBID chainStateDbId,
            out JET_TABLEID globalsTableId,
                out JET_COLUMNID chainTipColumnId,
                out JET_COLUMNID unspentTxCountColumnId,
                out JET_COLUMNID unspentOutputCountColumnId,
                out JET_COLUMNID totalTxCountColumnId,
                out JET_COLUMNID totalInputCountColumnId,
                out JET_COLUMNID totalOutputCountColumnId,
            out JET_TABLEID flushTableId,
                out JET_COLUMNID flushColumnId,
            out JET_TABLEID headersTableId,
                out JET_COLUMNID headerBlockHashColumnId,
                out JET_COLUMNID headerBytesColumnId,
            out JET_TABLEID unspentTxTableId,
                out JET_COLUMNID txHashColumnId,
                out JET_COLUMNID blockIndexColumnId,
                out JET_COLUMNID txIndexColumnId,
                out JET_COLUMNID txVersionColumnId,
                out JET_COLUMNID isCoinbaseColumnId,
                out JET_COLUMNID outputStatesColumnId,
            out JET_TABLEID unspentTxOutputTableId,
                out JET_COLUMNID txOutputKeyColumnId,
                out JET_COLUMNID txOutputBytesColumnId,
            out JET_TABLEID spentTxTableId,
                out JET_COLUMNID spentSpentBlockIndexColumnId,
                out JET_COLUMNID spentDataColumnId,
            out JET_TABLEID unmintedTxTableId,
                out JET_COLUMNID unmintedBlockHashColumnId,
                out JET_COLUMNID unmintedDataColumnId)
        {
            var success = false;
            jetSession = new Session(jetInstance);
            try
            {
                Api.JetOpenDatabase(jetSession, jetDatabase, "", out chainStateDbId, OpenDatabaseGrbit.None);

                Api.JetOpenTable(jetSession, chainStateDbId, "Globals", null, 0, OpenTableGrbit.None, out globalsTableId);
                chainTipColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "ChainTip");
                unspentTxCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "UnspentTxCount");
                unspentOutputCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "UnspentOutputCount");
                totalTxCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "TotalTxCount");
                totalInputCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "TotalInputCount");
                totalOutputCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "TotalOutputCount");

                if (!Api.TryMoveFirst(jetSession, globalsTableId))
                    throw new InvalidOperationException();

                Api.JetOpenTable(jetSession, chainStateDbId, "Flush", null, 0, OpenTableGrbit.None, out flushTableId);
                flushColumnId = Api.GetTableColumnid(jetSession, flushTableId, "Flush");

                if (!Api.TryMoveFirst(jetSession, flushTableId))
                    throw new InvalidOperationException();

                Api.JetOpenTable(jetSession, chainStateDbId, "Headers", null, 0, OpenTableGrbit.None, out headersTableId);
                headerBlockHashColumnId = Api.GetTableColumnid(jetSession, headersTableId, "BlockHash");
                headerBytesColumnId = Api.GetTableColumnid(jetSession, headersTableId, "HeaderBytes");

                Api.JetOpenTable(jetSession, chainStateDbId, "UnspentTx", null, 0, OpenTableGrbit.None, out unspentTxTableId);
                txHashColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "TxHash");
                blockIndexColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "BlockIndex");
                txIndexColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "TxIndex");
                txVersionColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "TxVersion");
                isCoinbaseColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "IsCoinbase");
                outputStatesColumnId = Api.GetTableColumnid(jetSession, unspentTxTableId, "OutputStates");

                Api.JetOpenTable(jetSession, chainStateDbId, "UnspentTxOutput", null, 0, OpenTableGrbit.None, out unspentTxOutputTableId);
                txOutputKeyColumnId = Api.GetTableColumnid(jetSession, unspentTxOutputTableId, "TxOutputKey");
                txOutputBytesColumnId = Api.GetTableColumnid(jetSession, unspentTxOutputTableId, "TxOutputBytes");

                Api.JetOpenTable(jetSession, chainStateDbId, "SpentTx", null, 0, OpenTableGrbit.None, out spentTxTableId);
                spentSpentBlockIndexColumnId = Api.GetTableColumnid(jetSession, spentTxTableId, "SpentBlockIndex");
                spentDataColumnId = Api.GetTableColumnid(jetSession, spentTxTableId, "SpentData");

                Api.JetOpenTable(jetSession, chainStateDbId, "UnmintedTx", null, 0, OpenTableGrbit.None, out unmintedTxTableId);
                unmintedBlockHashColumnId = Api.GetTableColumnid(jetSession, unmintedTxTableId, "BlockHash");
                unmintedDataColumnId = Api.GetTableColumnid(jetSession, unmintedTxTableId, "UnmintedData");

                success = true;
            }
            finally
            {
                if (!success)
                    jetSession.Dispose();
            }
        }
Exemplo n.º 5
0
        private void OpenCursor(string jetDatabase, Instance jetInstance, bool readOnly,
            out Session jetSession,
            out JET_DBID blockDbId,
            out JET_TABLEID globalsTableId,
            out JET_COLUMNID flushColumnId,
            out JET_TABLEID blockHeadersTableId,
            out JET_COLUMNID blockHeaderHashColumnId,
            out JET_COLUMNID blockHeaderPreviousHashColumnId,
            out JET_COLUMNID blockHeaderHeightColumnId,
            out JET_COLUMNID blockHeaderTotalWorkColumnId,
            out JET_COLUMNID blockHeaderValidColumnId,
            out JET_COLUMNID blockHeaderBytesColumnId)
        {
            jetSession = new Session(jetInstance);
            var success = false;
            try
            {
                Api.JetOpenDatabase(jetSession, jetDatabase, "", out blockDbId, readOnly ? OpenDatabaseGrbit.ReadOnly : OpenDatabaseGrbit.None);

                Api.JetOpenTable(jetSession, blockDbId, "Globals", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out globalsTableId);
                flushColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "Flush");

                if (!Api.TryMoveFirst(jetSession, globalsTableId))
                    throw new InvalidOperationException();

                Api.JetOpenTable(jetSession, blockDbId, "BlockHeaders", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blockHeadersTableId);
                blockHeaderHashColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "BlockHash");
                blockHeaderPreviousHashColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "PreviousBlockHash");
                blockHeaderHeightColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "Height");
                blockHeaderTotalWorkColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "TotalWork");
                blockHeaderValidColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "Valid");
                blockHeaderBytesColumnId = Api.GetTableColumnid(jetSession, blockHeadersTableId, "BlockHeaderBytes");

                success = true;
            }
            finally
            {
                if (!success)
                    jetSession.Dispose();
            }
        }
Exemplo n.º 6
0
        private void OpenCursor(string jetDatabase, Instance jetInstance, bool readOnly,
            out Session jetSession,
            out JET_DBID blockDbId,
            out JET_TABLEID globalsTableId,
            out JET_COLUMNID blockCountColumnId,
            out JET_COLUMNID flushColumnId,
            out JET_TABLEID blockIndexTableId,
            out JET_COLUMNID blockIndexBlockHashColumnId,
            out JET_COLUMNID blockIndexBlockIndexColumnId,
            out JET_TABLEID blocksTableId,
            out JET_COLUMNID blockIndexColumnId,
            out JET_COLUMNID txIndexColumnId,
            out JET_COLUMNID blockDepthColumnId,
            out JET_COLUMNID blockTxHashColumnId,
            out JET_COLUMNID blockTxBytesColumnId)
        {
            jetSession = new Session(jetInstance);
            var success = false;
            try
            {
                Api.JetOpenDatabase(jetSession, jetDatabase, "", out blockDbId, readOnly ? OpenDatabaseGrbit.ReadOnly : OpenDatabaseGrbit.None);

                Api.JetOpenTable(jetSession, blockDbId, "Globals", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out globalsTableId);
                blockCountColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "BlockCount");
                flushColumnId = Api.GetTableColumnid(jetSession, globalsTableId, "Flush");

                if (!Api.TryMoveFirst(jetSession, globalsTableId))
                    throw new InvalidOperationException();

                Api.JetOpenTable(jetSession, blockDbId, "BlockIndex", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blockIndexTableId);
                blockIndexBlockHashColumnId = Api.GetTableColumnid(jetSession, blockIndexTableId, "BlockHash");
                blockIndexBlockIndexColumnId = Api.GetTableColumnid(jetSession, blockIndexTableId, "BlockIndex");

                Api.JetOpenTable(jetSession, blockDbId, "Blocks", null, 0, readOnly ? OpenTableGrbit.ReadOnly : OpenTableGrbit.None, out blocksTableId);
                blockIndexColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "BlockIndex");
                txIndexColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "TxIndex");
                blockDepthColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "Depth");
                blockTxHashColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "TxHash");
                blockTxBytesColumnId = Api.GetTableColumnid(jetSession, blocksTableId, "TxBytes");

                success = true;
            }
            finally
            {
                if (!success)
                    jetSession.Dispose();
            }
        }