18 using System.Collections.Generic;
24 namespace Deveel.Data.Client {
41 this.connection = connection;
62 int origRowIndex = rowIndex;
63 int origRowCount = rowCount;
65 var cachedRows =
new List<CachedRow>();
68 bool foundNotcached =
false;
70 for (
int r = 0; r < rowCount && !foundNotcached; ++r) {
71 int daRow = rowIndex + r;
73 var rowRef =
new RowRef(resultId, daRow);
76 if (!rowCache.TryGet(rowRef, out rowObj)) {
78 if (rowIndex + rowCount > totalRowCount) {
79 rowCount = totalRowCount - rowIndex;
81 foundNotcached =
true;
88 var notCachedRows =
new List<CachedRow>();
92 foundNotcached =
false;
94 for (
int r = rowCount - 1; r >= 0 && !foundNotcached; --r) {
95 int daRow = rowIndex + r;
97 var rowRef =
new RowRef(resultId, daRow);
100 if (!rowCache.TryGet(rowRef, out rowObj)) {
101 if (rowIndex == origRowIndex) {
102 rowIndex = rowIndex - (rowCount - (r + 1));
104 rowCount = rowCount + rowIndex;
110 foundNotcached =
true;
113 notCachedRows.Insert(0, row);
119 if (foundNotcached) {
121 QueryResultPart block = connection.RequestResultPart(resultId, rowIndex, rowCount);
123 for (
int r = 0; r < rowCount; ++r) {
127 int theRow = (rowIndex + r);
129 var row = block.
GetRow(r);
130 for (
int c = 0; c < colCount; ++c) {
133 dataSizes[c] = row.ValueSizes[c];
134 colSize += row.ValueSizes[c];
145 if (colSize <= 3200) {
146 rowCache.Set(
new RowRef(resultId, theRow), cachedRow);
149 cachedRows.Add(cachedRow);
156 int low = origRowIndex;
157 int high = origRowIndex + origRowCount;
164 if (row.
Row >= low && row.
Row < high) {
166 var rowSizes =
new int[colCount];
167 for (
int c = 0; c < colCount; ++c) {
169 rowSizes[c] = row.
Sizes[c];
176 foreach (
CachedRow row
in notCachedRows) {
181 if (row.
Row >= low && row.
Row < high) {
183 var sizes =
new int[colCount];
184 for (
int c = 0; c < colCount; ++c) {
186 sizes[c] = row.
Sizes[c];
217 this.tableId = tableId;
222 return (
int)tableId + (row * 35331);
227 return (row == dest.row && tableId == dest.tableId);
QueryResultRow GetRow(int index)
void Clear()
Flushes the complete contents of the cache.
override int GetHashCode()
Defines the contract for a valid SQL Object
A cache that stores rows retrieved from the server in result set's.
Represents a cache of Objects. /summary>
LocalRowCache(DeveelDbConnection connection)
DeveelDbConnectionStringBuilder Settings
readonly Cache rowCache
The actual cache that stores the rows.
RowRef(int tableId, int row)
Used for the hash key in the cache.
override bool Equals(Object ob)
QueryResultPart GetResultPart(int resultId, int rowIndex, int rowCount, int colCount, int totalRowCount)
Requests a block of parts.
readonly DeveelDbConnection connection