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

Public Member Functions

 BinaryType (SqlTypeCode typeCode)
 
 BinaryType (SqlTypeCode typeCode, int maxSize)
 
override bool IsCacheable (ISqlObject value)
 
override Type GetObjectType ()
 
override Type GetRuntimeType ()
 
override string ToString ()
 
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 bool IsComparable (SqlType type)
 Verifies if a given SqlType is comparable to this data-type. More...
 
virtual bool CanCastTo (SqlType destType)
 Verifies if this type can cast any value to the given SqlType. More...
 
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)
 

Public Attributes

const int DefaultMaxSize = Int16.MaxValue
 

Protected Member Functions

override void GetData (SerializeData data)
 
- 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)
 

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 IsBinaryType (SqlTypeCode sqlType)
 

Properties

int ISizeableType. Size [get]
 
override bool IsStorable [get]
 
int MaxSize [get, private set]
 
override bool IsIndexable [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]
 
- Properties inherited from Deveel.Data.Types.ISizeableType
int Size [get]
 

Private Member Functions

 BinaryType (ObjectData data)
 
SqlBoolean ToBoolean (ISqlBinary binary)
 

Static Private Member Functions

static void AssertIsBinary (SqlTypeCode sqlType)
 

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)
 

Detailed Description

Definition at line 27 of file BinaryType.cs.

Constructor & Destructor Documentation

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

Definition at line 30 of file BinaryType.cs.

31  : this(typeCode, DefaultMaxSize) {
32  }
Deveel.Data.Types.BinaryType.BinaryType ( SqlTypeCode  typeCode,
int  maxSize 
)
inline

Definition at line 34 of file BinaryType.cs.

35  : base("BINARY", typeCode) {
36  MaxSize = maxSize;
37  AssertIsBinary(typeCode);
38  }
static void AssertIsBinary(SqlTypeCode sqlType)
Definition: BinaryType.cs:59
Deveel.Data.Types.BinaryType.BinaryType ( ObjectData  data)
inlineprivate

Definition at line 40 of file BinaryType.cs.

41  : base(data) {
42  MaxSize = data.GetInt32("MaxSize");
43  }

Member Function Documentation

static void Deveel.Data.Types.BinaryType.AssertIsBinary ( SqlTypeCode  sqlType)
inlinestaticprivate

Definition at line 59 of file BinaryType.cs.

59  {
60  if (!IsBinaryType(sqlType))
61  throw new ArgumentException(String.Format("The SQL type {0} is not a BINARY", sqlType));
62  }
A long string in the system.
static bool IsBinaryType(SqlTypeCode sqlType)
Definition: BinaryType.cs:165
override DataObject Deveel.Data.Types.BinaryType.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 99 of file BinaryType.cs.

99  {
100  var sqlType = destType.TypeCode;
101  var binary = ((ISqlBinary) value.Value);
102 
103  ISqlObject casted;
104 
105  switch (sqlType) {
106  case SqlTypeCode.Bit:
107  casted = ToBoolean(binary);
108  break;
109  // TODO: All other casts
110  default:
111  throw new InvalidCastException();
112  }
113 
114  return new DataObject(destType, casted);
115  }
Defines the contract for a valid SQL Object
Definition: ISqlObject.cs:23
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
Defines the required contract of a SQL BINARY object
Definition: ISqlBinary.cs:25
SqlBoolean ToBoolean(ISqlBinary binary)
Definition: BinaryType.cs:88
override int Deveel.Data.Types.BinaryType.ColumnSizeOf ( ISqlObject  obj)
inlinepackagevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 117 of file BinaryType.cs.

117  {
118  if (obj is SqlBinary) {
119  var binary = (SqlBinary) obj;
120  return 1 + 4 + (int) binary.Length;
121  } else if (obj is SqlLongBinary) {
122  throw new NotImplementedException();
123  }
124 
125  throw new NotSupportedException();
126  }
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
override ISqlObject Deveel.Data.Types.BinaryType.DeserializeObject ( Stream  stream)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 149 of file BinaryType.cs.

149  {
150  var reader = new BinaryReader(stream);
151 
152  var type = reader.ReadByte();
153  if (type == 1) {
154  var length = reader.ReadInt32();
155  var bytes = reader.ReadBytes(length);
156  return new SqlBinary(bytes);
157  }
158  if (type == 2) {
159  // TODO:
160  }
161 
162  throw new FormatException();
163  }
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
override void Deveel.Data.Types.BinaryType.GetData ( SerializeData  data)
inlineprotectedvirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 64 of file BinaryType.cs.

64  {
65  data.SetValue("MaxSize", MaxSize);
66  }
void SetValue(string key, Type type, object value)
override Type Deveel.Data.Types.BinaryType.GetObjectType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 72 of file BinaryType.cs.

72  {
73  return typeof(SqlBinary);
74  }
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
override Type Deveel.Data.Types.BinaryType.GetRuntimeType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 76 of file BinaryType.cs.

76  {
77  return typeof (Stream);
78  }
static bool Deveel.Data.Types.BinaryType.IsBinaryType ( SqlTypeCode  sqlType)
inlinestaticpackage

Definition at line 165 of file BinaryType.cs.

165  {
166  return sqlType == SqlTypeCode.Binary ||
167  sqlType == SqlTypeCode.VarBinary ||
168  sqlType == SqlTypeCode.LongVarBinary ||
169  sqlType == SqlTypeCode.Blob;
170  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override bool Deveel.Data.Types.BinaryType.IsCacheable ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 68 of file BinaryType.cs.

68  {
69  return value is SqlBinary || value is SqlNull;
70  }
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
override void Deveel.Data.Types.BinaryType.SerializeObject ( Stream  stream,
ISqlObject  obj 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 128 of file BinaryType.cs.

128  {
129  var writer = new BinaryWriter(stream);
130 
131  if (obj is SqlBinary) {
132  var bin = (SqlBinary) obj;
133  writer.Write((byte)1);
134  writer.Write((int)bin.Length);
135  writer.Write(bin.ToByteArray());
136  } else if (obj is SqlLongBinary) {
137  var lob = (SqlLongBinary) obj;
138 
139  writer.Write((byte) 2);
140 
141  // TODO:
142 
143  throw new NotImplementedException();
144  } else {
145  base.SerializeObject(stream, obj);
146  }
147  }
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
SqlBoolean Deveel.Data.Types.BinaryType.ToBoolean ( ISqlBinary  binary)
inlineprivate

Definition at line 88 of file BinaryType.cs.

88  {
89  if (binary.Length != 1)
90  throw new InvalidCastException();
91 
92  var b = binary.First();
93  if (b != 0 && b != 1)
94  throw new InvalidCastException();
95 
96  return b == 1;
97  }
long Length
Gets the raw length of the binary object.
Definition: ISqlBinary.cs:29
override string Deveel.Data.Types.BinaryType.ToString ( )
inline

Definition at line 80 of file BinaryType.cs.

80  {
81  var sb = new StringBuilder(Name);
82  if (MaxSize > 0)
83  sb.AppendFormat("({0})", MaxSize);
84 
85  return sb.ToString();
86  }
string Name
Gets the name of the data-type that is used to resolve it within the context.
Definition: SqlType.cs:75

Member Data Documentation

const int Deveel.Data.Types.BinaryType.DefaultMaxSize = Int16.MaxValue

Definition at line 28 of file BinaryType.cs.

Property Documentation

override bool Deveel.Data.Types.BinaryType.IsIndexable
get

Definition at line 55 of file BinaryType.cs.

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

Definition at line 49 of file BinaryType.cs.

int Deveel.Data.Types.BinaryType.MaxSize
getprivate set

Definition at line 53 of file BinaryType.cs.

int ISizeableType. Deveel.Data.Types.BinaryType.Size
getprivate

Definition at line 45 of file BinaryType.cs.


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