DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
VariableManager.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.Collections.Generic;
19 
20 using Deveel.Data.Types;
21 
22 namespace Deveel.Data.Sql.Variables {
23  public sealed class VariableManager : IVariableManager {
24  private Dictionary<string, Variable> variables;
25 
27  Scope = scope;
28 
29  variables = new Dictionary<string, Variable>();
30  }
31 
32  public IVariableScope Scope { get; private set; }
33 
34  public void Dispose() {
35  Dispose(true);
36  GC.SuppressFinalize(this);
37  }
38 
39  private void Dispose(bool disposing) {
40  if (disposing) {
41  if (variables != null)
42  variables.Clear();
43  }
44 
45  variables = null;
46  }
47 
48  public Variable DefineVariable(VariableInfo variableInfo) {
49  if (variableInfo == null)
50  throw new ArgumentNullException("variableInfo");
51 
52  if (variables.ContainsKey(variableInfo.VariableName))
53  throw new ArgumentException();
54 
55  var variable = new Variable(variableInfo);
56  variables[variableInfo.VariableName] = variable;
57  return variable;
58  }
59 
60  public bool VariableExists(string name) {
61  return variables.ContainsKey(name);
62  }
63 
64  public Variable GetVariable(string name) {
65  Variable variable;
66  if (!variables.TryGetValue(name, out variable))
67  return null;
68 
69  return variable;
70  }
71 
72  public bool DropVariable(string name) {
73  return variables.Remove(name);
74  }
75 
77  Variable variable;
78  if (!variables.TryGetValue(variableName.Name, out variable))
79  return null;
80 
81  return variable.Value;
82  }
83 
85  Variable variable;
86  if (!variables.TryGetValue(variableName.Name, out variable))
87  return null;
88 
89  return variable.Type;
90  }
91  }
92 }
DataObject Resolve(ObjectName variable)
Returns the value of a given variable.
Describes the name of an object within a database.
Definition: ObjectName.cs:44
Variable DefineVariable(VariableInfo variableInfo)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
Dictionary< string, Variable > variables
An interface to resolve a variable name to a constant object.
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
SqlType ReturnType(ObjectName variable)
Returns the SqlType of object the given variable is.