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

Public Member Functions

 BooleanType (SqlTypeCode typeCode)
 
override bool IsCacheable (ISqlObject value)
 
override Type GetObjectType ()
 
override Type GetRuntimeType ()
 
override int Compare (ISqlObject x, ISqlObject y)
 
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 ISqlObject Negate (ISqlObject value)
 
override void SerializeObject (Stream stream, ISqlObject obj)
 
override ISqlObject DeserializeObject (Stream stream)
 
override ISqlObject Reverse (ISqlObject value)
 
override ISqlObject And (ISqlObject a, ISqlObject b)
 
override ISqlObject Or (ISqlObject a, ISqlObject b)
 
override ISqlObject XOr (ISqlObject a, ISqlObject b)
 
- 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 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 UnaryPlus (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...
 
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)
 

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 IsBooleanType (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

 BooleanType (ObjectData data)
 

Static Private Member Functions

static void AssertIsBoolean (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)
 
- 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 26 of file BooleanType.cs.

Constructor & Destructor Documentation

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

Definition at line 27 of file BooleanType.cs.

28  : base("BOOLEAN", typeCode) {
29  AssertIsBoolean(typeCode);
30  }
static void AssertIsBoolean(SqlTypeCode sqlType)
Definition: BooleanType.cs:36
Deveel.Data.Types.BooleanType.BooleanType ( ObjectData  data)
inlineprivate

Definition at line 32 of file BooleanType.cs.

33  : base(data) {
34  }

Member Function Documentation

override ISqlObject Deveel.Data.Types.BooleanType.And ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 164 of file BooleanType.cs.

164  {
165  if (a.IsNull || b.IsNull)
166  return SqlBoolean.Null;
167 
168  var b1 = (SqlBoolean) a;
169  var b2 = (SqlBoolean) b;
170 
171  return b1.And(b2);
172  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
static void Deveel.Data.Types.BooleanType.AssertIsBoolean ( SqlTypeCode  sqlType)
inlinestaticprivate

Definition at line 36 of file BooleanType.cs.

36  {
37  if (!IsBooleanType(sqlType))
38  throw new ArgumentException(String.Format("The SQL type {0} is not BOOLEAN.", sqlType));
39  }
static bool IsBooleanType(SqlTypeCode sqlType)
Definition: BooleanType.cs:41
A long string in the system.
override bool Deveel.Data.Types.BooleanType.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 84 of file BooleanType.cs.

84  {
85  return destType is StringType ||
86  destType is NumericType ||
87  destType is BinaryType ||
88  destType is BooleanType;
89  }
BooleanType(SqlTypeCode typeCode)
Definition: BooleanType.cs:27
override DataObject Deveel.Data.Types.BooleanType.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 91 of file BooleanType.cs.

91  {
92  var bValue = ((SqlBoolean) value.Value);
93  if (destType is StringType) {
94  var s = Convert.ToString(bValue);
95  // TODO: Provide a method in StringType to build a string specific to the type
96  return new DataObject(destType, new SqlString(s));
97  }
98  if (destType is NumericType) {
99  SqlNumber num;
100  if (bValue == SqlBoolean.Null) {
101  num = SqlNumber.Null;
102  } else if (bValue) {
103  num = SqlNumber.One;
104  } else {
105  num = SqlNumber.Zero;
106  }
107 
108  return new DataObject(destType, num);
109  }
110  if (destType is BinaryType) {
111  var bytes = (byte[]) Convert.ChangeType(bValue, typeof (byte[]), CultureInfo.InvariantCulture);
112  return new DataObject(destType, new SqlBinary(bytes));
113  }
114  if (destType is BooleanType)
115  return value;
116 
117  return base.CastTo(value, destType);
118  }
BooleanType(SqlTypeCode typeCode)
Definition: BooleanType.cs:27
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
Definition: SqlBinary.cs:27
static readonly SqlNumber Zero
Definition: SqlNumber.cs:29
static readonly SqlNumber Null
Definition: SqlNumber.cs:31
static readonly SqlNumber One
Definition: SqlNumber.cs:30
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
Deveel.Data.Sql.Objects.SqlString SqlString
Definition: DataObject.cs:27
override int Deveel.Data.Types.BooleanType.ColumnSizeOf ( ISqlObject  obj)
inlinepackagevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 156 of file BooleanType.cs.

156  {
157  return obj.IsNull ? 1 : 1 + 1;
158  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
override int Deveel.Data.Types.BooleanType.Compare ( ISqlObject  x,
ISqlObject  y 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 62 of file BooleanType.cs.

62  {
63  if (!(x is SqlBoolean))
64  throw new ArgumentException();
65 
66  var a = (SqlBoolean) x;
67  SqlBoolean b;
68 
69  if (y is SqlNumber) {
70  b = ((SqlNumber) y) == SqlNumber.One ? SqlBoolean.True : ((SqlNumber) y) == SqlNumber.Zero ? SqlBoolean.False : SqlBoolean.Null;
71  } else if (y is SqlBoolean) {
72  b = (SqlBoolean) y;
73  } else {
74  throw new ArgumentException();
75  }
76 
77  return a.CompareTo(b);
78  }
static readonly SqlBoolean True
Represents the materialization of a true boolean.
Definition: SqlBoolean.cs:41
static readonly SqlBoolean False
Represents the materialization of a false boolean.
Definition: SqlBoolean.cs:46
static readonly SqlBoolean Null
Defines a null boolean.
Definition: SqlBoolean.cs:51
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override ISqlObject Deveel.Data.Types.BooleanType.DeserializeObject ( Stream  stream)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 145 of file BooleanType.cs.

145  {
146  var reader = new BinaryReader(stream);
147 
148  var type = reader.ReadByte();
149  if (type == 0)
150  return SqlBoolean.Null;
151 
152  var value = reader.ReadByte();
153  return new SqlBoolean(value);
154  }
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override Type Deveel.Data.Types.BooleanType.GetObjectType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 54 of file BooleanType.cs.

54  {
55  return typeof (SqlBoolean);
56  }
override Type Deveel.Data.Types.BooleanType.GetRuntimeType ( )
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 58 of file BooleanType.cs.

58  {
59  return typeof(bool);
60  }
static bool Deveel.Data.Types.BooleanType.IsBooleanType ( SqlTypeCode  sqlType)
inlinestaticpackage

Definition at line 41 of file BooleanType.cs.

41  {
42  return (sqlType == SqlTypeCode.Bit ||
43  sqlType == SqlTypeCode.Boolean);
44  }
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
Definition: SqlTypeCode.cs:23
override bool Deveel.Data.Types.BooleanType.IsCacheable ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 50 of file BooleanType.cs.

50  {
51  return value is SqlBoolean || value is SqlNull;
52  }
override bool Deveel.Data.Types.BooleanType.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 80 of file BooleanType.cs.

80  {
81  return type is BooleanType || type is NumericType;
82  }
BooleanType(SqlTypeCode typeCode)
Definition: BooleanType.cs:27
override ISqlObject Deveel.Data.Types.BooleanType.Negate ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 120 of file BooleanType.cs.

120  {
121  var b = (SqlBoolean) value;
122  return b.Not();
123  }
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override ISqlObject Deveel.Data.Types.BooleanType.Or ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 174 of file BooleanType.cs.

174  {
175  if (a.IsNull || b.IsNull)
176  return SqlBoolean.Null;
177 
178  var b1 = (SqlBoolean)a;
179  var b2 = (SqlBoolean)b;
180 
181  return b1.Or(b2);
182  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override ISqlObject Deveel.Data.Types.BooleanType.Reverse ( ISqlObject  value)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 160 of file BooleanType.cs.

160  {
161  return Negate(value);
162  }
override ISqlObject Negate(ISqlObject value)
Definition: BooleanType.cs:120
override void Deveel.Data.Types.BooleanType.SerializeObject ( Stream  stream,
ISqlObject  obj 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 125 of file BooleanType.cs.

125  {
126  var writer = new BinaryWriter(stream);
127 
128  if (obj is SqlNull) {
129  writer.Write((byte)0);
130  } else if (obj is SqlBoolean) {
131  var b = (SqlBoolean)obj;
132 
133  if (b.IsNull) {
134  writer.Write((byte)0);
135  } else {
136  var value = (bool)b;
137  writer.Write((byte)1);
138  writer.Write((byte)(value ? 1 : 0));
139  }
140  } else {
141  throw new ArgumentException("Cannot serialize an object that is not a BOOLEAN using a boolean type.");
142  }
143  }
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26
override ISqlObject Deveel.Data.Types.BooleanType.XOr ( ISqlObject  a,
ISqlObject  b 
)
inlinevirtual

Reimplemented from Deveel.Data.Types.SqlType.

Definition at line 184 of file BooleanType.cs.

184  {
185  if (a.IsNull || b.IsNull)
186  return SqlBoolean.Null;
187 
188  var b1 = (SqlBoolean)a;
189  var b2 = (SqlBoolean)b;
190 
191  return b1.And(b2);
192  }
bool IsNull
Gets a boolean value indicating if the object is NULL.
Definition: ISqlObject.cs:28
Deveel.Data.Sql.Objects.SqlBoolean SqlBoolean
Definition: DataObject.cs:26

Property Documentation

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

Definition at line 46 of file BooleanType.cs.


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