DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
LimitedTable.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;
19 using System.Collections.Generic;
20 
21 namespace Deveel.Data.Sql.Tables {
23  public long Offset { get; private set; }
24 
25  public long Total { get; private set; }
26 
27  public LimitedTable(ITable parent, long offset, long total)
28  : base(parent) {
29  if (offset < 0)
30  offset = 0;
31 
32  Offset = offset;
33  Total = total;
34  }
35 
36  private long NormalizeRow(long rowNumber) {
37  rowNumber += Offset;
38  return rowNumber;
39  }
40 
41  private int NormalizeCount(long count) {
42  count -= Offset;
43  return (int) System.Math.Min(count, Total);
44  }
45 
46  public override int RowCount {
47  get { return NormalizeCount(base.RowCount); }
48  }
49 
50  public override DataObject GetValue(long rowNumber, int columnOffset) {
51  if (rowNumber >= RowCount)
52  throw new ArgumentOutOfRangeException("rowNumber");
53 
54  return base.GetValue(NormalizeRow(rowNumber), columnOffset);
55  }
56 
57  public override IEnumerator<Row> GetEnumerator() {
58  return new Enumerator(this);
59  }
60 
61  #region Enumerator
62 
63  class Enumerator : IEnumerator<Row> {
64  private int offset = -1;
66 
67  public Enumerator(LimitedTable table) {
68  this.table = table;
69  }
70 
71  public void Dispose() {
72  table = null;
73  }
74 
75  public bool MoveNext() {
76  return ++offset < table.RowCount;
77  }
78 
79  public void Reset() {
80  offset = -1;
81  }
82 
83  public Row Current {
84  get { return table.GetRow(offset); }
85  }
86 
87  object IEnumerator.Current {
88  get { return Current; }
89  }
90  }
91 
92  #endregion
93  }
94 }
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
long NormalizeRow(long rowNumber)
Definition: LimitedTable.cs:36
A single row in a table of a database.
Definition: Row.cs:44
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
override IEnumerator< Row > GetEnumerator()
Definition: LimitedTable.cs:57
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: LimitedTable.cs:50
LimitedTable(ITable parent, long offset, long total)
Definition: LimitedTable.cs:27