DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ViewInfo.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 
23 using Deveel.Data.Sql.Objects;
24 using Deveel.Data.Sql.Query;
25 using Deveel.Data.Sql.Tables;
26 
27 namespace Deveel.Data.Sql.Views {
28  [Serializable]
29  public sealed class ViewInfo : IObjectInfo, ISerializable {
30  public ViewInfo(TableInfo tableInfo, SqlQueryExpression queryExpression, IQueryPlanNode queryPlan) {
31  if (tableInfo == null)
32  throw new ArgumentNullException("tableInfo");
33  if (queryExpression == null)
34  throw new ArgumentNullException("queryExpression");
35 
36  TableInfo = tableInfo;
37  QueryExpression = queryExpression;
38  QueryPlan = queryPlan;
39  }
40 
41  private ViewInfo(ObjectData data) {
42  TableInfo = data.GetValue<TableInfo>("TableInfo");
43  QueryExpression = data.GetValue<SqlQueryExpression>("QueryExpression");
44  QueryPlan = data.GetValue<IQueryPlanNode>("QueryPlan");
45 
46  }
47 
48  public TableInfo TableInfo { get; private set; }
49 
50  public ObjectName ViewName {
51  get { return TableInfo.TableName; }
52  }
53 
54  public SqlQueryExpression QueryExpression { get; private set; }
55 
56  public IQueryPlanNode QueryPlan { get; private set; }
57 
59  get { return DbObjectType.View; }
60  }
61 
63  get { return ViewName; }
64  }
65 
67  data.SetValue("TableInfo", TableInfo);
68  data.SetValue("QueryPlan", QueryPlan);
69  data.SetValue("QueryExpression", QueryExpression);
70  }
71 
72  public static void Serialize(ViewInfo viewInfo, BinaryWriter writer) {
73  var serializer = new BinarySerializer();
74  serializer.Serialize(writer, viewInfo);
75  }
76 
77  public static ViewInfo Deserialize(Stream stream) {
78  var serializer = new BinarySerializer();
79  return (ViewInfo) serializer.Deserialize(stream, typeof (ViewInfo));
80  }
81 
82  //public static void Serialize(ViewInfo viewInfo, BinaryWriter writer) {
83  // TableInfo.Serialize(viewInfo.TableInfo, writer);
84  // SqlExpression.Serialize(viewInfo.QueryExpression, writer);
85 
86  // var queryPlanType = viewInfo.QueryPlan.GetType();
87  // writer.Write(queryPlanType.FullName);
88  // QueryPlanSerializers.Serialize(viewInfo.QueryPlan, writer);
89  //}
90 
91  //public static ViewInfo Deserialize(Stream stream, ITypeResolver resolver) {
92  // var reader = new BinaryReader(stream, Encoding.Unicode);
93  // return Deserialize(reader, resolver);
94  //}
95 
96  //public static ViewInfo Deserialize(BinaryReader reader, ITypeResolver typeResolver) {
97  // var tableInfo = TableInfo.Deserialize(reader, typeResolver);
98  // var expression = SqlExpression.Deserialize(reader);
99 
100  // if (!(expression is SqlQueryExpression))
101  // throw new InvalidOperationException();
102 
103  // var queryExpression = (SqlQueryExpression) expression;
104 
105  // var queryPlanTypeString = reader.ReadString();
106  // var queryPlanType = Type.GetType(queryPlanTypeString, true);
107  // var queryPlan = QueryPlanSerializers.Deserialize(queryPlanType, reader);
108 
109  // return new ViewInfo(tableInfo, queryExpression, queryPlan);
110  //}
111 
112  public SqlBinary AsBinary() {
113  using (var stream = new MemoryStream()) {
114  using (var writer = new BinaryWriter(stream, Encoding.Unicode)) {
115  var serializer = new BinarySerializer();
116  serializer.Serialize(writer, this);
117  writer.Flush();
118  }
119 
120  var data = stream.ToArray();
121  return new SqlBinary(data);
122  }
123  }
124  }
125 }
ViewInfo(TableInfo tableInfo, SqlQueryExpression queryExpression, IQueryPlanNode queryPlan)
Definition: ViewInfo.cs:30
void GetData(SerializeData data)
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
static ViewInfo Deserialize(Stream stream)
Definition: ViewInfo.cs:77
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static void Serialize(ViewInfo viewInfo, BinaryWriter writer)
Definition: ViewInfo.cs:72
ObjectName TableName
Gets the fully qualified name of the table that is ensured to be unique within the system...
Definition: TableInfo.cs:97
A node element of a query plan tree. /summary>
ViewInfo(ObjectData data)
Definition: ViewInfo.cs:41
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
Defines the metadata properties of a table existing within a database.
Definition: TableInfo.cs:41