DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlTableColumn.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 
22 using Deveel.Data.Types;
23 
24 namespace Deveel.Data.Sql.Statements {
25  [Serializable]
26  public sealed class SqlTableColumn : IPreparable, ISerializable {
27  public SqlTableColumn(string columnName, SqlType columnType) {
28  if (String.IsNullOrEmpty(columnName))
29  throw new ArgumentNullException("columnName");
30  if (columnType == null)
31  throw new ArgumentNullException("columnType");
32 
33  ColumnName = columnName;
34  ColumnType = columnType;
35  }
36 
37  private SqlTableColumn(ObjectData data) {
38  ColumnName = data.GetString("ColumnName");
39  ColumnType = data.GetValue<SqlType>("ColumnType");
40  IsIdentity = data.GetBoolean("IsIdentity");
41  IsNotNull = data.GetBoolean("IsNotNull");
42  DefaultExpression = data.GetValue<SqlExpression>("Default");
43  }
44 
45  public string ColumnName { get; private set; }
46 
47  public SqlType ColumnType { get; private set; }
48 
49  public bool IsIdentity { get; set; }
50 
51  public SqlExpression DefaultExpression { get; set; }
52 
53  public bool HasDefaultExpression {
54  get { return DefaultExpression != null; }
55  }
56 
57  public bool IsNotNull { get; set; }
58 
60  var column = new SqlTableColumn(ColumnName, ColumnType);
61  if (DefaultExpression != null)
62  column.DefaultExpression = DefaultExpression.Prepare(preparer);
63 
64  column.IsNotNull = IsNotNull;
65  return column;
66  }
67 
68  //public static SqlTableColumn Deserialize(BinaryReader reader) {
69  // // TODO: Type resolver!!
70  // var columnName = reader.ReadString();
71  // var columnType = TypeSerializer.Deserialize(reader, null);
72  // var notNull = reader.ReadBoolean();
73  // var identity = reader.ReadBoolean();
74  // var defaultExpression = SqlExpression.Deserialize(reader);
75  // return new SqlTableColumn(columnName, columnType) {
76  // IsNotNull = notNull,
77  // IsIdentity = identity,
78  // DefaultExpression = defaultExpression
79  // };
80  //}
81 
82  //public static void Serialize(SqlTableColumn column, BinaryWriter writer) {
83  // writer.Write(column.ColumnName);
84  // TypeSerializer.SerializeTo(writer, column.ColumnType);
85  // writer.Write(column.IsNotNull);
86  // writer.Write(column.IsIdentity);
87  // SqlExpression.Serialize(column.DefaultExpression, writer);
88  //}
89 
91  data.SetValue("ColumnName", ColumnName);
92  data.SetValue("ColumnType", ColumnType);
93  data.SetValue("IsNotNull", IsNotNull);
94  data.SetValue("IsIdentity", IsIdentity);
95  data.SetValue("Default", DefaultExpression);
96  }
97  }
98 }
void GetData(SerializeData data)
SqlTableColumn(string columnName, SqlType columnType)
A long string in the system.
void SetValue(string key, Type type, object value)
An interface used to prepare a SqlExpression object.
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
object Prepare(IExpressionPreparer preparer)
Converts the underlying value of this instance into an object that can be evaluated by an expression...
Defines the base class for instances that represent SQL expression tree nodes.
A contract for objects that participate to a SqlExpression.Prepare phase of an expression evaluation...
Definition: IPreparable.cs:30