DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Store.FileStoreData Class Reference

A data store that is backed by a file located at the path given. More...

Inheritance diagram for Deveel.Data.Store.FileStoreData:
Deveel.Data.Store.IStoreData

Public Member Functions

 FileStoreData (string filePath)
 
void Dispose ()
 
bool Delete ()
 Deletes the data block. More...
 
void Open (bool readOnly)
 Opens the data block and make it ready to be accessed. More...
 
void Close ()
 Closes the block and make it unavailable. More...
 
int Read (long position, byte[] buffer, int offset, int length)
 Reads a given amount of data from the block, starting at the absolute position given and copying into the provided buffer. More...
 
void Write (long position, byte[] buffer, int offset, int length)
 Writes a given buffer into the block, starting at the absolute position given. More...
 
void Flush ()
 Flushes the data written in the temporary store of the block to the underlying medium. More...
 
void SetLength (long value)
 Sets the length of the data block. More...
 

Properties

string FilePath [get, private set]
 
bool IsOpen [get, private set]
 
bool Exists [get]
 
long Length [get]
 
bool IsReadOnly [get, private set]
 
- Properties inherited from Deveel.Data.Store.IStoreData
bool Exists [get]
 Gets a value indicating whether the data block object exists. More...
 
long Length [get]
 Gets the current length of the data block. More...
 
bool IsReadOnly [get]
 Gets a value indicating whether the data block is in read-only mode. More...
 

Private Member Functions

 ~FileStoreData ()
 
void Dispose (bool disposing)
 

Private Attributes

LocalFile file
 
readonly object objectLock = new object()
 

Detailed Description

A data store that is backed by a file located at the path given.

Definition at line 24 of file FileStoreData.cs.

Constructor & Destructor Documentation

Deveel.Data.Store.FileStoreData.FileStoreData ( string  filePath)
inline

Definition at line 28 of file FileStoreData.cs.

28  {
29  if (String.IsNullOrEmpty(filePath))
30  throw new ArgumentNullException("filePath");
31 
32  FilePath = filePath;
33  IsOpen = false;
34  }
A long string in the system.
Deveel.Data.Store.FileStoreData.~FileStoreData ( )
inlineprivate

Definition at line 36 of file FileStoreData.cs.

36  {
37  Dispose(false);
38  }

Member Function Documentation

void Deveel.Data.Store.FileStoreData.Close ( )
inline

Closes the block and make it unavailable.

When IDisposable.Dispose is invoked this method is also called to prevent any operation before disposal.

Implements Deveel.Data.Store.IStoreData.

Definition at line 93 of file FileStoreData.cs.

93  {
94  lock (objectLock) {
95  try {
96  file.Close();
97  } finally {
98  IsOpen = false;
99  }
100  }
101  }
bool Deveel.Data.Store.FileStoreData.Delete ( )
inline

Deletes the data block.

Returns
Returns true if the block was successfully deleted, or false otherwise.

Implements Deveel.Data.Store.IStoreData.

Definition at line 73 of file FileStoreData.cs.

73  {
74  if (IsOpen)
75  return false;
76 
77  try {
78  File.Delete(FilePath);
79  return !Exists;
80  } catch (Exception) {
81  return false;
82  }
83  }
void Deveel.Data.Store.FileStoreData.Dispose ( )
inline

Definition at line 44 of file FileStoreData.cs.

44  {
45  Dispose(true);
46  GC.SuppressFinalize(this);
47  }
void Deveel.Data.Store.FileStoreData.Dispose ( bool  disposing)
inlineprivate

Definition at line 49 of file FileStoreData.cs.

49  {
50  if (disposing) {
51  if (IsOpen)
52  Close();
53 
54  if (file != null)
55  file.Dispose();
56  }
57  }
void Close()
Closes the block and make it unavailable.
void Deveel.Data.Store.FileStoreData.Flush ( )
inline

Flushes the data written in the temporary store of the block to the underlying medium.

Implements Deveel.Data.Store.IStoreData.

Definition at line 131 of file FileStoreData.cs.

131  {
132  try {
133  file.Flush(true);
134  } catch (IOException) {
135  // There isn't much we can do about this exception. By itself it
136  // doesn't indicate a terminating error so it's a good idea to ignore
137  // it. Should it be silently ignored?
138  }
139  }
void Flush(bool writeThrough)
Definition: LocalFile.cs:83
void Deveel.Data.Store.FileStoreData.Open ( bool  readOnly)
inline

Opens the data block and make it ready to be accessed.

Parameters
readOnlyIndicates if the block must be open in read-only mode.

Implements Deveel.Data.Store.IStoreData.

Definition at line 85 of file FileStoreData.cs.

85  {
86  lock (objectLock) {
87  file = new LocalFile(FilePath, readOnly);
88  IsOpen = true;
89  IsReadOnly = readOnly;
90  }
91  }
int Deveel.Data.Store.FileStoreData.Read ( long  position,
byte[]  buffer,
int  offset,
int  length 
)
inline

Reads a given amount of data from the block, starting at the absolute position given and copying into the provided buffer.

Parameters
positionThe absolute position within the data block from where to start reading.
bufferThe destination buffer where the data read will be filled in.
offsetThe starting offset within the buffer where to start copying the data read.
lengthThe desired number of bytes to read from the data block.
Returns
Returns the actual number of bytes read from the data block or 0 if the end of the block was reached.

Implements Deveel.Data.Store.IStoreData.

Definition at line 103 of file FileStoreData.cs.

103  {
104  // Make sure we don't Read past the end
105  lock (objectLock) {
106  length = System.Math.Max(0, System.Math.Min(length, (int)(Length - position)));
107  int count = 0;
108  if (position < Length) {
109  file.Seek(position, SeekOrigin.Begin);
110  count = file.Read(buffer, offset, length);
111  }
112 
113  return count;
114  }
115  }
long Seek(long offset, SeekOrigin origin)
Definition: LocalFile.cs:67
int Read(byte[] buffer, int offset, int length)
Definition: LocalFile.cs:75
void Deveel.Data.Store.FileStoreData.SetLength ( long  value)
inline

Sets the length of the data block.

Parameters
valueThe new size to set for the data block.

If the value is less than Length this method will shrink the data block and trim the exceeding contents. If the value is more than Length then it is responsibility of the implementation of this contract to increase the contents.

Implements Deveel.Data.Store.IStoreData.

Definition at line 141 of file FileStoreData.cs.

141  {
142  lock (objectLock) {
143  file.SetLength(value);
144  }
145  }
void SetLength(long value)
Definition: LocalFile.cs:71
void Deveel.Data.Store.FileStoreData.Write ( long  position,
byte[]  buffer,
int  offset,
int  length 
)
inline

Writes a given buffer into the block, starting at the absolute position given.

Parameters
positionThe absolute position within the data block from where to start writing.
bufferThe data to write into the block.
offsetThe starting offset within the buffer where to start writing data from.
lengthThe number of bytes to write into the data block.

Implements Deveel.Data.Store.IStoreData.

Definition at line 117 of file FileStoreData.cs.

117  {
118  if (IsReadOnly)
119  throw new IOException();
120 
121  // Make sure we don't Write past the end
122  lock (objectLock) {
123  length = System.Math.Max(0, System.Math.Min(length, (int)(Length - position)));
124  if (position < Length) {
125  file.Seek(position, SeekOrigin.Begin);
126  file.Write(buffer, offset, length);
127  }
128  }
129  }
long Seek(long offset, SeekOrigin origin)
Definition: LocalFile.cs:67
void Write(byte[] buffer, int offset, int length)
Definition: LocalFile.cs:79

Member Data Documentation

LocalFile Deveel.Data.Store.FileStoreData.file
private

Definition at line 25 of file FileStoreData.cs.

readonly object Deveel.Data.Store.FileStoreData.objectLock = new object()
private

Definition at line 26 of file FileStoreData.cs.

Property Documentation

bool Deveel.Data.Store.FileStoreData.Exists
get

Definition at line 59 of file FileStoreData.cs.

string Deveel.Data.Store.FileStoreData.FilePath
getprivate set

Definition at line 40 of file FileStoreData.cs.

bool Deveel.Data.Store.FileStoreData.IsOpen
getprivate set

Definition at line 42 of file FileStoreData.cs.

bool Deveel.Data.Store.FileStoreData.IsReadOnly
getprivate set

Definition at line 71 of file FileStoreData.cs.

long Deveel.Data.Store.FileStoreData.Length
get

Definition at line 67 of file FileStoreData.cs.


The documentation for this class was generated from the following file: