DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Static Public Member Functions | Public Attributes | Properties | Private Member Functions | List of all members
Deveel.Data.Sql.ObjectName Class Reference

Describes the name of an object within a database. More...

Inheritance diagram for Deveel.Data.Sql.ObjectName:
Deveel.Data.Serialization.ISerializable

Public Member Functions

 ObjectName (string name)
 Constructs a name reference without a parent. More...
 
 ObjectName (ObjectName parent, string name)
 Constructs a name reference with a given parent. More...
 
ObjectName Child (string name)
 Creates a reference what is the child of the current one. More...
 
ObjectName Child (ObjectName childName)
 
int CompareTo (ObjectName other)
 Compares this instance of the object reference to a given one and returns a value indicating if the two instances equivales. More...
 
override string ToString ()
 
override bool Equals (object obj)
 
bool Equals (ObjectName other)
 
bool Equals (ObjectName other, bool ignoreCase)
 Compares this object name with the other one given, according to the case sensitivity specified. More...
 
override int GetHashCode ()
 

Static Public Member Functions

static ObjectName Parse (string s)
 Parses the given string into a ObjectName object. More...
 
static ObjectName ResolveSchema (string schemaName, string name)
 Creates a new reference to a table, given a schema and a table name. More...
 
static void Serialize (ObjectName objectName, Stream stream)
 
static void Serialize (ObjectName objectName, BinaryWriter writer)
 
static ObjectName Deserialize (Stream stream)
 
static ObjectName Deserialize (BinaryReader reader)
 

Public Attributes

const string GlobName = "*"
 The special name used as a wild-card to indicate all the columns of a table must be referenced in a given context. More...
 
const char Separator = '.'
 The character that separates a name from its parent or child. More...
 

Properties

ObjectName Parent [get, private set]
 Gets the parent reference of the current one, if any or null if none. More...
 
string ParentName [get]
 
string Name [get, private set]
 Gets the name of the object being referenced. More...
 
string FullName [get]
 Gets the full reference name formatted. More...
 
bool IsGlob [get]
 Indicates if this reference equivales to GlobName. More...
 

Private Member Functions

 ObjectName (ObjectData graph)
 
void ISerializable. GetData (SerializeData graph)
 

Detailed Description

Describes the name of an object within a database.

The name of an object is composed by multiple parts, depending on the level of nesting of the object this name references.

For example, a reference to a table will be composed by the name of the schema and the name of the table: Schema.Table, while a reference to a column will be composed by the name of the schema, the name of the parent table and the name of the column itself: Schema.Table.Column.

Depending on the xecution context, parts of the name can be omitted and will be resolved at run-time.

Definition at line 44 of file ObjectName.cs.

Constructor & Destructor Documentation

Deveel.Data.Sql.ObjectName.ObjectName ( string  name)
inline

Constructs a name reference without a parent.

Parameters
nameThe object name.

NOTE: This constructor is intended to be handling a name with no parent: if the string provided as name contains any Separator character, this will make the resolution to fail at run-time. User Parse method to obtain a reference tree.

Exceptions
ArgumentNullExceptionIf name is null or empty.
See also
ObjectName(ObjectName, String)

Definition at line 71 of file ObjectName.cs.

72  : this(null, name) {
73  }
Deveel.Data.Sql.ObjectName.ObjectName ( ObjectName  parent,
string  name 
)
inline

Constructs a name reference with a given parent.

Parameters
parentThe parent reference of the one being constructed
nameThe name of the object.
Exceptions
ArgumentNullExceptionIf name is null or empty.

Definition at line 83 of file ObjectName.cs.

83  {
84  if (String.IsNullOrEmpty(name))
85  throw new ArgumentNullException("name");
86 
87  Name = name;
88  Parent = parent;
89  }
A long string in the system.
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
Deveel.Data.Sql.ObjectName.ObjectName ( ObjectData  graph)
inlineprivate

Definition at line 91 of file ObjectName.cs.

91  {
92  Name = graph.GetString("Name");
93  Parent = graph.GetValue<ObjectName>("Parent");
94  }
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108

Member Function Documentation

ObjectName Deveel.Data.Sql.ObjectName.Child ( string  name)
inline

Creates a reference what is the child of the current one.

Parameters
nameThe name of the child rerefence.
Returns
Returns an istance of ObjectName that has this one as parent, and is named by the given name .

Definition at line 189 of file ObjectName.cs.

189  {
190  return new ObjectName(this, name);
191  }
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
ObjectName Deveel.Data.Sql.ObjectName.Child ( ObjectName  childName)
inline

Definition at line 193 of file ObjectName.cs.

193  {
194  var baseName = this;
195  ObjectName parent = childName.Parent;
196  while (parent != null) {
197  baseName = baseName.Child(parent.Name);
198  parent = parent.Parent;
199  }
200 
201  baseName = baseName.Child(childName.Name);
202  return baseName;
203  }
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
int Deveel.Data.Sql.ObjectName.CompareTo ( ObjectName  other)
inline

Compares this instance of the object reference to a given one and returns a value indicating if the two instances equivales.

Parameters
otherThe other object reference to compare.
Returns

Definition at line 211 of file ObjectName.cs.

211  {
212  if (other == null)
213  return -1;
214 
215  int v = 0;
216  if (Parent != null)
217  v = Parent.CompareTo(other.Parent);
218 
219  if (v == 0)
220  v = String.Compare(Name, other.Name, StringComparison.Ordinal);
221 
222  return v;
223  }
A long string in the system.
int CompareTo(ObjectName other)
Compares this instance of the object reference to a given one and returns a value indicating if the t...
Definition: ObjectName.cs:211
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
static ObjectName Deveel.Data.Sql.ObjectName.Deserialize ( Stream  stream)
inlinestatic

Definition at line 311 of file ObjectName.cs.

311  {
312  using (var reader = new BinaryReader(stream, Encoding.Unicode)) {
313  return Deserialize(reader);
314  }
315  }
static ObjectName Deserialize(Stream stream)
Definition: ObjectName.cs:311
static ObjectName Deveel.Data.Sql.ObjectName.Deserialize ( BinaryReader  reader)
inlinestatic

Definition at line 317 of file ObjectName.cs.

317  {
318  var status = reader.ReadByte();
319  if (status == 0)
320  return null;
321 
322  ObjectName parent = null;
323 
324  var parentStatus = reader.ReadByte();
325  if (parentStatus == 1)
326  parent = Deserialize(reader);
327 
328  var name = reader.ReadString();
329  return new ObjectName(parent, name);
330  }
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
static ObjectName Deserialize(Stream stream)
Definition: ObjectName.cs:311
override bool Deveel.Data.Sql.ObjectName.Equals ( object  obj)
inline

Definition at line 241 of file ObjectName.cs.

241  {
242  var other = obj as ObjectName;
243  if (other == null)
244  return false;
245 
246  return Equals(other);
247  }
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
override bool Equals(object obj)
Definition: ObjectName.cs:241
bool Deveel.Data.Sql.ObjectName.Equals ( ObjectName  other)
inline

Definition at line 249 of file ObjectName.cs.

249  {
250  return Equals(other, true);
251  }
override bool Equals(object obj)
Definition: ObjectName.cs:241
bool Deveel.Data.Sql.ObjectName.Equals ( ObjectName  other,
bool  ignoreCase 
)
inline

Compares this object name with the other one given, according to the case sensitivity specified.

Parameters
otherThe other ObjectName to compare.
ignoreCaseThe specification to either ignore the case for comparison.
Returns
Returns true if the two instances are equal, according to the case sensitivity given, or false otherwise.

Definition at line 263 of file ObjectName.cs.

263  {
264  if (other == null)
265  return false;
266 
267  if (Parent != null && other.Parent == null)
268  return false;
269  if (Parent == null && other.Parent != null)
270  return false;
271 
272  if (Parent != null && !Parent.Equals(other.Parent, ignoreCase))
273  return false;
274 
275  var comparison = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
276  return String.Equals(Name, other.Name, comparison);
277  }
A long string in the system.
override bool Equals(object obj)
Definition: ObjectName.cs:241
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
void ISerializable. Deveel.Data.Sql.ObjectName.GetData ( SerializeData  graph)
inlineprivate

Implements Deveel.Data.Serialization.ISerializable.

Definition at line 236 of file ObjectName.cs.

236  {
237  graph.SetValue("Name", Name);
238  graph.SetValue("Parent", Parent);
239  }
void SetValue(string key, Type type, object value)
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
override int Deveel.Data.Sql.ObjectName.GetHashCode ( )
inline

Definition at line 279 of file ObjectName.cs.

279  {
280  var code = Name.GetHashCode() ^ 5623;
281  if (Parent != null)
282  code ^= Parent.GetHashCode();
283 
284  return code;
285  }
override int GetHashCode()
Definition: ObjectName.cs:279
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
static ObjectName Deveel.Data.Sql.ObjectName.Parse ( string  s)
inlinestatic

Parses the given string into a ObjectName object.

Parameters
sThe string to parse
Returns
Returns an instance of ObjectName that is the result of parsing of the string given.
Exceptions
FormatExceptionIf the given input string is of an invalid format.
ArgumentNullExceptionIf the given string is null or empty.

Definition at line 139 of file ObjectName.cs.

139  {
140  if (String.IsNullOrEmpty(s))
141  throw new ArgumentNullException("s");
142 
143  var sp = s.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
144  if (sp.Length == 0)
145  throw new FormatException("At least one part of the name must be provided");
146 
147  if (sp.Length == 1)
148  return new ObjectName(sp[0]);
149 
150  ObjectName finalName = null;
151  for (int i = 0; i < sp.Length; i++) {
152  if (finalName == null) {
153  finalName = new ObjectName(sp[i]);
154  } else {
155  finalName = new ObjectName(finalName, sp[i]);
156  }
157  }
158 
159  return finalName;
160  }
A long string in the system.
ObjectName(string name)
Constructs a name reference without a parent.
Definition: ObjectName.cs:71
static ObjectName Deveel.Data.Sql.ObjectName.ResolveSchema ( string  schemaName,
string  name 
)
inlinestatic

Creates a new reference to a table, given a schema and a table name.

Parameters
schemaNameThe name of the schema that is the parent of the given table.
nameThe name of the table to reference.
Returns
Returns an instance of ObjectName that references a table within the given schema.

Definition at line 172 of file ObjectName.cs.

172  {
173  var sb = new StringBuilder();
174  if (!String.IsNullOrEmpty(schemaName))
175  sb.Append(schemaName).Append('.');
176  sb.Append(name);
177 
178  return Parse(sb.ToString());
179  }
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
A long string in the system.
static void Deveel.Data.Sql.ObjectName.Serialize ( ObjectName  objectName,
Stream  stream 
)
inlinestatic

Definition at line 287 of file ObjectName.cs.

287  {
288  using (var writer = new BinaryWriter(stream, Encoding.Unicode)) {
289  Serialize(objectName, writer);
290  }
291  }
static void Serialize(ObjectName objectName, Stream stream)
Definition: ObjectName.cs:287
static void Deveel.Data.Sql.ObjectName.Serialize ( ObjectName  objectName,
BinaryWriter  writer 
)
inlinestatic

Definition at line 293 of file ObjectName.cs.

293  {
294  if (objectName == null) {
295  writer.Write((byte) 0);
296  return;
297  }
298 
299  writer.Write((byte)1);
300 
301  if (objectName.Parent != null) {
302  writer.Write((byte) 1);
303  Serialize(objectName.Parent, writer);
304  } else {
305  writer.Write((byte)0);
306  }
307 
308  writer.Write(objectName.Name);
309  }
static void Serialize(ObjectName objectName, Stream stream)
Definition: ObjectName.cs:287
override string Deveel.Data.Sql.ObjectName.ToString ( )
inline

Definition at line 225 of file ObjectName.cs.

225  {
226  var sb = new StringBuilder();
227  if (Parent != null) {
228  sb.Append(Parent);
229  sb.Append('.');
230  }
231 
232  sb.Append(Name);
233  return sb.ToString();
234  }
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108

Member Data Documentation

const string Deveel.Data.Sql.ObjectName.GlobName = "*"

The special name used as a wild-card to indicate all the columns of a table must be referenced in a given context.

Definition at line 49 of file ObjectName.cs.

const char Deveel.Data.Sql.ObjectName.Separator = '.'

The character that separates a name from its parent or child.

Definition at line 54 of file ObjectName.cs.

Property Documentation

string Deveel.Data.Sql.ObjectName.FullName
get

Gets the full reference name formatted.

See also
ToString()

Definition at line 114 of file ObjectName.cs.

bool Deveel.Data.Sql.ObjectName.IsGlob
get

Indicates if this reference equivales to GlobName.

Definition at line 121 of file ObjectName.cs.

string Deveel.Data.Sql.ObjectName.Name
getprivate set

Gets the name of the object being referenced.

Definition at line 108 of file ObjectName.cs.

ObjectName Deveel.Data.Sql.ObjectName.Parent
getprivate set

Gets the parent reference of the current one, if any or null if none.

Definition at line 99 of file ObjectName.cs.

string Deveel.Data.Sql.ObjectName.ParentName
get

Definition at line 101 of file ObjectName.cs.


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