DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
VirtualTable.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 namespace Deveel.Data.Sql.Tables {
23  private IList<int>[] rowList;
24  private int rowCount;
25 
26  public VirtualTable(IEnumerable<ITable> tables)
27  : this(tables, null) {
28  }
29 
30  public VirtualTable(IEnumerable<ITable> tables, IList<IList<int>> rows)
31  : base(tables) {
32  SetRows(rows);
33  }
34 
35  public VirtualTable(ITable table)
36  : this(table, null) {
37  }
38 
39  public VirtualTable(ITable table, IList<int> rows)
40  : base(table) {
41  SetRows(new []{rows});
42  }
43 
44  private void SetRows(IList<IList<int>> rows) {
45  var tableList = ReferenceTables.ToList();
46 
47  for (int i = 0; i < tableList.Count; ++i) {
48  rowList[i] = new List<int>(rows[i]);
49  }
50  if (rows.Count > 0) {
51  rowCount = rows[0].Count();
52  }
53  }
54 
55  protected override void Init(IEnumerable<ITable> tables) {
56  var tableList = tables.ToList();
57  base.Init(tableList);
58 
59  int tableCount = tableList.Count;
60  rowList = new IList<int>[tableCount];
61  for (int i = 0; i < tableCount; ++i) {
62  rowList[i] = new List<int>();
63  }
64  }
65 
66  public override int RowCount {
67  get { return rowCount; }
68  }
69 
70  protected IList<int>[] ReferenceRows {
71  get { return rowList; }
72  }
73 
74  protected override IEnumerable<int> ResolveRowsForTable(IEnumerable<int> rows, int tableNum) {
75  var rowSet = rows.ToList();
76  IList<int> curRowList = rowList[tableNum];
77  for (int n = rowSet.Count - 1; n >= 0; --n) {
78  int aa = rowSet[n];
79  int bb = curRowList[aa];
80  rowSet[n] = bb;
81  }
82 
83  return rowSet.ToArray();
84  }
85  }
86 }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
override IEnumerable< int > ResolveRowsForTable(IEnumerable< int > rows, int tableNum)
Definition: VirtualTable.cs:74
VirtualTable(ITable table, IList< int > rows)
Definition: VirtualTable.cs:39
override void Init(IEnumerable< ITable > tables)
Definition: VirtualTable.cs:55
void SetRows(IList< IList< int >> rows)
Definition: VirtualTable.cs:44
VirtualTable(IEnumerable< ITable > tables)
Definition: VirtualTable.cs:26
VirtualTable(IEnumerable< ITable > tables, IList< IList< int >> rows)
Definition: VirtualTable.cs:30