Пример #1
0
        /// <summary>
        /// Initializes a new instance of the TableBase class.
        /// </summary>
        /// <param name="connection">The connection the table is opened against.</param>
        /// <param name="table">The name of the table to open.</param>
        protected TableBase(ConnectionBase connection, string table)
        {
            this.Tracer = new Tracer("Table", "Esent Table", String.Format("Table {0}", table));
            this.Connection = connection;
            this.tablename = table;

            this.recordsWithOpenCursor = new List<Record>();
            this.tableCursor = this.OpenCursor();
            this.CursorCache = new CursorCache<Cursor>(this.OpenCursor, this.CloseCursor, this.TableName, 4);

            this.LoadMetaData();
            this.Tracer.TraceInfo("opened");
        }
Пример #2
0
        /// <summary>
        /// Create the column for this definition in the specified table.
        /// </summary>
        /// <param name="cursor">
        /// The cursor to create the column on.
        /// </param>
        internal void CreateColumn(Cursor cursor)
        {
            var interopConversion = Dependencies.Container.Resolve<InteropConversion>();

            JET_COLUMNDEF columndef = interopConversion.CreateColumndefFromColumnDefinition(this);

            JET_COLUMNID ignored;
            if (null != this.DefaultValue)
            {
                var dataConversion = Dependencies.Container.Resolve<DataConversion>();
                object defaultValueObject = dataConversion.ConvertToObject[this.Type](this.DefaultValue);
                byte[] defaultValue = dataConversion.ConvertObjectToBytes[this.Type](defaultValueObject);
                cursor.AddColumn(this.Name, columndef, defaultValue, out ignored);
            }
            else
            {
                cursor.AddColumn(this.Name, columndef, null, out ignored);
            }
        }
Пример #3
0
        /// <summary>
        /// Open a new Cursor.
        /// </summary>
        /// <param name="tablename">The name of the table to open the cursor on.</param>
        /// <returns>A new cursor opened on the table.</returns>
        public Cursor OpenCursor(string tablename)
        {
            var cursor = new Cursor(this.session, this.dbid, tablename);

            if (this.InTransaction)
            {
                EsentTransaction currentTransaction = this.level0Transaction.GetNewestTransaction();
                currentTransaction.RolledBack += cursor.Dispose;
            }

            this.Tracer.TraceVerbose("opened cursor on table '{0}'", tablename);
            return cursor;
        }
Пример #4
0
 /// <summary>
 /// Return the value of the columnidLong of the cursor.
 /// </summary>
 /// <param name="cursor">The cursor to retrieve the column from.</param>
 /// <returns>The value of the columnid, converted to an int.</returns>
 private int RetrieveColumn(Cursor cursor)
 {
     byte[] data = cursor.RetrieveColumn(this.columnidLong, RetrieveColumnGrbit.None);
     Assert.AreEqual(4, data.Length);
     return BitConverter.ToInt32(data, 0);
 }
Пример #5
0
 /// <summary>
 /// Assert that we are currently positioned on the given record.
 /// </summary>
 /// <param name="cursor">The cursor to check.</param>
 /// <param name="recordId">The expected record ID.</param>
 private void AssertOnRecord(Cursor cursor, int recordId)
 {
     int actualId = this.RetrieveColumn(cursor);
     Assert.AreEqual(recordId, actualId);
 }
Пример #6
0
        /// <summary>
        /// Open a new cursor for this table.
        /// </summary>
        /// <returns>The new cursor.</returns>
        private Cursor OpenCursor()
        {
            Cursor theCursor;
            if (null != this.cachedCursor)
            {
                theCursor = this.cachedCursor;
                this.cachedCursor = null;
            }
            else
            {
                theCursor = new Cursor(this.Session, this.Dbid, this.TableName);
                this.Tracer.TraceInfo("opening a new Cursor");
            }

            return theCursor;
        }
Пример #7
0
 /// <summary>
 /// Create a record from the current position of the specified tableid.
 /// </summary>
 /// <param name="cursor">The cursor positioned on the record.</param>
 /// <returns>A new record containing the bookmark of the current position.</returns>
 private Record CreateRecordFromCurrentPosition(Cursor cursor)
 {
     return this.CreateRecord(cursor.GetBookmark());
 }
Пример #8
0
        /// <summary>
        /// Closes the table, freeing ESE resources.
        /// </summary>
        private void Close()
        {
            if (!this.IsClosed)
            {
                this.DisposeAllRecordsWithOpenTableids();
                this.CursorCache.Close();

                if (null != this.cachedCursor)
                {
                    this.cachedCursor.Dispose();
                }

                if (null != this.tableCursor)
                {
                    this.tableCursor.Dispose();
                }

                this.cachedCursor = null;
                this.tableCursor = null;

                GC.SuppressFinalize(this);
                this.Tracer.TraceInfo("closed");

                if (null != this.Disposed)
                {
                    this.Disposed(this);
                }

                this.IsClosed = true;
            }
        }
Пример #9
0
 /// <summary>
 /// Close a cursor on the table.
 /// </summary>
 /// <param name="cursor">The cursor to close.</param>
 public void CloseCursor(Cursor cursor)
 {
     if (null == this.cachedCursor)
     {
         this.cachedCursor = cursor;
     }
     else
     {
         cursor.Dispose();
     }
 }