DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Public Attributes | Package Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.TableSourceComposite Class Reference
Inheritance diagram for Deveel.Data.TableSourceComposite:
Deveel.Data.Sql.Tables.ITableSourceComposite

Public Member Functions

 TableSourceComposite (Database database)
 
void Dispose ()
 
bool Exists ()
 
void Open ()
 
void Create ()
 
void Close ()
 
void Delete ()
 
int NextTableId ()
 

Public Attributes

const string ObjectStoreName = "lob_store"
 

Package Functions

void MinimalCreate ()
 
TableSource CreateTableSource (TableInfo tableInfo, bool temporary)
 
TableSource GetTableSource (int tableId)
 
void Commit (Transaction transaction, IList< ITableSource > visibleTables, IEnumerable< ITableSource > selectedFromTables, IEnumerable< IMutableTable > touchedTables, TransactionRegistry journal, Action< TableCommitInfo > commitActions)
 
void Rollback (Transaction transaction, IList< IMutableTable > touchedTables, TransactionRegistry journal)
 
TableSource CopySourceTable (TableSource tableSource, IIndexSet indexSet)
 
ITransaction CreateTransaction (IsolationLevel isolation)
 
void RegisterOnCommit (Action< TableCommitInfo > action)
 
void UnregisterOnCommit (Action< TableCommitInfo > action)
 
void CloseTransaction (ITransaction transaction)
 
void CommitToTables (IEnumerable< int > createdTables, IEnumerable< int > droppedTables)
 
bool ContainsVisibleResource (int resourceId)
 

Properties

Database Database [get, private set]
 
IDatabaseContext DatabaseContext [get]
 
IStoreSystem StoreSystem [get]
 
int CurrentCommitId [get, private set]
 
bool IsReadOnly [get]
 
bool IsClosed [get]
 
TableStateStore StateStore [get, set]
 
string StateStoreName [get, set]
 
IObjectStore LargeObjectStore [get, set]
 

Private Member Functions

 ~TableSourceComposite ()
 
void ReadVisibleTables ()
 
void ReadDroppedTables ()
 
TableSource LoadTableSource (int tableId, string tableName)
 
void MarkUncommitted (int tableId)
 
void Dispose (bool disposing)
 
void Setup ()
 
void InitObjectStore ()
 
void CleanUp ()
 
bool CloseAndDropTable (string tableFileName)
 
void CloseTable (string sourceName, bool pendingDrop)
 
void InitSystemSchema ()
 
void CreateSystemSchema ()
 
ITableSource ITableSourceComposite. CreateTableSource (TableInfo tableInfo, bool temporary)
 
void OnCommitModification (ObjectName objName, IEnumerable< int > addedRows, IEnumerable< int > removedRows)
 
ITableSource ITableSourceComposite. CopySourceTable (ITableSource tableSource, IIndexSet indexSet)
 

Private Attributes

readonly object commitLock = new object()
 
Dictionary< int, TableSourcetableSources
 
List< TransactionObjectStateobjectStates
 
IStoreSystem tempStoreSystem
 
IStore lobStore
 
IStore stateStore
 
const string StateStorePostfix = "_sf"
 
Action< TableCommitInfotableCommitCallback
 

Detailed Description

Definition at line 29 of file TableSourceComposite.cs.

Constructor & Destructor Documentation

Deveel.Data.TableSourceComposite.TableSourceComposite ( Database  database)
inline

Definition at line 43 of file TableSourceComposite.cs.

43  {
44  Database = database;
45 
47  objectStates = new List<TransactionObjectState>();
48 
49  StateStoreName = String.Format("{0}{1}", database.Name, StateStorePostfix);
50 
51  Setup();
52  }
A long string in the system.
List< TransactionObjectState > objectStates
Deveel.Data.TableSourceComposite.~TableSourceComposite ( )
inlineprivate

Definition at line 54 of file TableSourceComposite.cs.

54  {
55  Dispose(false);
56  }

Member Function Documentation

void Deveel.Data.TableSourceComposite.CleanUp ( )
inlineprivate

Definition at line 238 of file TableSourceComposite.cs.

238  {
239  lock (commitLock) {
240  if (IsClosed)
241  return;
242 
243  // If no open transactions on the database, then clean up.
245  var deleteList = StateStore.GetDeleteList().ToArray();
246  if (deleteList.Length > 0) {
247  int dropCount = 0;
248 
249  for (int i = deleteList.Length - 1; i >= 0; --i) {
250  var tableName = deleteList[i].SourceName;
251  CloseTable(tableName, true);
252  }
253 
254  for (int i = deleteList.Length - 1; i >= 0; --i) {
255  string tableName = deleteList[i].SourceName;
256  bool dropped = CloseAndDropTable(tableName);
257  // If we managed to drop the table, remove from the list.
258  if (dropped) {
259  StateStore.RemoveDeleteResource(tableName);
260  ++dropCount;
261  }
262  }
263 
264  // If we dropped a table, commit an update to the conglomerate state.
265  if (dropCount > 0)
266  StateStore.Flush();
267  }
268  }
269  }
270  }
void CloseTable(string sourceName, bool pendingDrop)
void RemoveDeleteResource(string name)
bool CloseAndDropTable(string tableFileName)
ITransactionFactory TransactionFactory
Gets an object that is used to create new transactions to this database
Definition: Database.cs:89
IEnumerable< TableState > GetDeleteList()
TransactionCollection OpenTransactions
Gets the collection of currently open transactions.
void Deveel.Data.TableSourceComposite.Close ( )
inline

Definition at line 413 of file TableSourceComposite.cs.

413  {
414  lock (commitLock) {
415  CleanUp();
416 
418 
419  // Go through and close all the committed tables.
420  foreach (var source in tableSources.Values) {
421  source.Close(false);
422  }
423 
424  StateStore.Flush();
426 
427  tableSources = null;
428  }
429 
430  // Release the storage system
432 
433  if (LargeObjectStore != null)
435  }
void Unlock(String lockName)
Unlocks the exclusive access to the persistent store objects.
Dictionary< int, TableSource > tableSources
void SetCheckPoint()
Sets a new check point at the current state of this store system.
bool CloseStore(IStore store)
Closes a store that has been either created or opened with the CreateStore or OpenStore methods...
bool Deveel.Data.TableSourceComposite.CloseAndDropTable ( string  tableFileName)
inlineprivate

Definition at line 272 of file TableSourceComposite.cs.

272  {
273  // Find the table with this file name.
274  int? tableId = null;
275  foreach (var source in tableSources.Values) {
276  if (source.StoreIdentity.Equals(tableFileName)) {
277  if (source.IsRootLocked)
278  return false;
279 
280  if (!source.Drop())
281  return false;
282 
283  tableId = source.TableId;
284  }
285  }
286 
287  if (tableId != null)
288  tableSources.Remove(tableId.Value);
289 
290  return false;
291  }
Dictionary< int, TableSource > tableSources
void Deveel.Data.TableSourceComposite.CloseTable ( string  sourceName,
bool  pendingDrop 
)
inlineprivate

Definition at line 293 of file TableSourceComposite.cs.

293  {
294  // Find the table with this file name.
295  foreach (var source in tableSources.Values) {
296  if (source.SourceName.Equals(sourceName)) {
297  if (source.IsRootLocked)
298  break;
299 
300  source.Close(pendingDrop);
301  break;
302  }
303  }
304  }
Dictionary< int, TableSource > tableSources
void Deveel.Data.TableSourceComposite.CloseTransaction ( ITransaction  transaction)
inlinepackage

Definition at line 657 of file TableSourceComposite.cs.

657  {
658  bool lastTransaction;
659  // Closing must happen under a commit Lock.
660  lock (commitLock) {
662  // Increment the commit id.
663  ++CurrentCommitId;
664  // Was that the last transaction?
665  lastTransaction = Database.TransactionFactory.OpenTransactions.Count == 0;
666  }
667 
668  // If last transaction then schedule a clean up event.
669  if (lastTransaction) {
670  try {
671  CleanUp();
672  } catch (IOException) {
673  // TODO: Register the error ...
674  }
675  }
676  }
ITransactionFactory TransactionFactory
Gets an object that is used to create new transactions to this database
Definition: Database.cs:89
TransactionCollection OpenTransactions
Gets the collection of currently open transactions.
void Deveel.Data.TableSourceComposite.Commit ( Transaction  transaction,
IList< ITableSource visibleTables,
IEnumerable< ITableSource selectedFromTables,
IEnumerable< IMutableTable touchedTables,
TransactionRegistry  journal,
Action< TableCommitInfo commitActions 
)
inlinepackage

Definition at line 519 of file TableSourceComposite.cs.

521  {
522 
523  var state = new TransactionWork(this, transaction, selectedFromTables, touchedTables, journal);
524 
525  // Exit early if nothing changed (this is a Read-only transaction)
526  if (!state.HasChanges) {
527  CloseTransaction(state.Transaction);
528  return;
529  }
530 
531  lock (commitLock) {
532  var changedTablesList = state.Commit(objectStates, commitActions);
533 
534  // Flush the journals up to the minimum commit id for all the tables
535  // that this transaction changed.
537  foreach (var master in changedTablesList) {
538  master.MergeChanges(minCommitId);
539  }
540  int nsjsz = objectStates.Count;
541  for (int i = nsjsz - 1; i >= 0; --i) {
542  var namespaceJournal = objectStates[i];
543  // Remove if the commit id for the journal is less than the minimum
544  // commit id
545  if (namespaceJournal.CommitId < minCommitId) {
546  objectStates.RemoveAt(i);
547  }
548  }
549 
550  // Set a check point in the store system. This means that the
551  // persistance state is now stable.
553  }
554  }
List< TransactionObjectState > objectStates
void SetCheckPoint()
Sets a new check point at the current state of this store system.
ITransactionFactory TransactionFactory
Gets an object that is used to create new transactions to this database
Definition: Database.cs:89
void CloseTransaction(ITransaction transaction)
TransactionCollection OpenTransactions
Gets the collection of currently open transactions.
void Deveel.Data.TableSourceComposite.CommitToTables ( IEnumerable< int >  createdTables,
IEnumerable< int >  droppedTables 
)
inlinepackage

Definition at line 678 of file TableSourceComposite.cs.

678  {
679  // Add created tables to the committed tables list.
680  foreach (int createdTable in createdTables) {
681  // For all created tables, add to the visible list and remove from the
682  // delete list in the state store.
683  var t = GetTableSource(createdTable);
684  var resource = new TableStateStore.TableState(t.TableId, t.SourceName);
685  StateStore.AddVisibleResource(resource);
686  StateStore.RemoveDeleteResource(resource.SourceName);
687  }
688 
689  // Remove dropped tables from the committed tables list.
690  foreach (int droppedTable in droppedTables) {
691  // For all dropped tables, add to the delete list and remove from the
692  // visible list in the state store.
693  var t = GetTableSource(droppedTable);
694  var resource = new TableStateStore.TableState(t.TableId, t.SourceName);
695  StateStore.AddDeleteResource(resource);
696  StateStore.RemoveVisibleResource(resource.SourceName);
697  }
698 
699  try {
700  StateStore.Flush();
701  } catch (IOException e) {
702  throw new InvalidOperationException("IO Error: " + e.Message, e);
703  }
704  }
TableSource GetTableSource(int tableId)
void AddDeleteResource(TableState resource)
void RemoveDeleteResource(string name)
void AddVisibleResource(TableState resource)
void RemoveVisibleResource(string name)
bool Deveel.Data.TableSourceComposite.ContainsVisibleResource ( int  resourceId)
inlinepackage

Definition at line 706 of file TableSourceComposite.cs.

706  {
707  return StateStore.ContainsVisibleResource(resourceId);
708  }
bool ContainsVisibleResource(int tableId)
ITableSource ITableSourceComposite. Deveel.Data.TableSourceComposite.CopySourceTable ( ITableSource  tableSource,
IIndexSet  indexSet 
)
inlineprivate

Implements Deveel.Data.Sql.Tables.ITableSourceComposite.

Definition at line 590 of file TableSourceComposite.cs.

590  {
591  return CopySourceTable((TableSource) tableSource, indexSet);
592  }
ITableSource ITableSourceComposite. CopySourceTable(ITableSource tableSource, IIndexSet indexSet)
TableSource Deveel.Data.TableSourceComposite.CopySourceTable ( TableSource  tableSource,
IIndexSet  indexSet 
)
inlinepackage

Definition at line 594 of file TableSourceComposite.cs.

594  {
595  lock (commitLock) {
596  try {
597  // The unique id that identifies this table,
598  int tableId = NextTableId();
599  var sourceName = tableSource.SourceName;
600 
601  // Create the object.
602  var masterTable = new TableSource(this, StoreSystem, LargeObjectStore, tableId, sourceName);
603 
604  masterTable.CopyFrom(tableId, tableSource, indexSet);
605 
606  // Add to the list of all tables.
607  tableSources.Add(tableId, masterTable);
608 
609  // Add this to the list of deleted tables,
610  MarkUncommitted(tableId);
611 
612  // Commit this
613  StateStore.Flush();
614 
615  // And return it.
616  return masterTable;
617  } catch (IOException e) {
618  throw new Exception(String.Format("Unable to copy source table '{0}' because of an error.", tableSource.TableInfo.TableName), e);
619  }
620  }
621  }
A long string in the system.
Dictionary< int, TableSource > tableSources
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
void Deveel.Data.TableSourceComposite.Create ( )
inline

Definition at line 339 of file TableSourceComposite.cs.

339  {
340  MinimalCreate();
341 
342  // Initialize the conglomerate system tables.
344 
345  // Commit the state
346  StateStore.Flush();
347  }
void Deveel.Data.TableSourceComposite.CreateSystemSchema ( )
inlineprivate

Definition at line 394 of file TableSourceComposite.cs.

394  {
395  // Create the transaction
396  ITransaction transaction = null;
397 
398  try {
399  transaction = Database.CreateSafeTransaction(IsolationLevel.Serializable);
400  transaction.CreateSystemSchema();
401 
402  // Commit and close the transaction.
403  transaction.Commit();
404  transaction = null;
405  } catch (TransactionException e) {
406  throw new InvalidOperationException("Transaction Exception creating composite.", e);
407  } finally {
408  if (transaction != null)
409  transaction.Rollback();
410  }
411  }
void Rollback()
Rollback any write operations done during the lifetime of this transaction and invalidates it...
void Commit()
Commits all write operation done during the lifetime of this transaction and invalidates it...
The simplest implementation of a transaction.
Definition: ITransaction.cs:30
ITableSource ITableSourceComposite. Deveel.Data.TableSourceComposite.CreateTableSource ( TableInfo  tableInfo,
bool  temporary 
)
inlineprivate

Implements Deveel.Data.Sql.Tables.ITableSourceComposite.

Definition at line 464 of file TableSourceComposite.cs.

464  {
465  return CreateTableSource(tableInfo, temporary);
466  }
ITableSource ITableSourceComposite. CreateTableSource(TableInfo tableInfo, bool temporary)
TableSource Deveel.Data.TableSourceComposite.CreateTableSource ( TableInfo  tableInfo,
bool  temporary 
)
inlinepackage

Implements Deveel.Data.Sql.Tables.ITableSourceComposite.

Definition at line 468 of file TableSourceComposite.cs.

468  {
469  lock (commitLock) {
470  try {
471  int tableId = NextTableId();
472 
473  // Create the object.
474  var storeSystem = StoreSystem;
475  if (temporary)
476  storeSystem = tempStoreSystem;
477 
478  var source = new TableSource(this, storeSystem, LargeObjectStore, tableId, tableInfo.TableName.FullName);
479  source.Create(tableInfo);
480 
481  tableSources.Add(tableId, source);
482 
483  if (!temporary) {
484  MarkUncommitted(tableId);
485 
486  StateStore.Flush();
487  }
488 
489  // And return it.
490  return source;
491  } catch (IOException e) {
492  throw new InvalidOperationException(String.Format("Unable to create source for table '{0}'.", tableInfo.TableName), e);
493  }
494  }
495  }
A long string in the system.
Dictionary< int, TableSource > tableSources
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
ITransaction Deveel.Data.TableSourceComposite.CreateTransaction ( IsolationLevel  isolation)
inlinepackage

Definition at line 623 of file TableSourceComposite.cs.

623  {
624  var thisCommittedTables = new List<TableSource>();
625 
626  // Don't let a commit happen while we are looking at this.
627  lock (commitLock) {
628  int thisCommitId = CurrentCommitId;
629  var committedTableList = StateStore.GetVisibleList();
630  thisCommittedTables.AddRange(committedTableList.Select(resource => GetTableSource(resource.TableId)));
631 
632  // Create a set of IIndexSet for all the tables in this transaction.
633  var indexInfo = (thisCommittedTables.Select(mtable => mtable.CreateIndexSet())).ToList();
634 
635  // Create a context for the transaction to handle the isolated storage of variables and services
637 
638  // Create the transaction and record it in the open transactions list.
639  return new Transaction(context, Database, thisCommitId, isolation, thisCommittedTables, indexInfo);
640  }
641  }
TableSource GetTableSource(int tableId)
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
IEnumerable< TableState > GetVisibleList()
ITransactionContext CreateTransactionContext()
Creates a context to handle services and variables in the scope of a transaction. ...
void Deveel.Data.TableSourceComposite.Delete ( )
inline

Definition at line 437 of file TableSourceComposite.cs.

437  {
438  lock (commitLock) {
439  // We possibly have things to clean up.
440  CleanUp();
441 
442  // Go through and delete and close all the committed tables.
443  foreach (var source in tableSources.Values)
444  source.Drop();
445 
446  // Delete the state file
447  StateStore.Flush();
450 
451  // Delete the blob store
452  if (LargeObjectStore != null) {
455  }
456 
457  tableSources = null;
458  }
459 
460  // Release the storage system.
462  }
void Unlock(String lockName)
Unlocks the exclusive access to the persistent store objects.
Dictionary< int, TableSource > tableSources
bool CloseStore(IStore store)
Closes a store that has been either created or opened with the CreateStore or OpenStore methods...
bool DeleteStore(IStore store)
Permanently deletes a store from the system - use with care!
void Deveel.Data.TableSourceComposite.Dispose ( bool  disposing)
inlineprivate

Definition at line 169 of file TableSourceComposite.cs.

169  {
170  if (disposing) {
171  if (!IsClosed)
172  Close();
173 
174  if (lobStore != null)
175  lobStore.Dispose();
176  if (stateStore != null)
177  stateStore.Dispose();
178 
179  if (tempStoreSystem != null)
180  tempStoreSystem.Dispose();
181 
182  tempStoreSystem = null;
183  lobStore = null;
184  }
185  }
void Deveel.Data.TableSourceComposite.Dispose ( )
inline

Definition at line 187 of file TableSourceComposite.cs.

187  {
188  Dispose(true);
189  GC.SuppressFinalize(this);
190  }
bool Deveel.Data.TableSourceComposite.Exists ( )
inline

Definition at line 306 of file TableSourceComposite.cs.

306  {
308  }
bool StoreExists(String name)
Returns true if the store with the given name exists within the system, or false otherwise.
TableSource Deveel.Data.TableSourceComposite.GetTableSource ( int  tableId)
inlinepackage

Definition at line 497 of file TableSourceComposite.cs.

497  {
498  lock (commitLock) {
499  if (tableSources == null)
500  return null;
501 
502  TableSource source;
503  if (!tableSources.TryGetValue(tableId, out source))
504  throw new ObjectNotFoundException(
505  String.Format("Could not find any source for table with id {0} in this composite.", tableId));
506 
507  return source;
508  }
509  }
A long string in the system.
Dictionary< int, TableSource > tableSources
void Deveel.Data.TableSourceComposite.InitObjectStore ( )
inlineprivate

Definition at line 199 of file TableSourceComposite.cs.

199  {
200  // Does the file already exist?
201  bool blobStoreExists = StoreSystem.StoreExists(ObjectStoreName);
202  // If the blob store doesn't exist and we are read_only, we can't do
203  // anything further so simply return.
204  if (!blobStoreExists && IsReadOnly) {
205  return;
206  }
207 
208  // The blob store,
209  if (blobStoreExists) {
211  } else {
213  }
214 
215  try {
216  lobStore.Lock();
217 
218  // TODO: have multiple BLOB stores
220 
221  // Get the 64 byte fixed area
222  var fixedArea = lobStore.GetArea(-1, false);
223  // If the blob store didn't exist then we need to create it here,
224  if (!blobStoreExists) {
225  long headerP = LargeObjectStore.Create();
226  fixedArea.WriteInt8(headerP);
227  fixedArea.Flush();
228  } else {
229  // Otherwise we need to initialize the blob store
230  long headerP = fixedArea.ReadInt8();
231  LargeObjectStore.Open(headerP);
232  }
233  } finally {
234  lobStore.Unlock();
235  }
236  }
IStore CreateStore(String name)
Creates and returns a new persistent Store object given the unique name of the store.
void Lock()
This method is called before the start of a sequence of Write commands between consistant states of s...
void Open(long startOffset)
void Unlock()
This method is called after the end of a sequence of Write commands between consistant states of some...
IStore OpenStore(String name)
Opens an existing persistent Store object in the system and returns the IStore object that contains i...
bool StoreExists(String name)
Returns true if the store with the given name exists within the system, or false otherwise.
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...
void Deveel.Data.TableSourceComposite.InitSystemSchema ( )
inlineprivate

Definition at line 349 of file TableSourceComposite.cs.

349  {
350  using (var transaction = Database.CreateSafeTransaction(IsolationLevel.Serializable)) {
351  try {
352  SystemSchema.Setup(transaction);
353  transaction.Commit();
354  } catch (Exception ex) {
355  throw new InvalidOperationException("Transaction Exception initializing tables.", ex);
356  }
357  }
358  }
TableSource Deveel.Data.TableSourceComposite.LoadTableSource ( int  tableId,
string  tableName 
)
inlineprivate

Definition at line 136 of file TableSourceComposite.cs.

136  {
137  var source = new TableSource(this, StoreSystem, LargeObjectStore, tableId, tableName);
138  if (!source.Exists())
139  return null;
140 
141  return source;
142  }
void Deveel.Data.TableSourceComposite.MarkUncommitted ( int  tableId)
inlineprivate

Definition at line 144 of file TableSourceComposite.cs.

144  {
145  var masterTable = GetTableSource(tableId);
146  StateStore.AddDeleteResource(new TableStateStore.TableState(tableId, masterTable.SourceName));
147  }
TableSource GetTableSource(int tableId)
void AddDeleteResource(TableState resource)
void Deveel.Data.TableSourceComposite.MinimalCreate ( )
inlinepackage

Definition at line 360 of file TableSourceComposite.cs.

360  {
361  if (Exists())
362  throw new IOException("Composite already exists");
363 
364  // Lock the store system (generates an IOException if exclusive Lock
365  // can not be made).
366  if (!IsReadOnly) {
368  }
369 
370  // Create/Open the state store
372  try {
373  stateStore.Lock();
374 
375  StateStore = new TableStateStore(stateStore);
376  long headP = StateStore.Create();
377  // Get the fixed area
378  var fixedArea = stateStore.GetArea(-1);
379  fixedArea.WriteInt8(headP);
380  fixedArea.Flush();
381  } finally {
382  stateStore.Unlock();
383  }
384 
385  Setup();
386 
387  // Init the conglomerate blob store
388  InitObjectStore();
389 
390  // Create the system table (but don't initialize)
392  }
IStore CreateStore(String name)
Creates and returns a new persistent Store object given the unique name of the store.
void Lock()
This method is called before the start of a sequence of Write commands between consistant states of s...
void Unlock()
This method is called after the end of a sequence of Write commands between consistant states of some...
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...
void Lock(String lockName)
Attempts to lock this store system exclusively so that no other process may access or change the pers...
int Deveel.Data.TableSourceComposite.NextTableId ( )
inline

Definition at line 511 of file TableSourceComposite.cs.

511  {
512  return StateStore.NextTableId();
513  }
void Deveel.Data.TableSourceComposite.OnCommitModification ( ObjectName  objName,
IEnumerable< int >  addedRows,
IEnumerable< int >  removedRows 
)
inlineprivate

Definition at line 515 of file TableSourceComposite.cs.

515  {
516 
517  }
void Deveel.Data.TableSourceComposite.Open ( )
inline

Definition at line 310 of file TableSourceComposite.cs.

310  {
311  if (!Exists())
312  throw new IOException("Table composite does not exist");
313 
314  // Check the file Lock
315  if (!IsReadOnly) {
316  // Obtain the Lock (generate error if this is not possible)
318  }
319 
320  // Open the state store
322  StateStore = new TableStateStore(stateStore);
323 
324  // Get the fixed 64 byte area.
325  var fixedArea = stateStore.GetArea(-1);
326  long headP = fixedArea.ReadInt8();
327  StateStore.Open(headP);
328 
329  Setup();
330 
331  InitObjectStore();
332 
335 
336  CleanUp();
337  }
IStore OpenStore(String name)
Opens an existing persistent Store object in the system and returns the IStore object that contains i...
IArea GetArea(long id, bool readOnly)
Returns an object that allows for the contents of an area (represented by the id parameter) to be Re...
void Lock(String lockName)
Attempts to lock this store system exclusively so that no other process may access or change the pers...
void Deveel.Data.TableSourceComposite.ReadDroppedTables ( )
inlineprivate

Definition at line 108 of file TableSourceComposite.cs.

108  {
109  lock (commitLock) {
110  // The list of all dropped tables from the state file
111  var tables = StateStore.GetDeleteList();
112 
113  // For each visible table
114  foreach (var resource in tables) {
115  int tableId =resource.TableId;
116  string tableName = resource.SourceName;
117 
118  // Load the master table from the resource information
119  var source = LoadTableSource(tableId, tableName);
120 
121  // File wasn't found so remove from the delete resources
122  if (source == null) {
123  StateStore.RemoveDeleteResource(tableName);
124  } else {
125  source.Open();
126 
127  // Add the table to the table list
128  tableSources.Add(tableId, source);
129  }
130  }
131 
132  StateStore.Flush();
133  }
134  }
Dictionary< int, TableSource > tableSources
TableSource LoadTableSource(int tableId, string tableName)
void RemoveDeleteResource(string name)
IEnumerable< TableState > GetDeleteList()
void Deveel.Data.TableSourceComposite.ReadVisibleTables ( )
inlineprivate

Definition at line 84 of file TableSourceComposite.cs.

84  {
85  lock (commitLock) {
86  var tables = StateStore.GetVisibleList();
87 
88  // For each visible table
89  foreach (var resource in tables) {
90  var tableId = resource.TableId;
91  var sourceName = resource.SourceName;
92 
93  // TODO: add a table source type?
94 
95  // Load the master table from the resource information
96  var source = LoadTableSource(tableId, sourceName);
97 
98  if (source == null)
99  throw new InvalidOperationException(String.Format("Table {0} was not found.", sourceName));
100 
101  source.Open();
102 
103  tableSources.Add(tableId, source);
104  }
105  }
106  }
A long string in the system.
Dictionary< int, TableSource > tableSources
TableSource LoadTableSource(int tableId, string tableName)
IEnumerable< TableState > GetVisibleList()
void Deveel.Data.TableSourceComposite.RegisterOnCommit ( Action< TableCommitInfo action)
inlinepackage

Definition at line 645 of file TableSourceComposite.cs.

645  {
646  if (tableCommitCallback == null) {
647  tableCommitCallback = action;
648  } else {
649  tableCommitCallback = (Action<TableCommitInfo>) Delegate.Combine(tableCommitCallback, action);
650  }
651  }
Action< TableCommitInfo > tableCommitCallback
void Deveel.Data.TableSourceComposite.Rollback ( Transaction  transaction,
IList< IMutableTable touchedTables,
TransactionRegistry  journal 
)
inlinepackage

Definition at line 556 of file TableSourceComposite.cs.

556  {
557  // Go through the journal. Any rows added should be marked as deleted
558  // in the respective master table.
559 
560  // Get individual journals for updates made to tables in this
561  // transaction.
562  // The list MasterTableJournal
563  var journalList = new List<TableEventRegistry>();
564  for (int i = 0; i < touchedTables.Count; ++i) {
565  var tableJournal = touchedTables[i].EventRegistry;
566  if (tableJournal.EventCount > 0) // Check the journal has entries.
567  journalList.Add(tableJournal);
568  }
569 
570  var changedTables = journalList.ToArray();
571 
572  lock (commitLock) {
573  try {
574  // For each change to each table,
575  foreach (var changeJournal in changedTables) {
576  // The table the changes were made to.
577  int tableId = changeJournal.TableId;
578  // Get the master table with this table id.
579  var master = GetTableSource(tableId);
580  // Commit the rollback on the table.
581  master.RollbackTransactionChange(changeJournal);
582  }
583  } finally {
584  // Notify the conglomerate that this transaction has closed.
585  CloseTransaction(transaction);
586  }
587  }
588  }
TableSource GetTableSource(int tableId)
void CloseTransaction(ITransaction transaction)
void Deveel.Data.TableSourceComposite.Setup ( )
inlineprivate

Definition at line 192 of file TableSourceComposite.cs.

192  {
193  lock (this) {
194  CurrentCommitId = 0;
195  tableSources = new Dictionary<int, TableSource>();
196  }
197  }
Dictionary< int, TableSource > tableSources
void Deveel.Data.TableSourceComposite.UnregisterOnCommit ( Action< TableCommitInfo action)
inlinepackage

Definition at line 653 of file TableSourceComposite.cs.

653  {
654  tableCommitCallback = Delegate.Remove(tableCommitCallback, action) as Action<TableCommitInfo>;
655  }
Action< TableCommitInfo > tableCommitCallback

Member Data Documentation

readonly object Deveel.Data.TableSourceComposite.commitLock = new object()
private

Definition at line 30 of file TableSourceComposite.cs.

IStore Deveel.Data.TableSourceComposite.lobStore
private

Definition at line 36 of file TableSourceComposite.cs.

List<TransactionObjectState> Deveel.Data.TableSourceComposite.objectStates
private

Definition at line 33 of file TableSourceComposite.cs.

const string Deveel.Data.TableSourceComposite.ObjectStoreName = "lob_store"

Definition at line 41 of file TableSourceComposite.cs.

IStore Deveel.Data.TableSourceComposite.stateStore
private

Definition at line 37 of file TableSourceComposite.cs.

const string Deveel.Data.TableSourceComposite.StateStorePostfix = "_sf"
private

Definition at line 39 of file TableSourceComposite.cs.

Action<TableCommitInfo> Deveel.Data.TableSourceComposite.tableCommitCallback
private

Definition at line 643 of file TableSourceComposite.cs.

Dictionary<int, TableSource> Deveel.Data.TableSourceComposite.tableSources
private

Definition at line 31 of file TableSourceComposite.cs.

IStoreSystem Deveel.Data.TableSourceComposite.tempStoreSystem
private

Definition at line 35 of file TableSourceComposite.cs.

Property Documentation

int Deveel.Data.TableSourceComposite.CurrentCommitId
getprivate set

Definition at line 68 of file TableSourceComposite.cs.

Database Deveel.Data.TableSourceComposite.Database
getprivate set

Definition at line 58 of file TableSourceComposite.cs.

IDatabaseContext Deveel.Data.TableSourceComposite.DatabaseContext
get

Definition at line 60 of file TableSourceComposite.cs.

bool Deveel.Data.TableSourceComposite.IsClosed
getprivate

Definition at line 74 of file TableSourceComposite.cs.

bool Deveel.Data.TableSourceComposite.IsReadOnly
getprivate

Definition at line 70 of file TableSourceComposite.cs.

IObjectStore Deveel.Data.TableSourceComposite.LargeObjectStore
getsetprivate

Definition at line 82 of file TableSourceComposite.cs.

TableStateStore Deveel.Data.TableSourceComposite.StateStore
getsetprivate

Definition at line 78 of file TableSourceComposite.cs.

string Deveel.Data.TableSourceComposite.StateStoreName
getsetprivate

Definition at line 80 of file TableSourceComposite.cs.

IStoreSystem Deveel.Data.TableSourceComposite.StoreSystem
getprivate

Definition at line 64 of file TableSourceComposite.cs.


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