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

Defines the metadata properties of a table existing within a database. More...

Inheritance diagram for Deveel.Data.Sql.Tables.TableInfo:
Deveel.Data.Sql.IObjectInfo Deveel.Data.Serialization.ISerializable

Classes

class  ColumnsResolver
 

Public Member Functions

 TableInfo (ObjectName tableName)
 Constructs the object with the given table name. More...
 
void Establish (int id)
 
void AddColumn (ColumnInfo column)
 Adds a new column to the table at the last position of the columns list in the table metadata. More...
 
ColumnInfo AddColumn (string columnName, SqlType columnType)
 Adds a new column to the table having the given name and type. More...
 
ColumnInfo AddColumn (string columnName, SqlType columnType, bool notNull)
 Adds a new column to the table having the given name and type. More...
 
IEnumerator< ColumnInfoGetEnumerator ()
 
int IndexOfColumn (string columnName)
 Gets the offset of the column with the given name. More...
 
int IndexOfColumn (ObjectName columnName)
 
TableInfo AsReadOnly ()
 Creates a new instance of TableInfo as an immutable copy of this table metadata. More...
 
TableInfo Alias (ObjectName alias)
 
IEnumerable< int > IndexOfColumns (IEnumerable< string > columnNames)
 

Static Public Member Functions

static void Serialize (TableInfo tableInfo, Stream stream)
 
static void Serialize (TableInfo tableInfo, BinaryWriter writer)
 
static TableInfo Deserialize (Stream stream, ITypeResolver typeResolver)
 
static TableInfo Deserialize (BinaryReader reader, ITypeResolver typeResolver)
 

Package Functions

void AddColumnSafe (ColumnInfo column)
 
SqlExpression ResolveColumns (bool ignoreCase, SqlExpression expression)
 

Properties

DbObjectType IObjectInfo. ObjectType [get]
 
ObjectName TableName [get, private set]
 Gets the fully qualified name of the table that is ensured to be unique within the system. More...
 
ObjectName IObjectInfo. FullName [get]
 
int Id [get, private set]
 Gets a unique identifier of the table in a database system. More...
 
bool IsPermanent [get, private set]
 Gets a value that indicates if the table is permanent. More...
 
string Name [get]
 Gets the name part of the table name. More...
 
ObjectName SchemaName [get]
 Gets the schema name part of the table name. More...
 
string CatalogName [get]
 Gets the name of the catalog containing the table, if defined. More...
 
bool IsReadOnly [get, private set]
 Gets a boolean value that indicates if the structure of this table cannot be altered. More...
 
int ColumnCount [get]
 Gets a count of the columns defined by this object. More...
 
ColumnInfo this[int offset] [get]
 Gets the column object defined at the given offset within the table. More...
 
- Properties inherited from Deveel.Data.Sql.IObjectInfo
DbObjectType ObjectType [get]
 
ObjectName FullName [get]
 

Private Member Functions

 TableInfo (ObjectName tableName, int id, bool perm, IList< ColumnInfo > columns, bool isReadOnly)
 
 TableInfo (ObjectData data)
 
void AssertNotReadOnly ()
 
void ISerializable. GetData (SerializeData data)
 
IEnumerator IEnumerable. GetEnumerator ()
 

Private Attributes

readonly IList< ColumnInfocolumns
 
readonly Dictionary< ObjectName, int > columnsCache
 

Detailed Description

Defines the metadata properties of a table existing within a database.

A table structure implements a unique name within a database system, and a list columns that shape the design of the data that the table can accommodate.

Definition at line 41 of file TableInfo.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Tables.TableInfo.TableInfo ( ObjectName  tableName)
inline

Constructs the object with the given table name.

Parameters
tableNameThe unique name of the table within the database system.
idThe unique identifier of the table in the database.
Exceptions
ArgumentNullExceptionIf the provided tableName is null.

Definition at line 54 of file TableInfo.cs.

55  : this(tableName, -1, false, new List<ColumnInfo>(), false) {
56  }
Deveel.Data.Sql.Tables.TableInfo.TableInfo ( ObjectName  tableName,
int  id,
bool  perm,
IList< ColumnInfo columns,
bool  isReadOnly 
)
inlineprivate

Definition at line 58 of file TableInfo.cs.

58  {
59  if (tableName == null)
60  throw new ArgumentNullException("tableName");
61 
62  TableName = tableName;
63  Id = id;
64  IsPermanent = perm;
65  this.columns = columns;
66  IsReadOnly = isReadOnly;
67 
68  columnsCache = new Dictionary<ObjectName, int>();
69  }
readonly Dictionary< ObjectName, int > columnsCache
Definition: TableInfo.cs:43
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
bool IsReadOnly
Gets a boolean value that indicates if the structure of this table cannot be altered.
Definition: TableInfo.cs:153
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113
Deveel.Data.Sql.Tables.TableInfo.TableInfo ( ObjectData  data)
inlineprivate

Definition at line 71 of file TableInfo.cs.

71  {
72  TableName = data.GetValue<ObjectName>("TableName");
73  Id = data.GetInt32("TableId");
74  IsPermanent = data.GetBoolean("Permanent");
75  IsReadOnly = data.GetBoolean("ReaDOnly");
76 
77  columns = new List<ColumnInfo>();
78  var columnInfo = data.GetValue<ColumnInfo[]>("Columns");
79  if (columnInfo != null) {
80  foreach (var info in columnInfo) {
81  info.TableInfo = this;
82  columns.Add(info);
83  }
84  }
85 
86  columnsCache = new Dictionary<ObjectName, int>();
87  }
readonly Dictionary< ObjectName, int > columnsCache
Definition: TableInfo.cs:43
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
bool IsReadOnly
Gets a boolean value that indicates if the structure of this table cannot be altered.
Definition: TableInfo.cs:153
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113

Member Function Documentation

void Deveel.Data.Sql.Tables.TableInfo.AddColumn ( ColumnInfo  column)
inline

Adds a new column to the table at the last position of the columns list in the table metadata.

Parameters
columnThe ColumnInfo metadata to add to the table.
Exceptions
ArgumentNullExceptionIf the given column is null.
InvalidOperationExceptionIf the table is immutable (IsReadOnly is equals to true)
ArgumentExceptionIf the column is already defined in this table or if it is attacted to another table.

Definition at line 230 of file TableInfo.cs.

230  {
231  if (column == null)
232  throw new ArgumentNullException("column");
233 
235 
236  if (column.TableInfo != null &&
237  column.TableInfo != this)
238  throw new ArgumentException(String.Format("The column {0} belongs to another table already ({1})", column.ColumnName,
239  column.TableInfo.Name));
240 
241  if (columns.Any(x => x.ColumnName == column.ColumnName))
242  throw new ArgumentException(String.Format("Column {0} is already defined in table {1}", column.ColumnName, TableName));
243 
244  columnsCache.Clear();
245  column.TableInfo = this;
246  columns.Add(column);
247  }
readonly Dictionary< ObjectName, int > columnsCache
Definition: TableInfo.cs:43
A long string in the system.
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
ColumnInfo Deveel.Data.Sql.Tables.TableInfo.AddColumn ( string  columnName,
SqlType  columnType 
)
inline

Adds a new column to the table having the given name and type.

Parameters
columnNameThe name of the column to add.
columnTypeThe SqlType of the column to add.
Returns
Returns an instance of ColumnInfo that is generated by the given parameters.
See also
AddColumn(string, SqlType, bool)

Definition at line 259 of file TableInfo.cs.

259  {
260  return AddColumn(columnName, columnType, false);
261  }
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
Definition: TableInfo.cs:230
ColumnInfo Deveel.Data.Sql.Tables.TableInfo.AddColumn ( string  columnName,
SqlType  columnType,
bool  notNull 
)
inline

Adds a new column to the table having the given name and type.

Parameters
columnNameThe name of the column to add.
columnTypeThe SqlType of the column to add.
notNullIf the column values must be NOT NULL.
Returns
Returns an instance of ColumnInfo that is generated by the given parameters.
See also
AddColumn(string, SqlType, bool), AddColumn(ColumnInfo)
Exceptions
ArgumentNullExceptionIf either columnName or the columnType arguments are null.

Definition at line 279 of file TableInfo.cs.

279  {
280  if (String.IsNullOrEmpty(columnName))
281  throw new ArgumentNullException("columnName");
282 
283  if (columnType == null)
284  throw new ArgumentNullException("columnType");
285 
286  var column = new ColumnInfo(columnName, columnType);
287  column.IsNotNull = notNull;
288  AddColumn(column);
289  return column;
290  }
A long string in the system.
void AddColumn(ColumnInfo column)
Adds a new column to the table at the last position of the columns list in the table metadata...
Definition: TableInfo.cs:230
void Deveel.Data.Sql.Tables.TableInfo.AddColumnSafe ( ColumnInfo  column)
inlinepackage

Definition at line 203 of file TableInfo.cs.

203  {
204  if (column == null)
205  throw new ArgumentNullException("column");
206 
208 
209  columnsCache.Clear();
210  column.TableInfo = this;
211  columns.Add(column);
212  }
readonly Dictionary< ObjectName, int > columnsCache
Definition: TableInfo.cs:43
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
TableInfo Deveel.Data.Sql.Tables.TableInfo.Alias ( ObjectName  alias)
inline

Definition at line 346 of file TableInfo.cs.

346  {
347  return new TableInfo(alias, Id, IsPermanent, new ReadOnlyCollection<ColumnInfo>(columns), true);
348  }
TableInfo(ObjectName tableName)
Constructs the object with the given table name.
Definition: TableInfo.cs:54
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113
TableInfo Deveel.Data.Sql.Tables.TableInfo.AsReadOnly ( )
inline

Creates a new instance of TableInfo as an immutable copy of this table metadata.

Returns
Returns a new read-only instance of TableInfo that is a copy of this table metadata.

Definition at line 342 of file TableInfo.cs.

342  {
343  return new TableInfo(TableName, Id, IsPermanent, new ReadOnlyCollection<ColumnInfo>(columns), true);
344  }
TableInfo(ObjectName tableName)
Constructs the object with the given table name.
Definition: TableInfo.cs:54
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113
void Deveel.Data.Sql.Tables.TableInfo.AssertNotReadOnly ( )
inlineprivate

Definition at line 185 of file TableInfo.cs.

185  {
186  if (IsReadOnly)
187  throw new InvalidOperationException();
188  }
bool IsReadOnly
Gets a boolean value that indicates if the structure of this table cannot be altered.
Definition: TableInfo.cs:153
static TableInfo Deveel.Data.Sql.Tables.TableInfo.Deserialize ( Stream  stream,
ITypeResolver  typeResolver 
)
inlinestatic

Definition at line 411 of file TableInfo.cs.

411  {
412  var reader = new BinaryReader(stream, Encoding.Unicode);
413  return Deserialize(reader, typeResolver);
414  }
static TableInfo Deserialize(Stream stream, ITypeResolver typeResolver)
Definition: TableInfo.cs:411
static TableInfo Deveel.Data.Sql.Tables.TableInfo.Deserialize ( BinaryReader  reader,
ITypeResolver  typeResolver 
)
inlinestatic

Definition at line 416 of file TableInfo.cs.

416  {
417  var version = reader.ReadInt32();
418  if (version != 3)
419  throw new FormatException("Invalid version of the table info.");
420 
421  var catName = reader.ReadString();
422  var schemName = reader.ReadString();
423  var tableName = reader.ReadString();
424 
425  var objSchemaName = !String.IsNullOrEmpty(catName)
426  ? new ObjectName(new ObjectName(catName), schemName)
427  : new ObjectName(schemName);
428 
429  var objTableName = new ObjectName(objSchemaName, tableName);
430 
431  var tableInfo = new TableInfo(objTableName);
432 
433  var colCount = reader.ReadInt32();
434  for (int i = 0; i < colCount; i++) {
435  var columnInfo = ColumnInfo.Deserialize(reader, typeResolver);
436 
437  if (columnInfo != null)
438  tableInfo.AddColumn(columnInfo);
439  }
440 
441  return tableInfo;
442  }
A long string in the system.
TableInfo(ObjectName tableName)
Constructs the object with the given table name.
Definition: TableInfo.cs:54
void Deveel.Data.Sql.Tables.TableInfo.Establish ( int  id)
inline

Definition at line 190 of file TableInfo.cs.

190  {
191  Id = id;
192  IsPermanent = true;
193  }
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113
void ISerializable. Deveel.Data.Sql.Tables.TableInfo.GetData ( SerializeData  data)
inlineprivate

Implements Deveel.Data.Serialization.ISerializable.

Definition at line 195 of file TableInfo.cs.

195  {
196  data.SetValue("TableName", TableName);
197  data.SetValue("TableId", Id);
198  data.SetValue("ReadOnly", IsReadOnly);
199  data.SetValue("Permanent", IsPermanent);
200  data.SetValue("Columns", columns.ToArray());
201  }
int Id
Gets a unique identifier of the table in a database system.
Definition: TableInfo.cs:107
void SetValue(string key, Type type, object value)
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
bool IsReadOnly
Gets a boolean value that indicates if the structure of this table cannot be altered.
Definition: TableInfo.cs:153
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
bool IsPermanent
Gets a value that indicates if the table is permanent.
Definition: TableInfo.cs:113
IEnumerator<ColumnInfo> Deveel.Data.Sql.Tables.TableInfo.GetEnumerator ( )
inline

Definition at line 293 of file TableInfo.cs.

293  {
294  return columns.GetEnumerator();
295  }
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
IEnumerator IEnumerable. Deveel.Data.Sql.Tables.TableInfo.GetEnumerator ( )
inlineprivate

Definition at line 297 of file TableInfo.cs.

297  {
298  return GetEnumerator();
299  }
IEnumerator< ColumnInfo > GetEnumerator()
Definition: TableInfo.cs:293
int Deveel.Data.Sql.Tables.TableInfo.IndexOfColumn ( string  columnName)
inline

Gets the offset of the column with the given name.

Parameters
columnNameThe name of the column of which to get the offset.
Returns
Returns a zero-based index of a column with the given name, if defined by the table metadata, or -1 otherwise.

Definition at line 310 of file TableInfo.cs.

310  {
311  return IndexOfColumn(new ObjectName(TableName, columnName));
312  }
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
int Deveel.Data.Sql.Tables.TableInfo.IndexOfColumn ( ObjectName  columnName)
inline

Definition at line 314 of file TableInfo.cs.

314  {
315  int index;
316  if (!columnsCache.TryGetValue(columnName, out index)) {
317  bool found = false;
318  for (int i = 0; i < columns.Count; i++) {
319  var column = columns[i];
320  if (column.ColumnName.Equals(columnName.Name, StringComparison.Ordinal)) {
321  index = i;
322  columnsCache[columnName] = index;
323  found = true;
324  }
325  }
326 
327  if (!found)
328  index = -1;
329  }
330 
331  return index;
332  }
readonly Dictionary< ObjectName, int > columnsCache
Definition: TableInfo.cs:43
readonly IList< ColumnInfo > columns
Definition: TableInfo.cs:42
IEnumerable<int> Deveel.Data.Sql.Tables.TableInfo.IndexOfColumns ( IEnumerable< string >  columnNames)
inline

Definition at line 380 of file TableInfo.cs.

380  {
381  if (columnNames == null)
382  return new int[0];
383 
384  return columnNames.Select(IndexOfColumn).ToArray();
385  }
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
SqlExpression Deveel.Data.Sql.Tables.TableInfo.ResolveColumns ( bool  ignoreCase,
SqlExpression  expression 
)
inlinepackage

Definition at line 350 of file TableInfo.cs.

350  {
351  var visitor = new ColumnsResolver(this, ignoreCase);
352  return visitor.Visit(expression);
353  }
static void Deveel.Data.Sql.Tables.TableInfo.Serialize ( TableInfo  tableInfo,
Stream  stream 
)
inlinestatic

Definition at line 387 of file TableInfo.cs.

387  {
388  var writer = new BinaryWriter(stream, Encoding.Unicode);
389  Serialize(tableInfo, writer);
390  }
static void Serialize(TableInfo tableInfo, Stream stream)
Definition: TableInfo.cs:387
static void Deveel.Data.Sql.Tables.TableInfo.Serialize ( TableInfo  tableInfo,
BinaryWriter  writer 
)
inlinestatic

Definition at line 392 of file TableInfo.cs.

392  {
393  writer.Write(3); // Version
394 
395  var catName = tableInfo.CatalogName;
396  if (catName == null)
397  catName = String.Empty;
398 
399  writer.Write(catName);
400  writer.Write(tableInfo.SchemaName.Name);
401  writer.Write(tableInfo.Name);
402 
403  var colCount = tableInfo.columns.Count;
404  writer.Write(colCount);
405  for (int i = 0; i < colCount; i++) {
406  var column = tableInfo.columns[i];
407  ColumnInfo.Serialize(column, writer);
408  }
409  }
A long string in the system.

Member Data Documentation

readonly IList<ColumnInfo> Deveel.Data.Sql.Tables.TableInfo.columns
private

Definition at line 42 of file TableInfo.cs.

readonly Dictionary<ObjectName, int> Deveel.Data.Sql.Tables.TableInfo.columnsCache
private

Definition at line 43 of file TableInfo.cs.

Property Documentation

string Deveel.Data.Sql.Tables.TableInfo.CatalogName
get

Gets the name of the catalog containing the table, if defined.

Definition at line 136 of file TableInfo.cs.

int Deveel.Data.Sql.Tables.TableInfo.ColumnCount
get

Gets a count of the columns defined by this object.

Definition at line 159 of file TableInfo.cs.

ObjectName IObjectInfo. Deveel.Data.Sql.Tables.TableInfo.FullName
getprivate

Definition at line 99 of file TableInfo.cs.

int Deveel.Data.Sql.Tables.TableInfo.Id
getprivate set

Gets a unique identifier of the table in a database system.

See also
IsPermanent

Definition at line 107 of file TableInfo.cs.

bool Deveel.Data.Sql.Tables.TableInfo.IsPermanent
getprivate set

Gets a value that indicates if the table is permanent.

See also
ITransaction.CreateTable

Definition at line 113 of file TableInfo.cs.

bool Deveel.Data.Sql.Tables.TableInfo.IsReadOnly
getprivate set

Gets a boolean value that indicates if the structure of this table cannot be altered.

Definition at line 153 of file TableInfo.cs.

string Deveel.Data.Sql.Tables.TableInfo.Name
get

Gets the name part of the table name.

See also
TableName, ObjectName.Name

Definition at line 120 of file TableInfo.cs.

DbObjectType IObjectInfo. Deveel.Data.Sql.Tables.TableInfo.ObjectType
getprivate

Definition at line 89 of file TableInfo.cs.

ObjectName Deveel.Data.Sql.Tables.TableInfo.SchemaName
get

Gets the schema name part of the table name.

See also
TableName, ObjectName.Parent

Definition at line 129 of file TableInfo.cs.

ObjectName Deveel.Data.Sql.Tables.TableInfo.TableName
getprivate set

Gets the fully qualified name of the table that is ensured to be unique within the system.

Definition at line 97 of file TableInfo.cs.

ColumnInfo Deveel.Data.Sql.Tables.TableInfo.this[int offset]
get

Gets the column object defined at the given offset within the table.

Parameters
offsetThe zero-based offset of the column to return.
Returns
Returns an object of type ColumnInfo that is at the given offset within the table.
Exceptions
ArgumentOutOfRangeExceptionIf the given offset is less than zero or greater or equal than the number of columns defined in the table.

Definition at line 176 of file TableInfo.cs.


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