DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Static Public Attributes | Package Functions | Static Package Functions | Properties | Private Member Functions | Static Private Member Functions | List of all members
Deveel.Data.Types.DateType Class Reference
Inheritance diagram for Deveel.Data.Types.DateType:
Deveel.Data.Types.SqlType Deveel.Data.Serialization.ISerializable

Public Member Functions

 DateType (SqlTypeCode typeCode)
 
override bool IsCacheable (ISqlObject value)
 
override Type GetObjectType ()
 
override Type GetRuntimeType ()
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
override bool IsComparable (SqlType type)
 Verifies if a given SqlType is comparable to this data-type. More...
 
override bool CanCastTo (SqlType destType)
 Verifies if this type can cast any value to the given SqlType. More...
 
override DataObject CastTo (DataObject value, SqlType destType)
 Converts the given object value to a SqlType specified. More...
 
override void SerializeObject (Stream stream, ISqlObject obj)
 
override ISqlObject DeserializeObject (Stream stream)
 
- Public Member Functions inherited from Deveel.Data.Types.SqlType
virtual object ConvertTo (ISqlObject obj, Type destType)
 
virtual ISqlObject Add (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Subtract (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Multiply (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Divide (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Modulus (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Negate (ISqlObject value)
 
virtual SqlBoolean IsEqualTo (ISqlObject a, ISqlObject b)
 
virtual SqlBoolean IsNotEqualTo (ISqlObject a, ISqlObject b)
 
virtual SqlBoolean IsGreatherThan (ISqlObject a, ISqlObject b)
 
virtual SqlBoolean IsSmallerThan (ISqlObject a, ISqlObject b)
 
virtual SqlBoolean IsGreaterOrEqualThan (ISqlObject a, ISqlObject b)
 
virtual SqlBoolean IsSmallerOrEqualThan (ISqlObject a, ISqlObject b)
 
virtual ISqlObject And (ISqlObject a, ISqlObject b)
 
virtual ISqlObject Or (ISqlObject a, ISqlObject b)
 
virtual ISqlObject XOr (ISqlObject x, ISqlObject y)
 
virtual ISqlObject UnaryPlus (ISqlObject value)
 
virtual ISqlObject Reverse (ISqlObject value)
 
virtual SqlType Wider (SqlType otherType)
 Gets the one data-type between this and the other one given that handles the wider range of values. More...
 
virtual int Compare (ISqlObject x, ISqlObject y)
 
override bool Equals (object obj)
 
override int GetHashCode ()
 
virtual bool Equals (SqlType other)
 
override string ToString ()
 
virtual ISqlObject CreateFromLargeObject (ILargeObject objRef)
 
virtual ISqlObject CreateFrom (object value)
 

Static Public Attributes

static readonly string[] DateFormatSql
 
static readonly string[] TimeFormatSql
 
static readonly string[] TsFormatSql
 

Package Functions

override int ColumnSizeOf (ISqlObject obj)
 
- Package Functions inherited from Deveel.Data.Types.SqlType
virtual int GetCacheUsage (ISqlObject value)
 

Static Package Functions

static bool IsDateType (SqlTypeCode sqlType)
 

Properties

override bool IsStorable [get]
 
- Properties inherited from Deveel.Data.Types.SqlType
string Name [get, private set]
 Gets the name of the data-type that is used to resolve it within the context. More...
 
SqlTypeCode TypeCode [get, private set]
 Gets the kind of SQL type this data-type handles. More...
 
virtual bool IsIndexable [get]
 Indicates if the values handled by the type can be part of an index. More...
 
bool IsPrimitive [get]
 Gets a value indicating if this data-type is primitive. More...
 
bool IsNull [get]
 
virtual bool IsStorable [get]
 

Private Member Functions

SqlString ToString (SqlDateTime dateTime)
 

Static Private Member Functions

static void AssertDateType (SqlTypeCode sqlType)
 
static SqlDateTime ToTime (SqlDateTime dateTime)
 
static SqlDateTime ToDate (SqlDateTime dateTime)
 

Additional Inherited Members

- Static Public Member Functions inherited from Deveel.Data.Types.SqlType
static SqlType Parse (string s)
 Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent. More...
 
static SqlType Parse (IContext context, string s)
 Parses a SQL formatted string that defines a data-type into a constructed SqlType object equivalent. More...
 
static bool IsPrimitiveType (SqlTypeCode typeCode)
 
static SqlType Resolve (SqlTypeCode typeCode)
 
static SqlType Resolve (SqlTypeCode typeCode, DataTypeMeta[] meta)
 
static SqlType Resolve (SqlTypeCode typeCode, DataTypeMeta[] meta, ITypeResolver resolver)
 
static SqlType Resolve (SqlTypeCode typeCode, string name)
 
static SqlType Resolve (SqlTypeCode typeCode, string name, DataTypeMeta[] meta)
 
static SqlType Resolve (string name)
 
static SqlType Resolve (string name, DataTypeMeta[] meta)
 
static SqlType Resolve (string name, DataTypeMeta[] meta, ITypeResolver resolver)
 
static SqlType Resolve (SqlTypeCode typeCode, string name, DataTypeMeta[] meta, ITypeResolver resolver)
 
- Protected Member Functions inherited from Deveel.Data.Types.SqlType
 SqlType (SqlTypeCode sqlType)
 Constructs the SqlType for the given specific SQL TYPE. More...
 
 SqlType (string name, SqlTypeCode typeCode)
 Constructs the SqlType for the given specific SQL TYPE and a given name. More...
 
 SqlType (ObjectData data)
 
virtual void GetData (SerializeData data)
 

Detailed Description

Definition at line 23 of file DateType.cs.

Constructor & Destructor Documentation

Deveel.Data.Types.DateType.DateType ( SqlTypeCode  typeCode)
inline

Definition at line 24 of file DateType.cs.

25  : base("DATE", typeCode) {
26  AssertDateType(typeCode);
27  }
static void AssertDateType(SqlTypeCode sqlType)
Definition: DateType.cs:66

Member Function Documentation

static void Deveel.Data.Types.DateType.AssertDateType ( SqlTypeCode  sqlType)
inlinestaticprivate

Definition at line 66 of file DateType.cs.

66  {
67  if (!IsDateType(sqlType))
68  throw new ArgumentException(String.Format("The SQL type {0} is not a valid DATE", sqlType), "sqlType");
69  }
A long string in the system.
static bool IsDateType(SqlTypeCode sqlType)
Definition: DateType.cs:208
override bool Deveel.Data.Types.DateType.CanCastTo ( SqlType  destType)
inlinevirtual

Verifies if this type can cast any value to the given SqlType.

Parameters
destTypeThe other type, destination of the cast, to verify.

By default, this method returns false, because cast process must be specified per type: when overriding the method CastTo, pay attention to also override this method accordingly.

Returns

CastTo

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 103 of file DateType.cs.

103  {
104  return destType is StringType || destType is DateType;
105  }
DateType(SqlTypeCode typeCode)
Definition: DateType.cs:24
override DataObject Deveel.Data.Types.DateType.CastTo ( DataObject  value,
SqlType  destType 
)
inlinevirtual

Converts the given object value to a SqlType specified.

Parameters
valueThe value to convert.
destTypeThe destination type of the conversion.

If the given destType destination type is equivalent to this type, it will return the value provided, otherwise it will throw an exception by default.

Casting values to specific types is specific to each data-type: override this method to support type-specific conversions.

When overriding this method, CanCastTo should be overridden accordingly to indicate the type supports casting.

Returns
Returns an instance of DataObject that is the result of the conversion from this data-type to the other type given.

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 129 of file DateType.cs.

129  {
130  if (destType == null)
131  throw new ArgumentNullException("destType");
132 
133  var date = (SqlDateTime) value.Value;
134  var sqlType = destType.TypeCode;
135 
136  ISqlObject casted;
137 
138  switch (sqlType) {
139  case SqlTypeCode.String:
140  case SqlTypeCode.VarChar:
141  casted = ToString(date);
142  break;
143  case SqlTypeCode.Date:
144  casted = ToDate(date);
145  break;
146  case SqlTypeCode.Time:
147  casted = ToTime(date);
148  break;
149  case SqlTypeCode.TimeStamp:
150  case SqlTypeCode.DateTime:
151  // if it is not a TimeStamp already, there's not much we can do
152  casted = date;
153  break;
154  default:
155  throw new InvalidCastException(String.Format("Cannot cast type '{0}' to '{1}'.",
156  sqlType.ToString().ToUpperInvariant(), TypeCode.ToString().ToUpperInvariant()));
157  }
158 
159  return new DataObject(destType, casted);
160  }
A long string in the system.
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
static SqlDateTime ToDate(SqlDateTime dateTime)
Definition: DateType.cs:125
static SqlDateTime ToTime(SqlDateTime dateTime)
Definition: DateType.cs:121
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
override string ToString()
Definition: SqlType.cs:395
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override int Deveel.Data.Types.DateType.ColumnSizeOf ( ISqlObject  obj)
inlinepackagevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 182 of file DateType.cs.

182  {
183  if (obj is SqlNull)
184  return 1;
185 
186  if (!(obj is SqlDateTime))
187  throw new ArgumentException(String.Format("Cannot determine the size of an object of type '{0}'", obj.GetType()));
188 
189  if (obj.IsNull)
190  return 1;
191 
192  // Type + Length + Bytes
193  return 1 + 4 + 13;
194  }
A long string in the system.
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override ISqlObject Deveel.Data.Types.DateType.DeserializeObject ( Stream  stream)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 196 of file DateType.cs.

196  {
197  var reader = new BinaryReader(stream);
198 
199  var type = reader.ReadByte();
200  if (type == 0)
201  return SqlDateTime.Null;
202 
203  var length = reader.ReadInt32();
204  var bytes = reader.ReadBytes(length);
205  return new SqlDateTime(bytes);
206  }
static readonly SqlDateTime Null
Definition: SqlDateTime.cs:24
override bool Deveel.Data.Types.DateType.Equals ( object  obj)
inline

Definition at line 87 of file DateType.cs.

87  {
88  var other = obj as SqlType;
89  if (other == null)
90  return false;
91 
92  return TypeCode == other.TypeCode;
93  }
SqlType(SqlTypeCode sqlType)
Constructs the SqlType for the given specific SQL TYPE.
Definition: SqlType.cs:43
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
override int Deveel.Data.Types.DateType.GetHashCode ( )
inline

Definition at line 95 of file DateType.cs.

95  {
96  return TypeCode.GetHashCode();
97  }
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
override Type Deveel.Data.Types.DateType.GetObjectType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 79 of file DateType.cs.

79  {
80  return typeof (SqlDateTime);
81  }
override Type Deveel.Data.Types.DateType.GetRuntimeType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 83 of file DateType.cs.

83  {
84  return typeof (DateTimeOffset);
85  }
override bool Deveel.Data.Types.DateType.IsCacheable ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 75 of file DateType.cs.

75  {
76  return value is SqlDateTime || value is SqlNull;
77  }
override bool Deveel.Data.Types.DateType.IsComparable ( SqlType  type)
inlinevirtual

Verifies if a given SqlType is comparable to this data-type.

Parameters
typeThe other data-type to verify the compatibility.

It is not required two SqlType to be identical to be compared: when overridden by a derived class, this methods verifies the properties of the argument type, to see if values handled by the types can be compared.

By default, this method compares the values returned by TypeCode to see if they are identical.

Returns
Returns true if the values handled by this data-type can be compared to ones handled by the given type , or false otherwise.

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 99 of file DateType.cs.

99  {
100  return type is DateType;
101  }
DateType(SqlTypeCode typeCode)
Definition: DateType.cs:24
static bool Deveel.Data.Types.DateType.IsDateType ( SqlTypeCode  sqlType)
inlinestaticpackage

Definition at line 208 of file DateType.cs.

208  {
209  return sqlType == SqlTypeCode.Date ||
210  sqlType == SqlTypeCode.Time ||
211  sqlType == SqlTypeCode.TimeStamp ||
212  sqlType == SqlTypeCode.DateTime;
213  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override void Deveel.Data.Types.DateType.SerializeObject ( Stream  stream,
ISqlObject  obj 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 162 of file DateType.cs.

162  {
163  var writer = new BinaryWriter(stream);
164 
165  if (obj is SqlNull) {
166  writer.Write((byte) 0);
167  } else {
168  var date = (SqlDateTime) obj;
169 
170  if (date.IsNull) {
171  writer.Write((byte)0);
172  } else {
173  var bytes = date.ToByteArray(true);
174 
175  writer.Write((byte)1);
176  writer.Write(bytes.Length);
177  writer.Write(bytes);
178  }
179  }
180  }
static SqlDateTime Deveel.Data.Types.DateType.ToDate ( SqlDateTime  dateTime)
inlinestaticprivate

Definition at line 125 of file DateType.cs.

125  {
126  return new SqlDateTime(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0, 0, dateTime.Offset);
127  }
SqlDayToSecond Offset
Gets the offset between the date-time instance and the UTC time.
Definition: SqlDateTime.cs:214
SqlString Deveel.Data.Types.DateType.ToString ( SqlDateTime  dateTime)
inlineprivate

Definition at line 107 of file DateType.cs.

107  {
108  if (dateTime.IsNull)
109  return SqlString.Null;
110 
111  if (TypeCode == SqlTypeCode.Date)
112  return dateTime.ToDateString();
113  if (TypeCode == SqlTypeCode.Time)
114  return dateTime.ToTimeString();
115  if (TypeCode == SqlTypeCode.TimeStamp)
116  return dateTime.ToTimeStampString();
117 
118  return SqlString.Null;
119  }
SqlTypeCode TypeCode
Gets the kind of SQL type this data-type handles.
Definition: SqlType.cs:91
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
static SqlDateTime Deveel.Data.Types.DateType.ToTime ( SqlDateTime  dateTime)
inlinestaticprivate

Definition at line 121 of file DateType.cs.

121  {
122  return new SqlDateTime(0, 0, 0, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, dateTime.Offset);
123  }
SqlDayToSecond Offset
Gets the offset between the date-time instance and the UTC time.
Definition: SqlDateTime.cs:214

Member Data Documentation

readonly string [] Deveel.Data.Types.DateType.DateFormatSql
static
Initial value:
= {
"yyyy-MM-dd",
"yyyy MM dd"
}

Definition at line 29 of file DateType.cs.

readonly string [] Deveel.Data.Types.DateType.TimeFormatSql
static
Initial value:
= {
"HH:mm:ss.fff z",
"HH:mm:ss.fff zz",
"HH:mm:ss.fff zzz",
"HH:mm:ss.fff",
"HH:mm:ss z",
"HH:mm:ss zz",
"HH:mm:ss zzz",
"HH:mm:ss"
}

Definition at line 34 of file DateType.cs.

readonly string [] Deveel.Data.Types.DateType.TsFormatSql
static
Initial value:
= {
"yyyy-MM-dd HH:mm:ss.fff",
"yyyy-MM-dd HH:mm:ss.fff z",
"yyyy-MM-dd HH:mm:ss.fff zz",
"yyyy-MM-dd HH:mm:ss.fff zzz",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm:ss z",
"yyyy-MM-dd HH:mm:ss zz",
"yyyy-MM-dd HH:mm:ss zzz",
"yyyy-MM-ddTHH:mm:ss.fff",
"yyyy-MM-ddTHH:mm:ss.fff z",
"yyyy-MM-ddTHH:mm:ss.fff zz",
"yyyy-MM-ddTHH:mm:ss.fff zzz",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm:ss z",
"yyyy-MM-ddTHH:mm:ss zz",
"yyyy-MM-ddTHH:mm:ss zzz",
}

Definition at line 45 of file DateType.cs.

Property Documentation

override bool Deveel.Data.Types.DateType.IsStorable
get

Definition at line 71 of file DateType.cs.


The documentation for this class was generated from the following file: