DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
CachePointNode.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 
19 using Deveel.Data;
21 using Deveel.Data.Sql.Tables;
22 
23 namespace Deveel.Data.Sql.Query {
24  [Serializable]
26  private readonly static Object GlobLock = new Object();
27  private static int GlobId;
28 
30  : this(child,NewId()) {
31  }
32 
33  public CachePointNode(IQueryPlanNode child, long id)
34  : base(child) {
35  Id = id;
36  }
37 
38  private CachePointNode(ObjectData data)
39  : base(data) {
40  Id = data.GetInt32("Id");
41  }
42 
43  private static long NewId() {
44  long id;
45  lock (GlobLock) {
46  id = ((int)DateTime.Now.Ticks << 16) | (GlobId & 0x0FFFF);
47  ++GlobId;
48  }
49  return id;
50  }
51 
52  public long Id { get; private set; }
53 
54  public override ITable Evaluate(IRequest context) {
55  // Is the result available in the context?
56  var childTable = context.Query.GetCachedTable(Id.ToString());
57  if (childTable == null) {
58  // No so evaluate the child and cache it
59  childTable = Child.Evaluate(context);
60  context.Query.CacheTable(Id.ToString(), childTable);
61  }
62 
63  return childTable;
64  }
65 
66  protected override void GetData(SerializeData data) {
67  data.SetValue("Id", Id);
68  }
69  }
70 }
CachePointNode(IQueryPlanNode child)
Defines the contract to access the data contained into a table of a database.
Definition: ITable.cs:40
A IQueryPlanNode with a single child.
void SetValue(string key, Type type, object value)
CachePointNode(IQueryPlanNode child, long id)
override ITable Evaluate(IRequest context)
A node element of a query plan tree. /summary>
override void GetData(SerializeData data)