DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Protected Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Sql.Tables.JoinedTable Class Referenceabstract
Inheritance diagram for Deveel.Data.Sql.Tables.JoinedTable:
Deveel.Data.Sql.Tables.Table Deveel.Data.Sql.Tables.IQueryTable Deveel.Data.Transactions.ILockable Deveel.Data.Sql.Tables.ITable Deveel.Data.Sql.IDbObject Deveel.Data.Sql.Tables.NaturallyJoinedTable Deveel.Data.Sql.Tables.VirtualTable Deveel.Data.Sql.Tables.OuterTable

Public Member Functions

 JoinedTable (IEnumerable< ITable > tables)
 
 JoinedTable (ITable table)
 
override void Lock ()
 
override void Release ()
 
override DataObject GetValue (long rowNumber, int columnOffset)
 Gets a single cell within the table that is located at the given column offset and row. More...
 
override IEnumerator< RowGetEnumerator ()
 
- Public Member Functions inherited from Deveel.Data.Sql.Tables.Table
void Dispose ()
 
ColumnIndex GetIndex (int columnOffset)
 Gets an index for given column that can be used to select values from this table. More...
 

Protected Member Functions

virtual void Init (IEnumerable< ITable > tables)
 
override int IndexOfColumn (ObjectName columnName)
 
override RawTableInfo GetRawTableInfo (RawTableInfo rootInfo)
 
override ObjectName GetResolvedColumnName (int column)
 
override ColumnIndex GetIndex (int column, int originalColumn, ITable table)
 
override IEnumerable< int > ResolveRows (int column, IEnumerable< int > rowSet, ITable ancestor)
 
abstract IEnumerable< int > ResolveRowsForTable (IEnumerable< int > rowSet, int tableNum)
 
int ResolveRowForTable (int rowNumber, int tableNum)
 
- Protected Member Functions inherited from Deveel.Data.Sql.Tables.Table
virtual void Dispose (bool disposing)
 
virtual void OnLockAcquired (Lock @lock)
 
virtual void OnLockReleased (Lock @lock)
 
int FindColumn (ObjectName columnName)
 

Properties

ColumnIndex[] ColumnIndices [get]
 
int[] ColumnTable [get]
 
int[] ColumnFilter [get]
 
override int ColumnCount [get]
 
override IContext Context [get]
 
override TableInfo TableInfo [get]
 
ITable[] ReferenceTables [get]
 
int SortColumn [get, set]
 
- Properties inherited from Deveel.Data.Sql.Tables.Table
abstract IContext Context [get]
 
abstract TableInfo TableInfo [get]
 
bool IsLocked [get, private set]
 
object ILockable. RefId [get]
 
int IQueryTable. ColumnCount [get]
 
virtual int ColumnCount [get]
 
abstract int RowCount [get]
 
ObjectName FullName [get]
 
DbObjectType IDbObject. ObjectType [get]
 
- Properties inherited from Deveel.Data.Sql.Tables.IQueryTable
int ColumnCount [get]
 
- Properties inherited from Deveel.Data.Sql.Tables.ITable
IContext Context [get]
 
TableInfo TableInfo [get]
 Gets the metadata information of the table, used to resolve the column sources. More...
 
int RowCount [get]
 Gets the total number of rows in the table. More...
 
- Properties inherited from Deveel.Data.Sql.IDbObject
ObjectName FullName [get]
 Gets the fully qualified name of the object used to resolve it uniquely within the database. More...
 
DbObjectType ObjectType [get]
 Gets the type of database object that the implementation is for More...
 
- Properties inherited from Deveel.Data.Transactions.ILockable
object RefId [get]
 

Private Member Functions

IList< int > CalculateRowReferenceList ()
 
RawTableInfo GetRawTableInfo (RawTableInfo info, IEnumerable< int > rows)
 

Private Attributes

ITable[] referenceList
 
ColumnIndex[] indexes
 
int[] columnTable
 
int[] columnFilter
 
TableInfo vtTableInfo
 
byte rootsLocked
 

Detailed Description

Definition at line 24 of file JoinedTable.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.Tables.JoinedTable.JoinedTable ( IEnumerable< ITable tables)
inline

Definition at line 39 of file JoinedTable.cs.

39  {
40  SortColumn = -1;
41  Init(tables);
42  }
virtual void Init(IEnumerable< ITable > tables)
Definition: JoinedTable.cs:60
Deveel.Data.Sql.Tables.JoinedTable.JoinedTable ( ITable  table)
inline

Definition at line 44 of file JoinedTable.cs.

45  : this(new[] {table}) {
46  }

Member Function Documentation

IList<int> Deveel.Data.Sql.Tables.JoinedTable.CalculateRowReferenceList ( )
inlineprivate

Definition at line 141 of file JoinedTable.cs.

141  {
142  int size = RowCount;
143  List<int> allList = new List<int>(size);
144  for (int i = 0; i < size; ++i) {
145  allList.Add(i);
146  }
147  return allList;
148  }
abstract int RowCount
Definition: Table.cs:67
override IEnumerator<Row> Deveel.Data.Sql.Tables.JoinedTable.GetEnumerator ( )
inlinevirtual

Implements Deveel.Data.Sql.Tables.Table.

Definition at line 207 of file JoinedTable.cs.

207  {
208  return new SimpleRowEnumerator(this);
209  }
override ColumnIndex Deveel.Data.Sql.Tables.JoinedTable.GetIndex ( int  column,
int  originalColumn,
ITable  table 
)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Sql.Tables.Table.

Reimplemented in Deveel.Data.Sql.Tables.OuterTable.

Definition at line 211 of file JoinedTable.cs.

211  {
212  // First check if the given SelectableScheme is in the column_scheme array
213  var scheme = indexes[column];
214  if (scheme != null) {
215  if (table == this)
216  return scheme;
217 
218  return scheme.GetSubset(table, originalColumn);
219  }
220 
221  // If it isn't then we need to calculate it
222  ColumnIndex index;
223 
224  // Optimization: The table may be naturally ordered by a column. If it
225  // is we don't try to generate an ordered set.
226  if (SortColumn != -1 &&
227  SortColumn == column) {
228  var isop = new InsertSearchIndex(this, column, CalculateRowReferenceList());
229  isop.RecordUid = false;
230  index = isop;
231  indexes[column] = index;
232  if (table != this) {
233  index = index.GetSubset(table, originalColumn);
234  }
235 
236  } else {
237  // Otherwise we must generate the ordered set from the information in
238  // a parent index.
239  var parentTable = referenceList[columnTable[column]];
240  index = parentTable.GetIndex(columnFilter[column], originalColumn, table);
241  if (table == this) {
242  indexes[column] = index;
243  }
244  }
245 
246  return index;
247  }
IList< int > CalculateRowReferenceList()
Definition: JoinedTable.cs:141
virtual ColumnIndex GetSubset(ITable subsetTable, int subsetColumn)
Definition: ColumnIndex.cs:263
override RawTableInfo Deveel.Data.Sql.Tables.JoinedTable.GetRawTableInfo ( RawTableInfo  rootInfo)
inlineprotectedvirtual

Implements Deveel.Data.Sql.Tables.Table.

Definition at line 162 of file JoinedTable.cs.

162  {
163  var allList = new List<int>();
164  int size = RowCount;
165  for (int i = 0; i < size; ++i) {
166  allList.Add(i);
167  }
168 
169  return GetRawTableInfo(rootInfo, allList);
170  }
override RawTableInfo GetRawTableInfo(RawTableInfo rootInfo)
Definition: JoinedTable.cs:162
abstract int RowCount
Definition: Table.cs:67
RawTableInfo Deveel.Data.Sql.Tables.JoinedTable.GetRawTableInfo ( RawTableInfo  info,
IEnumerable< int >  rows 
)
inlineprivate

Definition at line 172 of file JoinedTable.cs.

172  {
173  if (this is IRootTable) {
174  info.Add((IRootTable)this, CalculateRowReferenceList());
175  } else {
176  for (int i = 0; i < referenceList.Length; ++i) {
177 
178  IEnumerable<int> newRowSet = new List<int>(rows);
179 
180  // Resolve the rows into the parents indices.
181  newRowSet = ResolveRowsForTable(newRowSet, i);
182 
183  var table = referenceList[i];
184  if (table is IRootTable) {
185  info.Add((IRootTable)table, newRowSet.ToArray());
186  } else if (table is JoinedTable) {
187  ((JoinedTable)table).GetRawTableInfo(info, newRowSet);
188  }
189  }
190  }
191 
192  return info;
193  }
JoinedTable(IEnumerable< ITable > tables)
Definition: JoinedTable.cs:39
IList< int > CalculateRowReferenceList()
Definition: JoinedTable.cs:141
abstract IEnumerable< int > ResolveRowsForTable(IEnumerable< int > rowSet, int tableNum)
override ObjectName Deveel.Data.Sql.Tables.JoinedTable.GetResolvedColumnName ( int  column)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Sql.Tables.Table.

Definition at line 195 of file JoinedTable.cs.

195  {
196  var parentTable = referenceList[columnTable[column]];
197  return parentTable.GetResolvedColumnName(columnFilter[column]);
198  }
override DataObject Deveel.Data.Sql.Tables.JoinedTable.GetValue ( long  rowNumber,
int  columnOffset 
)
inlinevirtual

Gets a single cell within the table that is located at the given column offset and row.

Parameters
rowNumberThe unique number of the row where the cell is located.
columnOffsetThe zero-based offset of the column of the cell to return.
Returns
Returns an instance of DataObject that is contained in the cell located by the row and column coordinates provided.
Exceptions
ArgumentOutOfRangeExceptionIf the given columnOffset is less than zero or greater or equal than the number of columns defined in the table metadata.
See also
Tables.TableInfo.IndexOfColumn(string)

Implements Deveel.Data.Sql.Tables.Table.

Reimplemented in Deveel.Data.Sql.Tables.OuterTable.

Definition at line 200 of file JoinedTable.cs.

200  {
201  int tableNum = columnTable[columnOffset];
202  var parentTable = referenceList[tableNum];
203  rowNumber = ResolveRowForTable((int)rowNumber, tableNum);
204  return parentTable.GetValue(rowNumber, columnFilter[columnOffset]);
205  }
int ResolveRowForTable(int rowNumber, int tableNum)
Definition: JoinedTable.cs:264
override int Deveel.Data.Sql.Tables.JoinedTable.IndexOfColumn ( ObjectName  columnName)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Sql.Tables.Table.

Definition at line 150 of file JoinedTable.cs.

150  {
151  int colIndex = 0;
152  for (int i = 0; i < referenceList.Length; ++i) {
153  int col = referenceList[i].FindColumn(columnName);
154  if (col != -1)
155  return col + colIndex;
156 
157  colIndex += referenceList[i].ColumnCount();
158  }
159  return -1;
160  }
virtual void Deveel.Data.Sql.Tables.JoinedTable.Init ( IEnumerable< ITable tables)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Sql.Tables.VirtualTable.

Definition at line 60 of file JoinedTable.cs.

60  {
61  var tablesArray = tables.ToArray();
62  referenceList = tablesArray;
63 
64  int colCount = ColumnCount;
65  indexes = new ColumnIndex[colCount];
66 
67  vtTableInfo = new TableInfo(new ObjectName("#VIRTUAL TABLE#"));
68 
69  // Generate look up tables for column_table and column_filter information
70 
71  columnTable = new int[colCount];
72  columnFilter = new int[colCount];
73 
74  int index = 0;
75  for (int i = 0; i < referenceList.Length; ++i) {
76  var curTable = referenceList[i];
77  var curTableInfo = curTable.TableInfo;
78  int refColCount = curTable.ColumnCount();
79 
80  // For each column
81  for (int n = 0; n < refColCount; ++n) {
82  columnFilter[index] = n;
83  columnTable[index] = i;
84  ++index;
85 
86  // Add this column to the data table info of this table.
87  var columnInfo = curTableInfo[n];
88  var newColumnInfo = new ColumnInfo(columnInfo.ColumnName, columnInfo.ColumnType) {
89  DefaultExpression = columnInfo.DefaultExpression,
90  IsNotNull = columnInfo.IsNotNull,
91  IndexType = columnInfo.IndexType
92  };
93 
94  vtTableInfo.AddColumnSafe(newColumnInfo);
95  }
96  }
97 
99  }
void AddColumnSafe(ColumnInfo column)
Definition: TableInfo.cs:203
TableInfo AsReadOnly()
Creates a new instance of TableInfo as an immutable copy of this table metadata.
Definition: TableInfo.cs:342
TableInfo TableInfo
Gets the metadata information of the table, used to resolve the column sources.
Definition: ITable.cs:47
int ColumnCount
Gets a count of the columns defined by this object.
Definition: TableInfo.cs:159
override void Deveel.Data.Sql.Tables.JoinedTable.Lock ( )
inlinevirtual

Implements Deveel.Data.Sql.Tables.Table.

Definition at line 125 of file JoinedTable.cs.

125  {
126  // For each table, recurse.
127  rootsLocked++;
128  for (int i = 0; i < referenceList.Length; ++i) {
129  referenceList[i].Lock();
130  }
131  }
override void Deveel.Data.Sql.Tables.JoinedTable.Release ( )
inlinevirtual

Implements Deveel.Data.Sql.Tables.Table.

Definition at line 133 of file JoinedTable.cs.

133  {
134  // For each table, recurse.
135  rootsLocked--;
136  for (int i = 0; i < referenceList.Length; ++i) {
137  referenceList[i].Release();
138  }
139  }
int Deveel.Data.Sql.Tables.JoinedTable.ResolveRowForTable ( int  rowNumber,
int  tableNum 
)
inlineprotected

Definition at line 264 of file JoinedTable.cs.

264  {
265  return ResolveRowsForTable(new[] {rowNumber}, tableNum).First();
266  }
abstract IEnumerable< int > ResolveRowsForTable(IEnumerable< int > rowSet, int tableNum)
override IEnumerable<int> Deveel.Data.Sql.Tables.JoinedTable.ResolveRows ( int  column,
IEnumerable< int >  rowSet,
ITable  ancestor 
)
inlineprotectedvirtual

Implements Deveel.Data.Sql.Tables.Table.

Definition at line 249 of file JoinedTable.cs.

249  {
250  if (ancestor == this)
251  return new int[0];
252 
253  int tableNum = columnTable[column];
254  var parentTable = referenceList[tableNum];
255 
256  // Resolve the rows into the parents indices
257  var rows = ResolveRowsForTable(rowSet, tableNum);
258 
259  return parentTable.ResolveRows(columnFilter[column], rows, ancestor);
260  }
abstract IEnumerable< int > ResolveRowsForTable(IEnumerable< int > rowSet, int tableNum)
abstract IEnumerable<int> Deveel.Data.Sql.Tables.JoinedTable.ResolveRowsForTable ( IEnumerable< int >  rowSet,
int  tableNum 
)
protectedpure virtual

Member Data Documentation

int [] Deveel.Data.Sql.Tables.JoinedTable.columnFilter
private

Definition at line 33 of file JoinedTable.cs.

int [] Deveel.Data.Sql.Tables.JoinedTable.columnTable
private

Definition at line 32 of file JoinedTable.cs.

ColumnIndex [] Deveel.Data.Sql.Tables.JoinedTable.indexes
private

Definition at line 26 of file JoinedTable.cs.

ITable [] Deveel.Data.Sql.Tables.JoinedTable.referenceList
private

Definition at line 25 of file JoinedTable.cs.

byte Deveel.Data.Sql.Tables.JoinedTable.rootsLocked
private

Definition at line 37 of file JoinedTable.cs.

TableInfo Deveel.Data.Sql.Tables.JoinedTable.vtTableInfo
private

Definition at line 35 of file JoinedTable.cs.

Property Documentation

override int Deveel.Data.Sql.Tables.JoinedTable.ColumnCount
getprotected

Definition at line 101 of file JoinedTable.cs.

int [] Deveel.Data.Sql.Tables.JoinedTable.ColumnFilter
getprotected

Definition at line 56 of file JoinedTable.cs.

ColumnIndex [] Deveel.Data.Sql.Tables.JoinedTable.ColumnIndices
getprotected

Definition at line 48 of file JoinedTable.cs.

int [] Deveel.Data.Sql.Tables.JoinedTable.ColumnTable
getprotected

Definition at line 52 of file JoinedTable.cs.

override IContext Deveel.Data.Sql.Tables.JoinedTable.Context
get

Definition at line 111 of file JoinedTable.cs.

ITable [] Deveel.Data.Sql.Tables.JoinedTable.ReferenceTables
getprotected

Definition at line 119 of file JoinedTable.cs.

int Deveel.Data.Sql.Tables.JoinedTable.SortColumn
getset

Definition at line 123 of file JoinedTable.cs.

override TableInfo Deveel.Data.Sql.Tables.JoinedTable.TableInfo
get

Definition at line 115 of file JoinedTable.cs.


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