DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TableInternalExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 
21 using Deveel.Data.Index;
22 
23 namespace Deveel.Data.Sql.Tables {
24  public static class TableInternalExtensions {
25  internal static int FindColumn(this ITable table, ObjectName columnName) {
26  if (table is IQueryTable)
27  return ((IQueryTable)table).FindColumn(columnName);
28 
29  var parent = columnName.Parent;
30  if (!parent.Equals(table.TableInfo.TableName))
31  return -1;
32 
33  return table.TableInfo.IndexOfColumn(columnName.Name);
34  }
35 
36  internal static int ColumnCount(this ITable table) {
37  if (table is IQueryTable)
38  return ((IQueryTable)table).ColumnCount;
39 
40  return table.TableInfo.ColumnCount;
41  }
42 
43  internal static ObjectName GetResolvedColumnName(this ITable table, int columnOffset) {
44  if (table is IQueryTable)
45  return ((IQueryTable)table).GetResolvedColumnName(columnOffset);
46 
47  var tableName = table.TableInfo.TableName;
48  var columnName = table.TableInfo[columnOffset].ColumnName;
49  return new ObjectName(tableName, columnName);
50  }
51 
52  internal static IEnumerable<int> ResolveRows(this ITable table, int columnOffset, IEnumerable<int> rows,
53  ITable ancestor) {
54  if (table is IQueryTable)
55  return ((IQueryTable)table).ResolveRows(columnOffset, rows, ancestor);
56 
57  if (table != ancestor)
58  throw new ArgumentException();
59 
60  return rows.ToList();
61  }
62 
63  internal static ColumnIndex GetIndex(this ITable thisTable, int column, int originalColumn, ITable table) {
64  if (thisTable is IQueryTable)
65  return ((IQueryTable)thisTable).GetIndex(column, originalColumn, table);
66 
67  var index = thisTable.GetIndex(column);
68  if (table == thisTable)
69  return index;
70 
71  // Otherwise, get the scheme to calculate a subset of the given scheme.
72  return index.GetSubset(table, originalColumn);
73  }
74 
75  internal static ITableVariableResolver GetVariableResolver(this ITable table) {
76  if (table is IQueryTable)
77  return ((IQueryTable)table).GetVariableResolver();
78 
79  // TODO: implement a default table resolver
80  throw new NotImplementedException();
81  }
82 
83  internal static ObjectName ResolveColumnName(this ITable table, string columnName) {
84  return new ObjectName(table.TableInfo.TableName, columnName);
85  }
86 
87  internal static RawTableInfo GetRawTableInfo(this ITable table) {
88  return GetRawTableInfo(table, new RawTableInfo());
89  }
90 
91  internal static RawTableInfo GetRawTableInfo(this ITable table, RawTableInfo info) {
92  if (table is IQueryTable)
93  return ((IQueryTable)table).GetRawTableInfo(info);
94 
95  throw new NotSupportedException();
96  }
97 
98  internal static void Lock(this ITable table) {
99  if (table is IQueryTable)
100  ((IQueryTable)table).Lock();
101  }
102 
103  internal static void Release(this ITable table) {
104  if (table is IQueryTable)
105  ((IQueryTable)table).Release();
106  }
107  }
108 }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
static RawTableInfo GetRawTableInfo(this ITable table)
static ObjectName ResolveColumnName(this ITable table, string columnName)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
static IEnumerable< int > ResolveRows(this ITable table, int columnOffset, IEnumerable< int > rows, ITable ancestor)
static ColumnIndex GetIndex(this ITable thisTable, int column, int originalColumn, ITable table)
static ITableVariableResolver GetVariableResolver(this ITable table)
TableInfo TableInfo
Gets the metadata information of the table, used to resolve the column sources.
Definition: ITable.cs:47
static RawTableInfo GetRawTableInfo(this ITable table, RawTableInfo info)
int IndexOfColumn(string columnName)
Gets the offset of the column with the given name.
Definition: TableInfo.cs:310
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
static ObjectName GetResolvedColumnName(this ITable table, int columnOffset)
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
static int FindColumn(this ITable table, ObjectName columnName)
int ColumnCount
Gets a count of the columns defined by this object.
Definition: TableInfo.cs:159
ColumnIndex GetIndex(int column, int originalColumn, ITable table)
virtual ColumnIndex GetSubset(ITable subsetTable, int subsetColumn)
Definition: ColumnIndex.cs:263