DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemContextExtensions.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.IO;
19 using System.Text;
20 
21 using Deveel.Data.Services;
22 
23 namespace Deveel.Data.Sql.Query {
24  public static class SystemContextExtensions {
25  public static void SerializeQueryPlan(this ISystemContext context, IQueryPlanNode planNode, Stream stream) {
26  using (var writer = new BinaryWriter(stream, Encoding.Unicode)) {
27  context.SerializeQueryPlan(planNode, writer);
28  }
29  }
30 
31  public static void SerializeQueryPlan(this ISystemContext context, IQueryPlanNode node, BinaryWriter writer) {
32  var nodeType = node.GetType();
33 
34  var serializers = context.ResolveAllServices<IQueryPlanNodeSerializer>();
35  foreach (var serializer in serializers) {
36  if (serializer.CanSerialize(nodeType)) {
37  serializer.Serialize(node, writer);
38  return;
39  }
40  }
41 
42  throw new InvalidOperationException(string.Format("Could not find any serializer for node type '{0}'.", nodeType));
43  }
44 
45  public static IQueryPlanNode DeserializeQueryPlan(this ISystemContext context, Type nodeType, BinaryReader reader) {
46  var serializers = context.ResolveAllServices<IQueryPlanNodeSerializer>();
47  foreach (var serializer in serializers) {
48  if (serializer.CanSerialize(nodeType)) {
49  return (IQueryPlanNode)serializer.Deserialize(reader);
50  }
51  }
52 
53  throw new InvalidOperationException(string.Format("Could not find any serializer for node type '{0}'.", nodeType));
54  }
55  }
56 }
The execution context of a database system, that is defining the configurations and the components us...
static IQueryPlanNode DeserializeQueryPlan(this ISystemContext context, Type nodeType, BinaryReader reader)
A query to the database to select data from a set of tables and columns.
static void SerializeQueryPlan(this ISystemContext context, IQueryPlanNode planNode, Stream stream)
A node element of a query plan tree. /summary>
static void SerializeQueryPlan(this ISystemContext context, IQueryPlanNode node, BinaryWriter writer)
void Serialize(object obj, BinaryWriter writer)