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

Public Member Functions

 SequenceTableContainer (SequenceManager manager)
 
int FindByName (ObjectName tableName)
 Finds the index in this container of the given table by its name. More...
 
ObjectName GetTableName (int offset)
 Gets the name of the table at the given index in this container. More...
 
TableInfo GetTableInfo (int offset)
 Gets the information of the table at the given offset in this container. More...
 
string GetTableType (int offset)
 Gets the type of the table at the given offset. More...
 
bool ContainsTable (ObjectName name)
 Checks if a table with the given name is contained in the current context. More...
 
ITable GetTable (int offset)
 Gets the table contained at the given offset within the context. More...
 

Properties

int TableCount [get]
 
- Properties inherited from Deveel.Data.Sql.Tables.ITableContainer
int TableCount [get]
 Returns the total count of tables that this object is maintaining. More...
 

Static Private Member Functions

static TableInfo CreateTableInfo (ObjectName schema, string name)
 

Private Attributes

readonly ITransaction transaction
 
readonly SequenceManager manager
 

Detailed Description

Definition at line 83 of file SequenceManager.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.SequenceTableContainer ( SequenceManager  manager)
inline

Definition at line 87 of file SequenceManager.cs.

87  {
89  this.manager = manager;
90  }
ITransaction Transaction
Gets the transaction where the manager is operating.

Member Function Documentation

bool Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.ContainsTable ( ObjectName  name)
inline

Checks if a table with the given name is contained in the current context.

Parameters
nameThe name of the table to search.
Returns
Returns true if any table with the given name was found in the container, false otherwise.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 178 of file SequenceManager.cs.

178  {
179  var seqInfo = SystemSchema.SequenceInfoTableName;
180 
181  // This set can not contain the table that is backing it, so we always
182  // return false for that. This check stops an annoying recursive
183  // situation for table name resolution.
184  if (name.Equals(seqInfo))
185  return false;
186 
187  return FindByName(name) != -1;
188  }
int FindByName(ObjectName tableName)
Finds the index in this container of the given table by its name.
static TableInfo Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.CreateTableInfo ( ObjectName  schema,
string  name 
)
inlinestaticprivate

Definition at line 99 of file SequenceManager.cs.

99  {
100  var info = new TableInfo(new ObjectName(schema, name));
101  info.AddColumn("last_value", PrimitiveTypes.Numeric());
102  info.AddColumn("current_value", PrimitiveTypes.Numeric());
103  info.AddColumn("top_value", PrimitiveTypes.Numeric());
104  info.AddColumn("increment_by", PrimitiveTypes.Numeric());
105  info.AddColumn("min_value", PrimitiveTypes.Numeric());
106  info.AddColumn("max_value", PrimitiveTypes.Numeric());
107  info.AddColumn("start", PrimitiveTypes.Numeric());
108  info.AddColumn("cache", PrimitiveTypes.Numeric());
109  info.AddColumn("cycle", PrimitiveTypes.Boolean());
110  info = info.AsReadOnly();
111  return info;
112  }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static BooleanType Boolean()
static NumericType Numeric()
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
int Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.FindByName ( ObjectName  name)
inline

Finds the index in this container of the given table by its name.

Parameters
nameThe name of the table to find.
Returns
Returns a zero-based index that represents the offset of the table identified by the given name within the context, ot -1 of not found.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 114 of file SequenceManager.cs.

114  {
115  if (tableName == null)
116  throw new ArgumentNullException("tableName");
117 
118  if (tableName.Parent == null)
119  return -1;
120 
121  var seqInfo = SystemSchema.SequenceInfoTableName;
122  if (transaction.RealTableExists(seqInfo)) {
123  // Search the table.
124  var table = transaction.GetTable(seqInfo);
125  var name = DataObject.VarChar(tableName.Name);
126  var schema = DataObject.VarChar(tableName.Parent.FullName);
127 
128  int p = 0;
129  foreach (var row in table) {
130  var seqType = row.GetValue(3);
131  if (!seqType.IsEqualTo(OneValue)) {
132  var obName = row.GetValue(2);
133  if (obName.IsEqualTo(name)) {
134  var obSchema = row.GetValue(1);
135  if (obSchema.IsEqualTo(schema)) {
136  // Match so return this
137  return p;
138  }
139  }
140  ++p;
141  }
142  }
143  }
144 
145  return -1;
146  }
static readonly DataObject OneValue
A static TObject that represents numeric 1.
ITable Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.GetTable ( int  offset)
inline

Gets the table contained at the given offset within the context.

Parameters
offsetThe zero-based offset of the table to return.
Returns
Returns an instance of ITable that provides access to the backed informaion for an object provided by the context.
Exceptions
ArgumentOutOfRangeExceptionIf the given offset is smaller than 0 or greater or equal than TableCount.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 190 of file SequenceManager.cs.

190  {
191  var table = transaction.GetTable(SystemSchema.SequenceInfoTableName);
192  int p = 0;
193  int rowIndex = -1;
194 
195  foreach (var row in table) {
196  var seqType = row.GetValue(3);
197  if (seqType.IsEqualTo(OneValue)) {
198  if (p == offset) {
199  rowIndex = row.RowId.RowNumber;
200  break;
201  }
202 
203  p++;
204  }
205  }
206 
207  if (rowIndex == -1)
208  throw new ArgumentOutOfRangeException("offset");
209 
210  var seqId = table.GetValue(rowIndex, 0);
211  var schema = ObjectName.Parse(table.GetValue(rowIndex, 1).Value.ToString());
212  var name = table.GetValue(rowIndex, 2).Value.ToString();
213 
214  var tableName = new ObjectName(schema, name);
215 
216  // Find this id in the 'sequence' table
217  var seqTable = transaction.GetTable(SystemSchema.SequenceTableName);
218 
219  var index = seqTable.GetIndex(0);
220  var list = index.SelectEqual(seqId);
221 
222  if (!list.Any())
223  throw new Exception("No SEQUENCE table entry for sequence.");
224 
225  int seqRowI = list.First();
226 
227  // Generate the DataTableInfo
228  var tableInfo = CreateTableInfo(schema, name);
229 
230  // Last value for this sequence generated by the transaction
231  DataObject lastValue;
232  try {
233  var sequence = manager.GetSequence(tableName);
234  if (sequence == null)
235  throw new ObjectNotFoundException(tableName);
236 
237  lastValue = DataObject.Number(sequence.GetCurrentValue());
238  } catch (Exception) {
239  lastValue = DataObject.BigInt(-1);
240  }
241 
242  // The current value of the sequence generator
243  var currentValue = DataObject.Number(manager.GetCurrentValue(tableName));
244 
245  // Read the rest of the values from the SEQUENCE table.
246  var topValue = seqTable.GetValue(seqRowI, 1);
247  var incrementBy = seqTable.GetValue(seqRowI, 2);
248  var minValue = seqTable.GetValue(seqRowI, 3);
249  var maxValue = seqTable.GetValue(seqRowI, 4);
250  var start = seqTable.GetValue(seqRowI, 5);
251  var cache = seqTable.GetValue(seqRowI, 6);
252  var cycle = seqTable.GetValue(seqRowI, 7);
253 
254 
255  return new SequenceTable(transaction.Database.Context, tableInfo) {
256  TopValue = topValue,
257  LastValue = lastValue,
258  CurrentValue = currentValue,
259  Increment = incrementBy,
260  MinValue = minValue,
261  MaxValue = maxValue,
262  Start = start,
263  Cache = cache,
264  Cycle = cycle
265  };
266  }
SqlNumber GetCurrentValue(ObjectName name)
static TableInfo CreateTableInfo(ObjectName schema, string name)
IDatabase Database
Gets the database this transaction belongs to.
Definition: ITransaction.cs:48
ISequence GetSequence(ObjectName sequenceName)
new IDatabaseContext Context
Gets the context that contains this database.
Definition: IDatabase.cs:50
The offset of the last value of the range.
static readonly DataObject OneValue
A static TObject that represents numeric 1.
TableInfo Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.GetTableInfo ( int  offset)
inline

Gets the information of the table at the given offset in this container.

Parameters
offsetThe zero-based offset of the table whose information to return.
Returns
Returns an instance of
See also
TableInfo
that describes the metadata of a table at the given offset within the context.
Exceptions
ArgumentOutOfRangeExceptionIf the given offset is smaller than 0 or greater or equal than TableCount.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 169 of file SequenceManager.cs.

169  {
170  var tableName = GetTableName(offset);
171  return CreateTableInfo(tableName.Parent, tableName.Name);
172  }
static TableInfo CreateTableInfo(ObjectName schema, string name)
ObjectName GetTableName(int offset)
Gets the name of the table at the given index in this container.
ObjectName Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.GetTableName ( int  offset)
inline

Gets the name of the table at the given index in this container.

Parameters
offsetThe zero-based offset of the table whose name to return.
Returns
Returns a
See also
ObjectName
that identifies the table.
Exceptions
ArgumentOutOfRangeExceptionIf the given offset is smaller than 0 or greater or equal than TableCount.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 148 of file SequenceManager.cs.

148  {
149  var seqInfo = SystemSchema.SequenceInfoTableName;
150  if (transaction.RealTableExists(seqInfo)) {
151  var table = transaction.GetTable(seqInfo);
152  int p = 0;
153  foreach (var row in table) {
154  var seqType = row.GetValue(3);
155  if (!seqType.IsEqualTo(OneValue)) {
156  if (offset == p) {
157  var obSchema = row.GetValue(1);
158  var obName = row.GetValue(2);
159  return new ObjectName(ObjectName.Parse(obSchema.Value.ToString()), obName.Value.ToString());
160  }
161  ++p;
162  }
163  }
164  }
165 
166  throw new ArgumentOutOfRangeException("offset");
167  }
static readonly DataObject OneValue
A static TObject that represents numeric 1.
string Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.GetTableType ( int  offset)
inline

Gets the type of the table at the given offset.

Parameters
offsetThe zero-based offset of the table whose type to return.
Returns
Returns a String that describes the type of table at the given offset.
Exceptions
ArgumentOutOfRangeExceptionIf the given offset is smaller than 0 or greater or equal than TableCount.

Implements Deveel.Data.Sql.Tables.ITableContainer.

Definition at line 174 of file SequenceManager.cs.

174  {
175  return TableTypes.Sequence;
176  }

Member Data Documentation

readonly SequenceManager Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.manager
private

Definition at line 85 of file SequenceManager.cs.

readonly ITransaction Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.transaction
private

Definition at line 84 of file SequenceManager.cs.

Property Documentation

int Deveel.Data.Sql.Sequences.SequenceManager.SequenceTableContainer.TableCount
get

Definition at line 92 of file SequenceManager.cs.


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