DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
JoinPart.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 
21 
22 namespace Deveel.Data.Sql.Expressions {
23  [Serializable]
24  public sealed class JoinPart : ISerializable {
25  internal JoinPart(JoinType joinType, ObjectName tableName, SqlExpression onExpression) {
26  if (tableName == null)
27  throw new ArgumentNullException("tableName");
28 
29  OnExpression = onExpression;
30  JoinType = joinType;
31  TableName = tableName;
32  }
33 
34  internal JoinPart(JoinType joinType, SqlQueryExpression subQuery, SqlExpression onExpression) {
35  if (subQuery == null)
36  throw new ArgumentNullException("subQuery");
37 
38  OnExpression = onExpression;
39  JoinType = joinType;
40  SubQuery = subQuery;
41  }
42 
43  private JoinPart(ObjectData data) {
44  TableName = data.GetValue<ObjectName>("Table");
45  SubQuery = data.GetValue<SqlQueryExpression>("SubQuery");
46  JoinType = (JoinType) data.GetInt32("JoinType");
47  OnExpression = data.GetValue<SqlExpression>("On");
48  }
49 
50  public JoinType JoinType { get; private set; }
51 
52  public ObjectName TableName { get; private set; }
53 
54  public SqlQueryExpression SubQuery { get; private set; }
55 
56  public SqlExpression OnExpression { get; private set; }
57 
59  data.SetValue("Table", TableName);
60  data.SetValue("SubQuery", SubQuery);
61  data.SetValue("JoinType", (int)JoinType);
62  data.SetValue("On", OnExpression);
63  }
64 
65  //public static void Serialize(JoinPart joinPart, BinaryWriter writer) {
66  // writer.Write((byte)joinPart.JoinType);
67 
68  // if (joinPart.SubQuery != null) {
69  // writer.Write((byte)2);
70  // SqlExpression.Serialize(joinPart.SubQuery, writer);
71  // } else {
72  // writer.Write((byte)1);
73  // ObjectName.Serialize(joinPart.TableName, writer);
74  // }
75 
76  // SqlExpression.Serialize(joinPart.OnExpression, writer);
77  //}
78 
79  //public static JoinPart Deserialize(BinaryReader reader) {
80  // var joinType = (JoinType) reader.ReadByte();
81 
82  // var joinSourceType = reader.ReadByte();
83 
84  // SqlQueryExpression subQuery = null;
85  // ObjectName tableName = null;
86 
87  // if (joinSourceType == 1) {
88  // tableName = ObjectName.Deserialize(reader);
89  // } else if (joinSourceType == 2) {
90  // subQuery = (SqlQueryExpression) SqlExpression.Deserialize(reader);
91  // } else {
92  // throw new FormatException();
93  // }
94 
95  // var onExpression = SqlExpression.Deserialize(reader);
96 
97  // if (joinSourceType == 1)
98  // return new JoinPart(joinType, tableName, onExpression);
99 
100  // return new JoinPart(joinType, subQuery, onExpression);
101  //}
102  }
103 }
void GetData(SerializeData data)
JoinType
Enumerates the kind of group join in a selection query.
Definition: JoinType.cs:23
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
JoinPart(JoinType joinType, ObjectName tableName, SqlExpression onExpression)
Definition: JoinPart.cs:25
Defines the base class for instances that represent SQL expression tree nodes.
JoinPart(JoinType joinType, SqlQueryExpression subQuery, SqlExpression onExpression)
Definition: JoinPart.cs:34