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

An implementation of IStore that persists data in the application memory. More...

Inheritance diagram for Deveel.Data.Store.InMemoryStore:
Deveel.Data.Store.IStore

Classes

class  InMemoryArea
 
class  InMemoryBlock
 

Public Member Functions

void Dispose ()
 
IArea CreateArea (long size)
 Allocates a block of memory in the store of the specified size and returns an IArea object that can be used to initialize the contents of the area. More...
 
void DeleteArea (long id)
 Deletes an area that was previously allocated by the CreateArea method by the area id. More...
 
IArea GetArea (long id, bool readOnly)
 Returns an object that allows for the contents of an area (represented by the id parameter) to be Read. More...
 
void Lock ()
 This method is called before the start of a sequence of Write commands between consistant states of some data structure represented by the store. More...
 
void Unlock ()
 This method is called after the end of a sequence of Write commands between consistant states of some data structure represented by the store. More...
 
void CheckPoint ()
 
IEnumerable< long > GetAllAreas ()
 Returns a complete list of pointers to all areas in the Store as long objects sorted from lowest pointer to highest. More...
 

Package Functions

 InMemoryStore (string name, int hashSize)
 

Properties

string Name [get, private set]
 Gets the unique name of the store within the application. More...
 
InMemoryBlock FixedAreaBlock [get]
 
bool ClosedClean [get]
 
- Properties inherited from Deveel.Data.Store.IStore
bool ClosedClean [get]
 Indicates if the store was closed cleanly last time was accessed. More...
 

Private Member Functions

 ~InMemoryStore ()
 
void Dispose (bool disposing)
 
InMemoryBlock GetBlock (long pointer)
 
InMemoryBlock GetAreaBlock (long pointer)
 

Private Attributes

InMemoryBlock fixedAreaBlock
 
InMemoryBlock[] areaMap
 
long uniqueIdKey
 

Detailed Description

An implementation of IStore that persists data in the application memory.

Definition at line 27 of file InMemoryStore.cs.

Constructor & Destructor Documentation

Deveel.Data.Store.InMemoryStore.InMemoryStore ( string  name,
int  hashSize 
)
inlinepackage

Definition at line 32 of file InMemoryStore.cs.

32  {
33  Name = name;
34  areaMap = new InMemoryBlock[hashSize];
35  uniqueIdKey = 0;
36  }
string Name
Gets the unique name of the store within the application.
Deveel.Data.Store.InMemoryStore.~InMemoryStore ( )
inlineprivate

Definition at line 38 of file InMemoryStore.cs.

38  {
39  Dispose(false);
40  }

Member Function Documentation

void Deveel.Data.Store.InMemoryStore.CheckPoint ( )
inline

Definition at line 171 of file InMemoryStore.cs.

171  {
172  }
IArea Deveel.Data.Store.InMemoryStore.CreateArea ( long  size)
inline

Allocates a block of memory in the store of the specified size and returns an IArea object that can be used to initialize the contents of the area.

Implements Deveel.Data.Store.IStore.

Definition at line 105 of file InMemoryStore.cs.

105  {
106  if (size > Int32.MaxValue)
107  throw new IOException("'size' is too large.");
108 
109  lock (this) {
110  // Generate a unique id for this area.
111  long id = uniqueIdKey;
112  ++uniqueIdKey;
113 
114  // Create the element.
115  var element = new InMemoryBlock(id, (int)size);
116 
117  // The position in the hash map
118  int hashPos = (int)(id % areaMap.Length);
119 
120  // Add to the chain
121  element.Next = areaMap[hashPos];
122  areaMap[hashPos] = element;
123 
124  return element.GetArea(false);
125  }
126  }
void Deveel.Data.Store.InMemoryStore.DeleteArea ( long  id)
inline

Deletes an area that was previously allocated by the CreateArea method by the area id.

Implements Deveel.Data.Store.IStore.

Definition at line 129 of file InMemoryStore.cs.

129  {
130  lock (this) {
131  // Find the pointer in the hash
132  var hashPos = (int)(id % areaMap.Length);
133  InMemoryBlock prev = null;
134  InMemoryBlock block = areaMap[hashPos];
135 
136  // Search for this pointer
137  while (block != null && block.Id != id) {
138  prev = block;
139  block = block.Next;
140  }
141 
142  // If not found
143  if (block == null)
144  throw new IOException("Area ID " + id + " is invalid.");
145 
146  // Remove
147  if (prev == null) {
148  areaMap[hashPos] = block.Next;
149  } else {
150  prev.Next = block.Next;
151  }
152 
153  // Garbage collector should do the rest...
154  }
155  }
void Deveel.Data.Store.InMemoryStore.Dispose ( bool  disposing)
inlineprivate

Definition at line 58 of file InMemoryStore.cs.

58  {
59  if (disposing) {
60  fixedAreaBlock = null;
61  areaMap = null;
62  }
63  }
void Deveel.Data.Store.InMemoryStore.Dispose ( )
inline

Definition at line 65 of file InMemoryStore.cs.

65  {
66  Dispose(true);
67  GC.SuppressFinalize(this);
68  }
IEnumerable<long> Deveel.Data.Store.InMemoryStore.GetAllAreas ( )
inline

Returns a complete list of pointers to all areas in the Store as long objects sorted from lowest pointer to highest.

Implements Deveel.Data.Store.IStore.

Definition at line 180 of file InMemoryStore.cs.

180  {
181  throw new NotImplementedException();
182  }
IArea Deveel.Data.Store.InMemoryStore.GetArea ( long  id,
bool  readOnly 
)
inline

Returns an object that allows for the contents of an area (represented by the id parameter) to be Read.

Implements Deveel.Data.Store.IStore.

Definition at line 158 of file InMemoryStore.cs.

158  {
159  return GetBlock(id).GetArea(readOnly);
160  }
InMemoryBlock GetBlock(long pointer)
InMemoryBlock Deveel.Data.Store.InMemoryStore.GetAreaBlock ( long  pointer)
inlineprivate

Definition at line 77 of file InMemoryStore.cs.

77  {
78  lock (this) {
79  // Find the pointer in the hash
80  var hashPos = (int)(pointer % areaMap.Length);
81  InMemoryBlock prev = null;
82  var block = areaMap[hashPos];
83 
84  // Search for this pointer
85  while (block != null && block.Id != pointer) {
86  prev = block;
87  block = block.Next;
88  }
89 
90  if (block == null)
91  throw new IOException("Pointer " + pointer + " is invalid.");
92 
93  // Move the element to the start of the list.
94  if (prev != null) {
95  prev.Next = block.Next;
96  block.Next = areaMap[hashPos];
97  areaMap[hashPos] = block;
98  }
99 
100  return block;
101  }
102  }
InMemoryBlock Deveel.Data.Store.InMemoryStore.GetBlock ( long  pointer)
inlineprivate

Definition at line 70 of file InMemoryStore.cs.

70  {
71  if (pointer == -1)
72  return FixedAreaBlock;
73 
74  return GetAreaBlock(pointer);
75  }
InMemoryBlock GetAreaBlock(long pointer)
void Deveel.Data.Store.InMemoryStore.Lock ( )
inline

This method is called before the start of a sequence of Write commands between consistant states of some data structure represented by the store.

Implements Deveel.Data.Store.IStore.

Definition at line 163 of file InMemoryStore.cs.

163  {
164  }
void Deveel.Data.Store.InMemoryStore.Unlock ( )
inline

This method is called after the end of a sequence of Write commands between consistant states of some data structure represented by the store.

Implements Deveel.Data.Store.IStore.

Definition at line 167 of file InMemoryStore.cs.

167  {
168  }

Member Data Documentation

InMemoryBlock [] Deveel.Data.Store.InMemoryStore.areaMap
private

Definition at line 29 of file InMemoryStore.cs.

InMemoryBlock Deveel.Data.Store.InMemoryStore.fixedAreaBlock
private

Definition at line 28 of file InMemoryStore.cs.

long Deveel.Data.Store.InMemoryStore.uniqueIdKey
private

Definition at line 30 of file InMemoryStore.cs.

Property Documentation

bool Deveel.Data.Store.InMemoryStore.ClosedClean
get

Definition at line 175 of file InMemoryStore.cs.

InMemoryBlock Deveel.Data.Store.InMemoryStore.FixedAreaBlock
getprivate

Definition at line 47 of file InMemoryStore.cs.

string Deveel.Data.Store.InMemoryStore.Name
getprivate set

Gets the unique name of the store within the application.

Definition at line 45 of file InMemoryStore.cs.


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