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

A default implementation of a sequence manager that is backed by a given transaction. More...

Inheritance diagram for Deveel.Data.Sql.Sequences.SequenceManager:
Deveel.Data.Sql.ISequenceManager Deveel.Data.Sql.IObjectManager

Classes

class  Sequence
 
class  SequenceTable
 
class  SequenceTableContainer
 

Public Member Functions

 SequenceManager (ITransaction transaction)
 Construct a new instance of SequenceManager that is backed by the given transaction factory. More...
 
void Dispose ()
 
void Create ()
 Initializes the manager into the underlying system. More...
 
ISequence CreateSequence (SequenceInfo sequenceInfo)
 
ObjectName ResolveName (ObjectName objName, bool ignoreCase)
 Normalizes the input object name using the case sensitivity specified. More...
 
bool DropSequence (ObjectName sequenceName)
 
bool SequenceExists (ObjectName sequenceName)
 
ISequence GetSequence (ObjectName sequenceName)
 

Properties

DbObjectType IObjectManager. ObjectType [get]
 
ITransaction Transaction [get, set]
 Gets the transaction where the manager is operating. More...
 
ITableContainer TableContainer [get]
 
- Properties inherited from Deveel.Data.Sql.ISequenceManager
ITableContainer TableContainer [get]
 Provides a table container that exposes the sequences managed as tables. More...
 
- Properties inherited from Deveel.Data.Sql.IObjectManager
DbObjectType ObjectType [get]
 Gets the type of objects managed by this instance. More...
 

Private Member Functions

 ~SequenceManager ()
 
void Dispose (bool disposing)
 
void UpdateSequenceState (Sequence sequence)
 Updates the state of the sequence key in the sequence tables in the database. More...
 
void IObjectManager. CreateObject (IObjectInfo objInfo)
 Create a new object of the ObjectType given the specifications given. More...
 
Sequence CreateCustomSequence (ObjectName sequenceName, SequenceInfo sequenceInfo)
 
ISequence CreateNativeTableSequence (ObjectName tableName)
 
bool IObjectManager. AlterObject (IObjectInfo objInfo)
 Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given. More...
 
bool IObjectManager. DropObject (ObjectName objName)
 Deletes a database object handled by this manager from the system. More...
 
bool RemoveNativeTableSequence (ObjectName tableName)
 
bool IObjectManager. ObjectExists (ObjectName objName)
 Checks if an object identified by the given name is managed by this instance. More...
 
bool IObjectManager. RealObjectExists (ObjectName objName)
 Checks if an object really exists in the system. More...
 
SqlNumber NextValue (ObjectName name)
 
SqlNumber SetValue (ObjectName name, SqlNumber value)
 
SqlNumber GetCurrentValue (ObjectName name)
 
IDbObject IObjectManager. GetObject (ObjectName objName)
 Gets a database object managed by this manager. More...
 

Private Attributes

Dictionary< ObjectName, SequencesequenceKeyMap
 

Static Private Attributes

static readonly DataObject OneValue = DataObject.Integer(1)
 A static TObject that represents numeric 1. More...
 

Detailed Description

A default implementation of a sequence manager that is backed by a given transaction.

See also
ISequenceManager

Definition at line 32 of file SequenceManager.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Sequences.SequenceManager.SequenceManager ( ITransaction  transaction)
inline

Construct a new instance of SequenceManager that is backed by the given transaction factory.

Parameters
transaction

Definition at line 45 of file SequenceManager.cs.

45  {
46  Transaction = transaction;
47  sequenceKeyMap = new Dictionary<ObjectName, Sequence>();
48  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
Dictionary< ObjectName, Sequence > sequenceKeyMap
Deveel.Data.Sql.Sequences.SequenceManager.~SequenceManager ( )
inlineprivate

Definition at line 50 of file SequenceManager.cs.

50  {
51  Dispose(false);
52  }

Member Function Documentation

bool IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.AlterObject ( IObjectInfo  objInfo)
inlineprivate

Modifies an existing object managed, identified by IObjectInfo.FullName component of the given specification, with the format given.

Parameters
objInfoThe object specification used to alter an existing object.
Returns
Returns true an object was identified and successfully altered, or false if none database object was found for the unique name given.
Exceptions
ArgumentNullExceptionIf the given objInfo object is null.
ArgumentExceptionIf the type of the object specified (IObjectInfo.ObjectType) is different than the type of objects handled by this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 482 of file SequenceManager.cs.

482  {
483  throw new NotImplementedException();
484  }
void Deveel.Data.Sql.Sequences.SequenceManager.Create ( )
inline

Initializes the manager into the underlying system.

Typically this method generates the tables required to manage the features relative to the objects.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 380 of file SequenceManager.cs.

380  {
381  // SYSTEM.SEQUENCE_INFO
382  var tableInfo = new TableInfo(SystemSchema.SequenceInfoTableName);
383  tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
384  tableInfo.AddColumn("schema", PrimitiveTypes.String());
385  tableInfo.AddColumn("name", PrimitiveTypes.String());
386  tableInfo.AddColumn("type", PrimitiveTypes.Numeric());
387  tableInfo = tableInfo.AsReadOnly();
388  Transaction.CreateTable(tableInfo);
389 
390  // SYSTEM.SEQUENCE
391  tableInfo = new TableInfo(SystemSchema.SequenceTableName);
392  tableInfo.AddColumn("seq_id", PrimitiveTypes.Numeric());
393  tableInfo.AddColumn("last_value", PrimitiveTypes.Numeric());
394  tableInfo.AddColumn("increment", PrimitiveTypes.Numeric());
395  tableInfo.AddColumn("minvalue", PrimitiveTypes.Numeric());
396  tableInfo.AddColumn("maxvalue", PrimitiveTypes.Numeric());
397  tableInfo.AddColumn("start", PrimitiveTypes.Numeric());
398  tableInfo.AddColumn("cache", PrimitiveTypes.Numeric());
399  tableInfo.AddColumn("cycle", PrimitiveTypes.Boolean());
400  tableInfo = tableInfo.AsReadOnly();
401  Transaction.CreateTable(tableInfo);
402  }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
static BooleanType Boolean()
static NumericType Numeric()
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
Sequence Deveel.Data.Sql.Sequences.SequenceManager.CreateCustomSequence ( ObjectName  sequenceName,
SequenceInfo  sequenceInfo 
)
inlineprivate

Definition at line 433 of file SequenceManager.cs.

433  {
434  // The SEQUENCE and SEQUENCE_INFO table
435  var seq = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
436  var seqi = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);
437 
438  var list = seqi.SelectRowsEqual(2, DataObject.VarChar(sequenceName.Name), 1, DataObject.VarChar(sequenceName.Parent.FullName));
439  if (list.Any())
440  throw new Exception(String.Format("Sequence generator with name '{0}' already exists.", sequenceName));
441 
442  // Generate a unique id for the sequence info table
443  var uniqueId = Transaction.NextTableId(SystemSchema.SequenceInfoTableName);
444 
445  // Insert the new row
446  var dataRow = seqi.NewRow();
447  dataRow.SetValue(0, DataObject.Number(uniqueId));
448  dataRow.SetValue(1, DataObject.VarChar(sequenceName.Parent.FullName));
449  dataRow.SetValue(2, DataObject.VarChar(sequenceName.Name));
450  dataRow.SetValue(3, DataObject.BigInt(2));
451  seqi.AddRow(dataRow);
452 
453  // Insert into the SEQUENCE table.
454  dataRow = seq.NewRow();
455  dataRow.SetValue(0, DataObject.Number(uniqueId));
456  dataRow.SetValue(1, DataObject.Number(sequenceInfo.StartValue));
457  dataRow.SetValue(2, DataObject.Number(sequenceInfo.Increment));
458  dataRow.SetValue(3, DataObject.Number(sequenceInfo.MinValue));
459  dataRow.SetValue(4, DataObject.Number(sequenceInfo.MaxValue));
460  dataRow.SetValue(5, DataObject.Number(sequenceInfo.StartValue));
461  dataRow.SetValue(6, DataObject.BigInt(sequenceInfo.Cache));
462  dataRow.SetValue(7, DataObject.Boolean(sequenceInfo.Cycle));
463  seq.AddRow(dataRow);
464 
465  return new Sequence(this, uniqueId, sequenceInfo);
466  }
A long string in the system.
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
ISequence Deveel.Data.Sql.Sequences.SequenceManager.CreateNativeTableSequence ( ObjectName  tableName)
inlineprivate

Definition at line 468 of file SequenceManager.cs.

468  {
469  var table = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);
470  var uniqueId = Transaction.NextTableId(SystemSchema.SequenceInfoTableName);
471 
472  var dataRow = table.NewRow();
473  dataRow.SetValue(0, DataObject.Number(uniqueId));
474  dataRow.SetValue(1, DataObject.VarChar(tableName.Parent.FullName));
475  dataRow.SetValue(2, DataObject.VarChar(tableName.Name));
476  dataRow.SetValue(3, DataObject.BigInt(1));
477  table.AddRow(dataRow);
478 
479  return new Sequence(this, uniqueId, SequenceInfo.Native(tableName));
480  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
void IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.CreateObject ( IObjectInfo  objInfo)
inlineprivate

Create a new object of the ObjectType given the specifications given.

Parameters
objInfoThe object specifications used to create a new object.
Exceptions
ArgumentNullExceptionIf the given objInfo is null.
ArgumentExceptionIf the object type of the specification (IObjectInfo.ObjectType) is different than the ObjectType of this manager.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 404 of file SequenceManager.cs.

404  {
405  var seqInfo = objInfo as SequenceInfo;
406  if (seqInfo == null)
407  throw new ArgumentException();
408 
409  CreateSequence(seqInfo);
410  }
ISequence CreateSequence(SequenceInfo sequenceInfo)
ISequence Deveel.Data.Sql.Sequences.SequenceManager.CreateSequence ( SequenceInfo  sequenceInfo)
inline

Definition at line 412 of file SequenceManager.cs.

412  {
413  if (sequenceInfo == null)
414  throw new ArgumentNullException("sequenceInfo");
415 
416  var sequenceName = sequenceInfo.SequenceName;
417 
418  // If the Sequence or SequenceInfo tables don't exist then
419  // We can't add or remove native tables
420  if (sequenceName.Equals(SystemSchema.SequenceTableName) ||
421  sequenceName.Equals(SystemSchema.SequenceInfoTableName) ||
422  !Transaction.TableExists(SystemSchema.SequenceTableName) ||
423  !Transaction.TableExists(SystemSchema.SequenceInfoTableName)) {
424  return null;
425  }
426 
427  if (sequenceInfo.Type == SequenceType.Native)
428  return CreateNativeTableSequence(sequenceName);
429 
430  return CreateCustomSequence(sequenceName, sequenceInfo);
431  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
Sequence CreateCustomSequence(ObjectName sequenceName, SequenceInfo sequenceInfo)
ISequence CreateNativeTableSequence(ObjectName tableName)
SequenceType
The form of a ISequence object in a transaction.
Definition: SequenceType.cs:26
void Deveel.Data.Sql.Sequences.SequenceManager.Dispose ( bool  disposing)
inlineprivate

Definition at line 58 of file SequenceManager.cs.

58  {
59  if (disposing) {
60  if (sequenceKeyMap !=null)
61  sequenceKeyMap.Clear();
62 
63  sequenceKeyMap = null;
64  }
65  }
Dictionary< ObjectName, Sequence > sequenceKeyMap
void Deveel.Data.Sql.Sequences.SequenceManager.Dispose ( )
inline

Definition at line 67 of file SequenceManager.cs.

67  {
68  Dispose(true);
69  GC.SuppressFinalize(this);
70  }
bool IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.DropObject ( ObjectName  objName)
inlineprivate

Deletes a database object handled by this manager from the system.

Parameters
objNameThe unique name of the object to be deleted.
Returns
Returns true if a database object was found with the given unique name and successfully deleted from the system, or false if none object was found.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 486 of file SequenceManager.cs.

486  {
487  return DropSequence(objName);
488  }
bool DropSequence(ObjectName sequenceName)
bool Deveel.Data.Sql.Sequences.SequenceManager.DropSequence ( ObjectName  sequenceName)
inline

Definition at line 494 of file SequenceManager.cs.

494  {
495  // If the Sequence or SequenceInfo tables don't exist then
496  // we can't create the sequence sequence
497  if (!Transaction.ObjectExists(SystemSchema.SequenceTableName) ||
498  !Transaction.ObjectExists(SystemSchema.SequenceInfoTableName)) {
499  throw new Exception("System sequence tables do not exist.");
500  }
501 
502  // Remove the table sequence (delete SEQUENCE_INFO and SEQUENCE entry)
503  return RemoveNativeTableSequence(sequenceName);
504  }
bool RemoveNativeTableSequence(ObjectName tableName)
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
SqlNumber Deveel.Data.Sql.Sequences.SequenceManager.GetCurrentValue ( ObjectName  name)
inlineprivate

Definition at line 610 of file SequenceManager.cs.

610  {
611  lock (this) {
612  var sequence = (Sequence) GetSequence(name);
613 
614  if (sequence.SequenceInfo.Type == SequenceType.Native)
615  return Transaction.NextTableId(name);
616 
617  // Custom sequence generator
618  return sequence.CurrentValue;
619  }
620  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ISequence GetSequence(ObjectName sequenceName)
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
SequenceType
The form of a ISequence object in a transaction.
Definition: SequenceType.cs:26
IDbObject IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.GetObject ( ObjectName  objName)
inlineprivate

Gets a database object managed by this manager.

Parameters
objNameThe name that uniquely identifies the object to get.
Returns
Returns a IDbObject instance that is identified by the given unique name, or null if this manager was not able to map any object to the name specified.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 622 of file SequenceManager.cs.

622  {
623  return GetSequence(objName);
624  }
ISequence GetSequence(ObjectName sequenceName)
ISequence Deveel.Data.Sql.Sequences.SequenceManager.GetSequence ( ObjectName  sequenceName)
inline

Definition at line 626 of file SequenceManager.cs.

626  {
627  // Is the generator already in the cache?
628  Sequence sequence;
629 
630  if (!sequenceKeyMap.TryGetValue(sequenceName, out sequence)) {
631  // This sequence generator is not in the cache so we need to query the
632  // sequence table for this.
633  var seqi = Transaction.GetTable(SystemSchema.SequenceInfoTableName);
634 
635  var schemaVal = DataObject.VarChar(sequenceName.Parent.FullName);
636  var nameVal = DataObject.VarChar(sequenceName.Name);
637  var list = seqi.SelectRowsEqual(2, nameVal, 1, schemaVal).ToList();
638 
639  if (list.Count == 0) {
640  throw new ArgumentException(String.Format("Sequence '{0}' not found.", sequenceName));
641  } else if (list.Count() > 1) {
642  throw new Exception("Assert failed: multiple sequence keys with same name.");
643  }
644 
645  int rowIndex = list.First();
646  var sid = seqi.GetValue(rowIndex, 0);
647  var sschema = seqi.GetValue(rowIndex, 1);
648  var sname = seqi.GetValue(rowIndex, 2);
649  var stype = seqi.GetValue(rowIndex, 3);
650 
651  // Is this a custom sequence generator?
652  // (stype == 1) == true
653  if (stype.IsEqualTo(OneValue)) {
654  // Native generator.
655  sequence = new Sequence(this, (SqlNumber) sid.Value, SequenceInfo.Native(sequenceName));
656  } else {
657  // Query the sequence table.
658  var seq = Transaction.GetTable(SystemSchema.SequenceTableName);
659 
660  list = seq.SelectRowsEqual(0, sid).ToList();
661 
662  if (!list.Any())
663  throw new Exception("Sequence table does not contain sequence information.");
664  if (list.Count() > 1)
665  throw new Exception("Sequence table contains multiple generators for id.");
666 
667  rowIndex = list.First();
668  var lastValue = (SqlNumber) seq.GetValue(rowIndex, 1).Value;
669  var increment = (SqlNumber) seq.GetValue(rowIndex, 2).Value;
670  var minvalue = (SqlNumber) seq.GetValue(rowIndex, 3).Value;
671  var maxvalue = (SqlNumber) seq.GetValue(rowIndex, 4).Value;
672  var start = (SqlNumber) seq.GetValue(rowIndex, 5).Value;
673  var cache = (long) seq.GetValue(rowIndex, 6).AsBigInt();
674  bool cycle = seq.GetValue(rowIndex, 7).AsBoolean();
675 
676  var info = new SequenceInfo(sequenceName, start, increment, minvalue, maxvalue, cache, cycle);
677  sequence = new Sequence(this, (SqlNumber) sid.Value, lastValue, info);
678 
679  // Put the generator in the cache
680  sequenceKeyMap[sequenceName] = sequence;
681  }
682 
683  }
684 
685  // Return the generator
686  return sequence;
687 
688  }
A long string in the system.
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
Dictionary< ObjectName, Sequence > sequenceKeyMap
static readonly DataObject OneValue
A static TObject that represents numeric 1.
SqlNumber Deveel.Data.Sql.Sequences.SequenceManager.NextValue ( ObjectName  name)
inlineprivate

Definition at line 562 of file SequenceManager.cs.

562  {
563  lock (this) {
564  var sequence = (Sequence)GetSequence(name);
565 
566  if (sequence.SequenceInfo.Type == SequenceType.Native)
567  // Native generator
568  return Transaction.NextTableId(name);
569 
570  // Custom sequence generator
571  var currentVal = sequence.CurrentValue;
572 
573  // Increment the current value.
574  sequence.IncrementCurrentValue();
575 
576  // Have we reached the current cached point?
577  if (currentVal == sequence.LastValue) {
578  // Increment the generator
579  for (int i = 0; i < sequence.SequenceInfo.Cache; ++i) {
580  sequence.IncrementLastValue();
581  }
582 
583  // Update the state
584  UpdateSequenceState(sequence);
585 
586  }
587 
588  return sequence.CurrentValue;
589  }
590  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ISequence GetSequence(ObjectName sequenceName)
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
void UpdateSequenceState(Sequence sequence)
Updates the state of the sequence key in the sequence tables in the database.
SequenceType
The form of a ISequence object in a transaction.
Definition: SequenceType.cs:26
bool IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.ObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object identified by the given name is managed by this instance.

Parameters
objNameThe name that uniquely identifies the object.
Returns

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 538 of file SequenceManager.cs.

538  {
539  return SequenceExists(objName);
540  }
bool SequenceExists(ObjectName sequenceName)
bool IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.RealObjectExists ( ObjectName  objName)
inlineprivate

Checks if an object really exists in the system.

Parameters
objNameThe unique name of the object to check.
Returns
Returns true if an object with the given name concretely exists in the system, or false otherwise.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 542 of file SequenceManager.cs.

542  {
543  return SequenceExists(objName);
544  }
bool SequenceExists(ObjectName sequenceName)
bool Deveel.Data.Sql.Sequences.SequenceManager.RemoveNativeTableSequence ( ObjectName  tableName)
inlineprivate

Definition at line 506 of file SequenceManager.cs.

506  {
507  // If the Sequence or SequenceInfo tables don't exist then
508  // We can't add or remove native tables
509  if (tableName.Equals(SystemSchema.SequenceTableName) ||
510  tableName.Equals(SystemSchema.SequenceInfoTableName) ||
511  !Transaction.ObjectExists(SystemSchema.SequenceTableName) ||
512  !Transaction.ObjectExists(SystemSchema.SequenceInfoTableName)) {
513  return false;
514  }
515 
516  // The SEQUENCE and SEQUENCE_INFO table
517  var seq = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
518  var seqi = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);
519 
520  var list = seqi.SelectRowsEqual(2, DataObject.VarChar(tableName.Name), 1, DataObject.VarChar(tableName.Parent.FullName));
521 
522  // Remove the corresponding entry in the SEQUENCE table
523  foreach (var rowIndex in list) {
524  var sid = seqi.GetValue(rowIndex, 0);
525  var list2 = seq.SelectRowsEqual(0, sid);
526  foreach (int rowIndex2 in list2) {
527  // Remove entry from the sequence table.
528  seq.RemoveRow(rowIndex2);
529  }
530 
531  // Remove entry from the sequence info table
532  seqi.RemoveRow(rowIndex);
533  }
534 
535  return true;
536  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ObjectName Deveel.Data.Sql.Sequences.SequenceManager.ResolveName ( ObjectName  objName,
bool  ignoreCase 
)
inline

Normalizes the input object name using the case sensitivity specified.

Parameters
objNameThe input object name, that can be partial or complete, to be normalized to the real name of an object.
ignoreCaseThe case sensitivity specification used to compare the input name with the names of the existing objects handled by this manager.
Returns
Returns the fully normalized ObjectName that is the real name of an object matching the input name, or null if the input name was not possible to be resolved.

Implements Deveel.Data.Sql.IObjectManager.

Definition at line 490 of file SequenceManager.cs.

490  {
491  throw new NotImplementedException();
492  }
bool Deveel.Data.Sql.Sequences.SequenceManager.SequenceExists ( ObjectName  sequenceName)
inline

Definition at line 546 of file SequenceManager.cs.

546  {
547  // If the Sequence or SequenceInfo tables don't exist then
548  // we can't create the sequence generator
549  if (!Transaction.TableExists(SystemSchema.SequenceTableName) ||
550  !Transaction.TableExists(SystemSchema.SequenceInfoTableName)) {
551  throw new Exception("System sequence tables do not exist.");
552  }
553 
554  // The SEQUENCE and SEQUENCE_INFO table
555  var seq = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
556  var seqi = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);
557 
558  return seqi.SelectRowsEqual(2, DataObject.VarChar(sequenceName.Parent.FullName), 1, DataObject.VarChar(sequenceName.Name)).Any();
559  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
SqlNumber Deveel.Data.Sql.Sequences.SequenceManager.SetValue ( ObjectName  name,
SqlNumber  value 
)
inlineprivate

Definition at line 592 of file SequenceManager.cs.

592  {
593  lock (this) {
594  var sequence = (Sequence) GetSequence(name);
595 
596  if (sequence.SequenceInfo.Type == SequenceType.Native)
597  return Transaction.SetTableId(name, value);
598 
599  // Custom sequence generator
600  sequence.CurrentValue = value;
601  sequence.LastValue = value;
602 
603  // Update the state
604  UpdateSequenceState(sequence);
605 
606  return value;
607  }
608  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35
ISequence GetSequence(ObjectName sequenceName)
A SEQUENCE of numeric values that can be native or user-defined with given configuration.
void UpdateSequenceState(Sequence sequence)
Updates the state of the sequence key in the sequence tables in the database.
SequenceType
The form of a ISequence object in a transaction.
Definition: SequenceType.cs:26
void Deveel.Data.Sql.Sequences.SequenceManager.UpdateSequenceState ( Sequence  sequence)
inlineprivate

Updates the state of the sequence key in the sequence tables in the database.

Parameters
sequence

The update occurs on an independent transaction.

Definition at line 346 of file SequenceManager.cs.

346  {
347  // We need to update the sequence key state.
348 
349  // The sequence table
350  var seq = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
351 
352  // Find the row with the id for this sequence.
353  var list = seq.SelectRowsEqual(0, DataObject.Number(sequence.Id)).ToList();
354 
355  // Checks
356  var count = list.Count();
357  if (count == 0)
358  throw new ObjectNotFoundException(sequence.FullName);
359 
360  if (count > 1)
361  throw new Exception("Assert failed: multiple id for sequence.");
362 
363  // Create the DataRow
364  var dataRow = seq.GetRow(list.First());
365 
366  // Set the content of the row data
367  dataRow.SetValue(0, DataObject.Number(sequence.Id));
368  dataRow.SetValue(1, DataObject.Number(sequence.LastValue));
369  dataRow.SetValue(2, DataObject.Number(sequence.SequenceInfo.Increment));
370  dataRow.SetValue(3, DataObject.Number(sequence.SequenceInfo.MinValue));
371  dataRow.SetValue(4, DataObject.Number(sequence.SequenceInfo.MaxValue));
372  dataRow.SetValue(5, DataObject.Number(sequence.SequenceInfo.StartValue));
373  dataRow.SetValue(6, DataObject.BigInt(sequence.SequenceInfo.Cache));
374  dataRow.SetValue(7, DataObject.Boolean(sequence.SequenceInfo.Cycle));
375 
376  // Update the row
377  seq.UpdateRow(dataRow);
378  }
The system implementation of a transaction model that handles isolated operations within a database c...
Definition: Transaction.cs:35

Member Data Documentation

readonly DataObject Deveel.Data.Sql.Sequences.SequenceManager.OneValue = DataObject.Integer(1)
staticprivate

A static TObject that represents numeric 1.

Definition at line 36 of file SequenceManager.cs.

Dictionary<ObjectName, Sequence> Deveel.Data.Sql.Sequences.SequenceManager.sequenceKeyMap
private

Definition at line 38 of file SequenceManager.cs.

Property Documentation

DbObjectType IObjectManager. Deveel.Data.Sql.Sequences.SequenceManager.ObjectType
getprivate

Definition at line 54 of file SequenceManager.cs.

ITableContainer Deveel.Data.Sql.Sequences.SequenceManager.TableContainer
get

Definition at line 77 of file SequenceManager.cs.

ITransaction Deveel.Data.Sql.Sequences.SequenceManager.Transaction
getsetprivate

Gets the transaction where the manager is operating.

Definition at line 75 of file SequenceManager.cs.


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