18 using System.Collections.Generic;
57 var nodeType = queryPlan.GetType();
59 if (seriializer == null)
60 throw new InvalidOperationException(String.Format(
"Could not find any serializer for type '{0}'.", nodeType));
66 var seriializer = Resolver.ResolveSerializer(nodeType);
67 if (seriializer == null)
68 throw new InvalidOperationException(String.Format(
"Could not find any serializer for type '{0}'.", nodeType));
75 if (seriializer == null)
76 throw new InvalidOperationException(String.Format(
"Could not find any serializer for type '{0}'.", nodeType));
83 writer.Write((byte) 0);
85 var nodeTypeString = node.GetType().FullName;
86 writer.Write((byte)1);
87 writer.Write(nodeTypeString);
89 Serialize(node, writer);
94 var state = reader.ReadByte();
98 var typeString = reader.ReadString();
100 var type =
Type.GetType(typeString,
true);
102 var type =
Type.GetType(typeString,
true,
true);
105 return Deserialize(type, reader);
108 private static void WriteArray<T>(T[] arrary, BinaryWriter writer, Action<T, BinaryWriter> write) {
109 var count = arrary == null ? 0 : arrary.Length;
112 if (arrary != null) {
113 for (
int i = 0; i < count; i++) {
114 write(arrary[i], writer);
124 WriteArray(expressions, writer, (expression, binaryWriter) =>
SqlExpression.
Serialize(expression, binaryWriter));
127 private static void WriteStrings(
string[] array, BinaryWriter writer) {
128 WriteArray(array, writer, (s, binaryWriter) => binaryWriter.Write(s));
131 private static T[] ReadArray<T>(BinaryReader reader, Func<BinaryReader, T> read) {
132 var count = reader.ReadInt32();
133 var list =
new List<T>(count);
134 for (
int i = 0; i < count; i++) {
135 var obj = read(reader);
139 return list.ToArray();
151 return ReadArray(reader, binaryReader => binaryReader.ReadString());
154 #region QueryPlanNodeSerializerResolver
157 protected override void Init() {
158 Register<CachePointNode, CacheNodePointSerializer>();
159 Register<CompositeNode, CompositeNodeSerializer>();
160 Register<ConstantSelectNode, ConstantSelectNodeSerializer>();
161 Register<CreateFunctionsNode, CreateFunctionNodeSerializer>();
162 Register<DistinctNode, DistinctNodeSerializer>();
163 Register<EquiJoinNode, EquiJoinNodeSerializer>();
164 Register<ExhaustiveSelectNode, ExhaustiveSelectNodeSerializer>();
165 Register<FetchTableNode, FetchTableNodeSerializer>();
166 Register<FetchViewNode, FetchViewNodeSerializer>();
167 Register<GroupNode, GroupNodeSerializer>();
168 Register<JoinNode, JoinNodeSerializer>();
169 Register<LeftOuterJoinNode, LeftOuterJoinNodeSerializer>();
170 Register<LogicalUnionNode, LogicalUnionNodeSerializer>();
171 Register<MarkerNode, MarkerNodeSerializer>();
172 Register<NaturalJoinNode, NaturalJoinNodeSerializer>();
173 Register<NonCorrelatedAnyAllNode, NonCorrelatedAnyAllNodeSerializer>();
174 Register<RangeSelectNode, RageSelectNodeSerializer>();
175 Register<SimplePatternSelectNode, SimplePatternSelectNodeSerializer>();
176 Register<SimpleSelectNode, SimpleSelectNodeSerializer>();
177 Register<SingleRowTableNode, SingleRowTableNodeSerializer>();
178 Register<SortNode, SortNodeSerializer>();
179 Register<SubsetNode, SubsetNodeSerializer>();
180 Register<LimitNode, LimitNodeSerializer>();
186 #region QueryPlanNodeSerializer
190 return nodeType == typeof (TNode);
196 #region CacheNodePointSerializer
200 WriteChildNode(writer, node.
Child);
201 writer.Write(node.
Id);
205 var child = ReadChildNode(reader);
206 var
id = reader.ReadInt64();
213 #region CompositeNodeSerializer
217 WriteChildNode(writer, node.
Left);
218 WriteChildNode(writer, node.
Right);
220 writer.Write(node.
All);
225 var left = ReadChildNode(reader);
226 var right = ReadChildNode(reader);
227 bool all = reader.ReadBoolean();
236 #region ConstantSelectNodeSerializer
240 WriteChildNode(writer, node.
Child);
245 var child = ReadChildNode(reader);
254 #region CreateFunctionNodeSerializer
258 WriteChildNode(writer, node.
Child);
259 WriteExpressions(node.
Functions, writer);
260 WriteStrings(node.
Names, writer);
264 var child = ReadChildNode(reader);
266 var functions = ReadExpressions(reader);
267 var names = ReadStrings(reader);
275 #region DistinctNodeSerializer
279 WriteChildNode(writer, node.
Child);
284 var child = ReadChildNode(reader);
285 var names = ReadObjectNames(reader);
293 #region EquiJoinNodeSerializer
297 WriteChildNode(writer, node.
Left);
298 WriteChildNode(writer, node.
Right);
305 var leftNode = ReadChildNode(reader);
306 var rightNode = ReadChildNode(reader);
308 var leftColNames = ReadObjectNames(reader);
309 var rightColNames = ReadObjectNames(reader);
311 return new EquiJoinNode(leftNode, rightNode, leftColNames, rightColNames);
317 #region ExhaustiveSelectNodeSerializer
321 WriteChildNode(writer, node.
Child);
326 var child = ReadChildNode(reader);
335 #region FetchTableNodeSerializer
353 #region FetchViewNodeSerializer
372 #region GroupNodeSerializer
376 WriteChildNode(writer, node.
Child);
381 WriteExpressions(node.
Functions, writer);
382 WriteStrings(node.
Names, writer);
386 var child = ReadChildNode(reader);
387 var colNames = ReadObjectNames(reader);
389 var functions = ReadExpressions(reader);
390 var names = ReadStrings(reader);
392 return new GroupNode(child, colNames, groupMax, functions, names);
398 #region JoinNodeSerializer
402 WriteChildNode(writer, node.
Left);
403 WriteChildNode(writer, node.
Right);
413 var left = ReadChildNode(reader);
414 var right = ReadChildNode(reader);
420 return new JoinNode(left, right, leftColumnName, op, rightExpression);
426 #region LeftOuterJoinNodeSerializer
430 WriteChildNode(writer, node.
Child);
435 var child = ReadChildNode(reader);
436 var markerName = reader.ReadString();
444 #region LogicalUnionNodeSerializer
448 WriteChildNode(writer, node.
Left);
449 WriteChildNode(writer, node.
Right);
453 var left = ReadChildNode(reader);
454 var right = ReadChildNode(reader);
462 #region MarkerNodeSerializer
466 WriteChildNode(writer, node.
Child);
471 var child = ReadChildNode(reader);
472 var markerName = reader.ReadString();
480 #region NaturalJoinNodeSerializer
484 WriteChildNode(writer, node.
Left);
485 WriteChildNode(writer, node.
Right);
489 var left = ReadChildNode(reader);
490 var right = ReadChildNode(reader);
498 #region NonCorrelatedAnyAllNodeSerializer
502 WriteChildNode(writer, node.
Left);
503 WriteChildNode(writer, node.
Right);
510 var left = ReadChildNode(reader);
511 var right = ReadChildNode(reader);
513 var columnNames = ReadObjectNames(reader);
522 #region RangeSelectNodeSerializer
526 WriteChildNode(writer, node.
Child);
531 var child = ReadChildNode(reader);
540 #region SimplePatternSelectNodeSerializer
544 WriteChildNode(writer, node.
Child);
549 var child = ReadChildNode(reader);
558 #region SimpleSelectNodeSerializer
562 WriteChildNode(writer, node.
Child);
569 var child = ReadChildNode(reader);
580 #region SingleRowTableNodeSerializer
593 #region SortNodeSerializer
597 WriteChildNode(writer, node.
Child);
599 WriteArray(node.
Ascending, writer, (b, binaryWriter) => binaryWriter.Write(b));
603 var child = ReadChildNode(reader);
604 var columnNames = ReadObjectNames(reader);
605 var ascending = ReadArray(reader, binaryReader => binaryReader.ReadBoolean());
607 return new SortNode(child, columnNames, ascending);
613 #region SubsetNodeSerializer
617 WriteChildNode(writer, node.
Child);
623 var child = ReadChildNode(reader);
624 var columnNames = ReadObjectNames(reader);
625 var aliasNames = ReadObjectNames(reader);
627 return new SubsetNode(child, columnNames, aliasNames);
633 #region LimitNodeSerializer
637 WriteChildNode(writer, obj.
Child);
639 writer.Write(obj.
Count);
643 var child = ReadChildNode(reader);
644 var offset = reader.ReadInt64();
645 var count = reader.ReadInt64();
647 return new LimitNode(child, offset, count);
override LogicalUnionNode Deserialize(BinaryReader reader)
IQueryPlanNode Right
Gets the right node of the branch query plan node.
override SingleRowTableNode Deserialize(BinaryReader reader)
override ConstantSelectNode Deserialize(BinaryReader reader)
bool All
If this is true, the composite includes all results from both children, otherwise removes deplicates...
A branch node for performing a composite function on two child nodes.
static IQueryPlanNode ReadChildNode(BinaryReader reader)
override DistinctNode Deserialize(BinaryReader reader)
string[] Names
The list of names to give each function table.
ObjectName AliasName
The name to alias the table as.
override void Serialize(DistinctNode node, BinaryWriter writer)
override FetchViewNode Deserialize(BinaryReader reader)
The execution context of a database system, that is defining the configurations and the components us...
static IQueryPlanNode Deserialize(Type nodeType, BinaryReader reader)
static IQueryPlanNode Deserialize(Type nodeType, Stream inputStream)
IQueryPlanNode Child
Gets the single child node of the plan.
static void WriteObjectNames(ObjectName[] names, BinaryWriter writer)
The node for evaluating an expression that contains entirely constant values (no variables).
SqlExpression[] Functions
A query to the database to select data from a set of tables and columns.
SqlExpression Expression
A simple expression that represents the range to select. See the class comments for a description for...
override JoinNode Deserialize(BinaryReader reader)
static void Serialize(ObjectName objectName, Stream stream)
static void WriteExpressions(SqlExpression[] expressions, BinaryWriter writer)
override void Serialize(NaturalJoinNode node, BinaryWriter writer)
override void Serialize(MarkerNode node, BinaryWriter writer)
bool CanSerialize(Type nodeType)
override void Serialize(FetchViewNode node, BinaryWriter writer)
override SimpleSelectNode Deserialize(BinaryReader reader)
Describes the name of an object within a database.
static ObjectName[] ReadObjectNames(BinaryReader reader)
override LeftOuterJoinNode Deserialize(BinaryReader reader)
override GroupNode Deserialize(BinaryReader reader)
SqlExpressionType Operator
static ObjectName Deserialize(Stream stream)
override void Serialize(LogicalUnionNode node, BinaryWriter writer)
static void Serialize(SqlExpression expression, BinaryWriter writer)
SqlExpressionType
All the possible type of SqlExpression supported
The node for performing a simple indexed query on a single column of the child node.
static void RegisterSerializers(ISystemContext context)
ObjectName LeftColumnName
A node element of a query plan tree. /summary>
The node for performing a simple select operation on a table.
A marker node that takes the result of a child and marks it as a name that can later be retrieved...
A user-defined TYPE that holds complex objects in a database column.
override void Serialize(FetchTableNode node, BinaryWriter writer)
override void Serialize(SingleRowTableNode node, BinaryWriter writer)
override SortNode Deserialize(BinaryReader reader)
ObjectName[] AliasColumnNames
The node for merging the child node with a set of new function columns over the entire result...
static void WriteStrings(string[] array, BinaryWriter writer)
static SqlExpression Deserialize(BinaryReader reader)
SqlExpression[] Functions
The list of functions to create.
override void Serialize(ExhaustiveSelectNode node, BinaryWriter writer)
static string[] ReadStrings(BinaryReader reader)
SqlExpression RightExpression
override RangeSelectNode Deserialize(BinaryReader reader)
override void Serialize(LeftOuterJoinNode node, BinaryWriter writer)
The node for performing a exhaustive select operation on the child node.
static void Serialize(IQueryPlanNode queryPlan, BinaryWriter writer)
override CachePointNode Deserialize(BinaryReader reader)
override NaturalJoinNode Deserialize(BinaryReader reader)
override CompositeNode Deserialize(BinaryReader reader)
A branch node for a left outer join.
SqlExpression Expression
The search expression.
override void Serialize(LimitNode obj, BinaryWriter writer)
override void Serialize(RangeSelectNode node, BinaryWriter writer)
ObjectName TableName
The name of the table to fetch.
ObjectName[] OriginalColumnNames
SqlExpressionType OperatorType
override void Serialize(CachePointNode node, BinaryWriter writer)
static SqlExpression[] ReadExpressions(BinaryReader reader)
CompositeFunction CompositeFunction
The composite operation.
override void Serialize(CompositeNode node, BinaryWriter writer)
ObjectName GroupMaxColumn
override LimitNode Deserialize(BinaryReader reader)
override SubsetNode Deserialize(BinaryReader reader)
override SimplePatternSelectNode Deserialize(BinaryReader reader)
void Serialize(object obj, BinaryWriter writer)
A branch node for naturally joining two tables together.
override EquiJoinNode Deserialize(BinaryReader reader)
override void Serialize(JoinNode node, BinaryWriter writer)
ObjectName[] RightColumns
override void Serialize(EquiJoinNode node, BinaryWriter writer)
override void Serialize(SortNode node, BinaryWriter writer)
override void Serialize(ConstantSelectNode node, BinaryWriter writer)
override FetchTableNode Deserialize(BinaryReader reader)
CompositeFunction
The kind of composite function in a CompositeTable.
Defines the base class for instances that represent SQL expression tree nodes.
object Deserialize(BinaryReader reader)
static void WriteChildNode(BinaryWriter writer, IQueryPlanNode node)
override void Serialize(CreateFunctionsNode node, BinaryWriter writer)
override void Serialize(SubsetNode node, BinaryWriter writer)
IQueryPlanNode Left
Gets the left node of the branch query plan node.
override CreateFunctionsNode Deserialize(BinaryReader reader)
override ExhaustiveSelectNode Deserialize(BinaryReader reader)
The node for fetching a table from the current transaction.
override MarkerNode Deserialize(BinaryReader reader)
override void Serialize(SimpleSelectNode node, BinaryWriter writer)
override void Serialize(GroupNode node, BinaryWriter writer)
override void Serialize(SimplePatternSelectNode node, BinaryWriter writer)