internal Transaction(NativeOperator nativeOperator, TransactionMode transactionMode, LockMode lockMode) { _operator = nativeOperator; this.TransactionMode = transactionMode; this.LockMode = lockMode; _operator.BeginTransaction(transactionMode, Utility.GetLockBias(lockMode)); }
public RecordOperator(NativeOperator nativeOperator, Path path, string ownerName, OpenMode?openMode, int reusableCapacity, byte[] temporaryBuffer = null) { var recordType = typeof(TRecord); var recordConstructor = recordType.GetConstructor(new Type[] { typeof(byte[]) }); if (recordConstructor == null) { throw new InvalidDefinitionException(); } _recordConstructor = Resource.GetRecordConstructor(typeof(TRecord)); this.RecordInfo = Resource.GetRecordInfo(recordType); if (temporaryBuffer != null && temporaryBuffer.Length < this.RecordInfo.DataBufferCapacity) { throw new ArgumentException(); } this.PrimaryKeyNumber = this.RecordInfo.PrimaryKeyNumber; _nativeOperator = nativeOperator; this.IsClosable = true; this.HasVariableFields = this.RecordInfo.VariableOption != RecordVariableOption.NotVariable && this.RecordInfo.VariableRangeFields.Count() != 0; this.Path = Path.Merge(path, this.RecordInfo); this.OwnerName = ownerName; this.OpenMode = openMode; this.TemporaryBuffer = temporaryBuffer ?? new byte[ushort.MaxValue]; _reusableCapacity = reusableCapacity; _reusableRecords = new Queue <TRecord>(_reusableCapacity); }
public RecordManager( NativeOperator nativeOperator, string path, string ownerName = null, OpenMode?openMode = null, int reusableCapacity = 1000, byte[] temporaryBuffer = null) : base(nativeOperator, path, ownerName, openMode, reusableCapacity, temporaryBuffer) { }
protected TransactionalObjectFactory(NativeOperator nativeOperator) { this.Operator = nativeOperator; this.Transaction = null; _managedObjects = new List <ITransactionalObject>(); }
public OperatorTest() { _temp = new Temporary("OperatorTest"); _operator = new NativeOperator(); _operator.Reset(); }
public static Record FromBtrieveFile(Path path, string dllPath = null, IEnumerable <string> dependencyPaths = null, byte defaultByte = 0x00, string ownerName = null) { StatData stat; var nativeOperator = new NativeOperator(dllPath: dllPath, dependencyPaths: dependencyPaths); var positionBlock = nativeOperator.Open(path.GetFilePath(), ownerName); try { stat = nativeOperator.Stat(positionBlock); } finally { nativeOperator.Close(positionBlock); } var statKeySpecs = new List <StatKeySpec>(); var keys = new List <Key>(); var fields = new List <Field>(); foreach (var keySpec in stat.KeySpecs) { statKeySpecs.Add(keySpec); if (!keySpec.IsSegmentKey) { var statKey = statKeySpecs .Select(s => new { DuplicateKeyOption = s.DuplicateKeyOption, IsModifiable = s.IsModifiable, NullKeyOption = s.NullKeyOption, KeyNumber = s.Number }) .Distinct() .Single(); var keySegments = new List <KeySegment>(); ushort i = 0; foreach (var statKeySpec in statKeySpecs) { var field = fields.SingleOrDefault(f => f.KeyType == statKeySpec.KeyType && f.Position == statKeySpec.Position && f.Length == statKeySpec.Length); if (field == null) { field = new Field() { Position = statKeySpec.Position, Length = statKeySpec.Length, KeyType = statKeySpec.KeyType, ConverterTypeName = Config.GetConverterTypeName(statKeySpec.KeyType, statKeySpec.Length), Parameter = Config.GetConverterParameter(statKeySpec.KeyType, statKeySpec.Length), NullType = NullType.None }; fields.Add(field); } keySegments.Add( new KeySegment() { Index = i, KeyType = statKeySpec.KeyType, NullValue = statKeySpec.NullValue, IsDescending = statKeySpec.IsDescending, IsIgnoreCase = statKeySpec.IsIgnoreCase, Field = field }); i++; } var key = new Key(); key.Name = String.Format(Config.KeyName, statKey.KeyNumber); key.DuplicateKeyOption = statKey.DuplicateKeyOption; key.IsModifiable = statKey.IsModifiable; key.NullKeyOption = statKey.NullKeyOption; key.KeyNumber = statKey.KeyNumber; key.Segments = keySegments.ToArray(); keys.Add(key); statKeySpecs.Clear(); } } if (statKeySpecs.Count != 0) { throw new InvalidModelException(); } var result = new Record(); if (path.PathType == PathType.Uri) { result.Name = path.UriTable ?? new System.IO.FileInfo(path.UriDbFile ?? path.UriFile ?? "Record").Name; } else { var fileInfo = new System.IO.FileInfo(path.GetFilePath()); result.Name = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length).TrimEnd('.'); } result.FixedLength = stat.FileSpec.RecordLength; result.PageSize = stat.FileSpec.PageSize; result.DuplicatedPointerCount = 0; result.Allocation = 0; result.VariableOption = stat.FileSpec.VariableOption; result.UsesIndexBalancing = stat.FileSpec.UsesIndexBalancing; result.IsCompressed = stat.FileSpec.IsCompressed; result.FreeSpaceThreshold = stat.FileSpec.FreeSpaceThreshold; result.IsManualKeyNumber = stat.FileSpec.IsManualKeyNumber; result.SystemDataOption = stat.FileSpec.SystemDataOption; result.DefaultByte = defaultByte; result.OwnerName = ownerName; result.UriTable = path.UriTable; result.UriDbFile = path.UriDbFile; result.UriFile = path.UriFile; result.AbsolutePath = path.AbsolutePath; result.RelativePath = path.RelativePath; result.VariableFieldCapacity = 0; result.Keys = keys.ToArray(); result.Fields = fields.OrderBy(f => f.Position).ToArray(); Record.Initialize(result, true); return(result); }
public RecordOperator(NativeOperator nativeOperator, string path, string ownerName = null, OpenMode?openMode = null, int reusableCapacity = 1000, byte[] temporaryBuffer = null) : this(nativeOperator, Path.Absolute(path), ownerName, openMode, reusableCapacity, temporaryBuffer) { }