DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
VersionedTableIndexList.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 using Deveel.Data.Sql;
22 
23 namespace Deveel.Data.Sql.Tables {
25  private readonly List<TableEventRegistry> eventRegistries;
26 
27  public VersionedTableIndexList(TableSource tableSource) {
28  TableSource = tableSource;
29 
30  eventRegistries = new List<TableEventRegistry>();
31  }
32 
34  get { return TableSource.DatabaseContext; }
35  }
36 
37  public TableSource TableSource { get; private set; }
38 
39  public bool HasChangesPending {
40  get { return eventRegistries.Any(); }
41  }
42 
43  public void AddRegistry(TableEventRegistry registry) {
44  eventRegistries.Add(registry);
45  }
46 
47  public bool MergeChanges(long commitId) {
48  // TODO: report the stat to the system
49 
50  while (eventRegistries.Count > 0) {
51  var registry = eventRegistries[0];
52 
53  if (commitId > registry.CommitId) {
54  // Remove the top registry from the list.
55  eventRegistries.RemoveAt(0);
56  } else {
57  return false;
58  }
59  }
60 
61  return true;
62  }
63 
64  public IEnumerable<TableEventRegistry> FindSinceCommit(long commitId) {
65  return eventRegistries.Where(x => x.CommitId >= commitId);
66  }
67  }
68 }
The context of a single database within a system.
readonly List< TableEventRegistry > eventRegistries
IEnumerable< TableEventRegistry > FindSinceCommit(long commitId)