public void Setup() { _startUpLog = SetupMock <IStartupLog>(); _errorLog = SetupMock <IErrorLog>(); _pagePoolFactory = SetupMock <IPagePoolFactory>(); _pagePool = _pagePoolFactory.Create(_pageSize); _dataFileInfo = new FileInfo("C:\\temp\\test.mdf"); _dataFile = new DataFile(_dataFileInfo, _pageSize, _startUpLog); _logFileInfo = new FileInfo("C:\\temp\\test.ldf"); _logFile = new LogFile(_logFileInfo, true, _startUpLog); _fileSet = new FileSet( new[] { _dataFile }, new[] { _logFile }, _pagePoolFactory, _startUpLog); var databaseFactory = SetupMock <IDatabaseFactory>(); _database = databaseFactory.Open(null); var pageCache = new PageCache(_fileSet, _database, _pagePoolFactory, _startUpLog, _errorLog); _pageStore = new PageStore(pageCache, _startUpLog); _accessorFactory = new AccessorFactory(); _accessor = _accessorFactory.SmallSequentialAccessor(_pageStore); }
/// <summary> /// After calling Append you can call this method to write the record data. This is convenient /// if the record data is already in a single byte array. /// </summary> /// <param name="transaction">The transaction context for updating the pages</param> /// <param name="location">The location to write to as returned from the Append method</param> /// <param name="recordPieces">The chunks of data to write into the spece reserved for the record. /// The lengths of these chuncks must add up to the record length in the location parameter</param> public static void Write( this ISequentialRecordAccessor accessor, ITransaction transaction, PageLocation location, IEnumerable <byte[]> recordPieces) { throw new NotImplementedException(); }
/// <summary> /// After calling Append you can call this method to write the record data. This is convenient /// if the record data is already in a single byte array. /// </summary> /// <param name="transaction">The transaction context for updating the pages</param> /// <param name="location">The location to write to as returned from the Append method</param> /// <param name="record">The array of bytes to write. This must be the same size as the /// length property of the location parameter</param> public static void Write( this ISequentialRecordAccessor accessor, ITransaction transaction, PageLocation location, byte[] record) { if (location.Length != (uint)record.LongLength) { throw new FileLayerException("Incorrect record length writing to sequential accessor"); } var pageSize = location.PageStore.PageSize; var bytesRemaining = (ulong)record.LongLength; var recordOffset = 0UL; var updates = new List <PageUpdate>(); var sequence = 1U; var pageIndex = -1; while (bytesRemaining > 0) { if (pageIndex >= 0) { var bytesToCopy = bytesRemaining < pageSize ? bytesRemaining : pageSize; var buffer = new byte[bytesToCopy]; Array.Copy(record, (long)recordOffset, buffer, 0, (long)bytesToCopy); updates.Add( new PageUpdate { SequenceNumber = sequence++, PageNumber = location.ContunuationPages[pageIndex], Offset = 0U, Data = buffer }); bytesRemaining -= bytesToCopy; recordOffset += bytesToCopy; } else if (location.Offset + bytesRemaining > pageSize) { var bytesToCopy = pageSize - location.Offset; var buffer = new byte[bytesToCopy]; Array.Copy(record, 0, buffer, 0, buffer.LongLength); updates.Add( new PageUpdate { SequenceNumber = sequence++, PageNumber = location.PageNumber, Offset = location.Offset, Data = buffer }); bytesRemaining -= bytesToCopy; recordOffset = bytesToCopy; } else { updates.Add( new PageUpdate { SequenceNumber = sequence++, PageNumber = location.PageNumber, Offset = location.Offset, Data = record }); bytesRemaining = 0; } pageIndex++; } location.PageStore.Update(transaction, updates); }
public SequentialRecordEnumerator(ISequentialRecordAccessor accessor, ulong firstPageNumber, ITransaction transaction) { _accessor = accessor; _firstPageNumber = firstPageNumber; _transaction = transaction; }