18 using System.Collections.Generic;
23 namespace Deveel.Data.Sql.Tables {
45 : this(new[] {table}) {
49 get {
return indexes; }
52 protected int[] ColumnTable {
53 get {
return columnTable; }
56 protected int[] ColumnFilter {
57 get {
return columnFilter; }
60 protected virtual void Init(IEnumerable<ITable> tables) {
61 var tablesArray = tables.ToArray();
62 referenceList = tablesArray;
64 int colCount = ColumnCount;
71 columnTable =
new int[colCount];
72 columnFilter =
new int[colCount];
75 for (
int i = 0; i < referenceList.Length; ++i) {
76 var curTable = referenceList[i];
81 for (
int n = 0; n < refColCount; ++n) {
82 columnFilter[index] = n;
83 columnTable[index] = i;
87 var columnInfo = curTableInfo[n];
88 var newColumnInfo =
new ColumnInfo(columnInfo.ColumnName, columnInfo.ColumnType) {
90 IsNotNull = columnInfo.IsNotNull,
91 IndexType = columnInfo.IndexType
101 protected override int ColumnCount {
103 int columnCountSum = 0;
104 for (
int i = 0; i < referenceList.Length; ++i) {
105 columnCountSum += referenceList[i].ColumnCount();
107 return columnCountSum;
112 get {
return referenceList[0].
Context; }
116 get {
return vtTableInfo; }
120 get {
return referenceList; }
128 for (
int i = 0; i < referenceList.Length; ++i) {
129 referenceList[i].Lock();
136 for (
int i = 0; i < referenceList.Length; ++i) {
137 referenceList[i].Release();
143 List<int> allList =
new List<int>(size);
144 for (
int i = 0; i < size; ++i) {
152 for (
int i = 0; i < referenceList.Length; ++i) {
153 int col = referenceList[i].FindColumn(columnName);
155 return col + colIndex;
157 colIndex += referenceList[i].ColumnCount();
163 var allList =
new List<int>();
165 for (
int i = 0; i < size; ++i) {
169 return GetRawTableInfo(rootInfo, allList);
174 info.
Add((IRootTable)
this, CalculateRowReferenceList());
176 for (
int i = 0; i < referenceList.Length; ++i) {
178 IEnumerable<int> newRowSet =
new List<int>(rows);
181 newRowSet = ResolveRowsForTable(newRowSet, i);
183 var table = referenceList[i];
184 if (table is IRootTable) {
185 info.
Add((IRootTable)table, newRowSet.ToArray());
187 ((JoinedTable)table).GetRawTableInfo(info, newRowSet);
196 var parentTable = referenceList[columnTable[column]];
197 return parentTable.GetResolvedColumnName(columnFilter[column]);
201 int tableNum = columnTable[columnOffset];
202 var parentTable = referenceList[tableNum];
203 rowNumber = ResolveRowForTable((
int)rowNumber, tableNum);
204 return parentTable.GetValue(rowNumber, columnFilter[columnOffset]);
213 var scheme = indexes[column];
214 if (scheme != null) {
218 return scheme.
GetSubset(table, originalColumn);
229 isop.RecordUid =
false;
231 indexes[column] = index;
233 index = index.
GetSubset(table, originalColumn);
239 var parentTable = referenceList[columnTable[column]];
240 index = parentTable.GetIndex(columnFilter[column], originalColumn, table);
242 indexes[column] = index;
249 protected override IEnumerable<int>
ResolveRows(
int column, IEnumerable<int> rowSet,
ITable ancestor) {
250 if (ancestor ==
this)
253 int tableNum = columnTable[column];
254 var parentTable = referenceList[tableNum];
257 var rows = ResolveRowsForTable(rowSet, tableNum);
259 return parentTable.ResolveRows(columnFilter[column], rows, ancestor);
262 protected abstract IEnumerable<int> ResolveRowsForTable(IEnumerable<int> rowSet,
int tableNum);
265 return ResolveRowsForTable(
new[] {rowNumber}, tableNum).First();
Defines the metadata properties of a column within a table of a database.
Defines the contract to access the data contained into a table of a database.
override IEnumerator< Row > GetEnumerator()
void AddColumnSafe(ColumnInfo column)
override IEnumerable< int > ResolveRows(int column, IEnumerable< int > rowSet, ITable ancestor)
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
Describes the name of an object within a database.
JoinedTable(IEnumerable< ITable > tables)
IList< int > CalculateRowReferenceList()
override ColumnIndex GetIndex(int column, int originalColumn, ITable table)
TableInfo AsReadOnly()
Creates a new instance of TableInfo as an immutable copy of this table metadata.
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
TableInfo TableInfo
Gets the metadata information of the table, used to resolve the column sources.
SqlExpression DefaultExpression
Gets or sets a SqlExpression used as a DEFAULT when a constraint for the column is to SET DEFAULT...
void Add(IRootTable table, IList< int > rowSet)
RawTableInfo GetRawTableInfo(RawTableInfo info, IEnumerable< int > rows)
override RawTableInfo GetRawTableInfo(RawTableInfo rootInfo)
virtual void Init(IEnumerable< ITable > tables)
JoinedTable(ITable table)
int ColumnCount
Gets a count of the columns defined by this object.
override ObjectName GetResolvedColumnName(int column)
override int IndexOfColumn(ObjectName columnName)
Object used to represent a column in the ORDER BY clauses of a select statement.
Defines the metadata properties of a table existing within a database.
int ResolveRowForTable(int rowNumber, int tableNum)
virtual ColumnIndex GetSubset(ITable subsetTable, int subsetColumn)
Interface that is implemented by all root tables.