DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
FilterTable.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 
20 using Deveel.Data.Index;
21 
22 namespace Deveel.Data.Sql.Tables {
23  class FilterTable : Table {
25 
26  public FilterTable(ITable parent) {
27  Parent = parent;
28  }
29 
30  protected ITable Parent { get; private set; }
31 
32  public override IEnumerator<Row> GetEnumerator() {
33  return Parent.GetEnumerator();
34  }
35 
36  public override IContext Context {
37  get { return Parent.Context; }
38  }
39 
40  public override TableInfo TableInfo {
41  get { return Parent.TableInfo; }
42  }
43 
44  public override int RowCount {
45  get { return Parent.RowCount; }
46  }
47 
48  public override void Lock() {
49  Parent.Lock();
50  }
51 
52  public override void Release() {
53  Parent.Release();
54  }
55 
56  protected override RawTableInfo GetRawTableInfo(RawTableInfo rootInfo) {
57  return Parent.GetRawTableInfo(rootInfo);
58  }
59 
60  protected override ColumnIndex GetIndex(int column, int originalColumn, ITable table) {
61  if (columnIndices == null) {
62  columnIndices = new ColumnIndex[Parent.ColumnCount()];
63  }
64 
65  // Is there a local index available?
66  var index = columnIndices[column];
67  if (index == null) {
68  // If we are asking for the index of this table we must
69  // tell the parent we are looking for its index.
70  var t = table;
71  if (table == this)
72  t = Parent;
73 
74  // Index is not cached in this table so ask the parent.
75  index = Parent.GetIndex(column, originalColumn, t);
76  if (table == this)
77  columnIndices[column] = index;
78 
79  } else {
80  // If this has a cached scheme and we are in the correct domain then
81  // return it.
82  if (table == this)
83  return index;
84 
85  // Otherwise we must calculate the subset of the scheme
86  return index.GetSubset(table, originalColumn);
87  }
88 
89  return index;
90  }
91 
92  protected override IEnumerable<int> ResolveRows(int column, IEnumerable<int> rowSet, ITable ancestor) {
93  if (ancestor == this || ancestor == Parent)
94  return rowSet;
95 
96  return Parent.ResolveRows(column, rowSet, ancestor);
97  }
98 
99  public override DataObject GetValue(long rowNumber, int columnOffset) {
100  return Parent.GetValue(rowNumber, columnOffset);
101  }
102 
103  protected override ObjectName GetResolvedColumnName(int column) {
104  return Parent.GetResolvedColumnName(column);
105  }
106  }
107 }
override IEnumerator< Row > GetEnumerator()
Definition: FilterTable.cs:32
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
TableInfo(ObjectName tableName)
Constructs the object with the given table name.
Definition: TableInfo.cs:54
override RawTableInfo GetRawTableInfo(RawTableInfo rootInfo)
Definition: FilterTable.cs:56
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
Definition: FilterTable.cs:99
Describes the name of an object within a database.
Definition: ObjectName.cs:44
override ColumnIndex GetIndex(int column, int originalColumn, ITable table)
Definition: FilterTable.cs:60
override IEnumerable< int > ResolveRows(int column, IEnumerable< int > rowSet, ITable ancestor)
Definition: FilterTable.cs:92
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41
virtual ColumnIndex GetSubset(ITable subsetTable, int subsetColumn)
Definition: ColumnIndex.cs:263
ColumnIndex GetIndex(int columnOffset)
Gets an index for given column that can be used to select values from this table. ...
override ObjectName GetResolvedColumnName(int column)
Definition: FilterTable.cs:103