DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Package Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.DatabaseSystem Class Reference
Inheritance diagram for Deveel.Data.DatabaseSystem:
Deveel.Data.ISystem Deveel.Data.IDatabaseHandler Deveel.Data.Diagnostics.IEventSource

Public Member Functions

IDatabase GetDatabase (string databaseName)
 
void Dispose ()
 
IEnumerable< string > GetDatabases ()
 
IDatabase CreateDatabase (IConfiguration configuration, string adminUser, string adminPassword)
 
IDatabase OpenDatabase (IConfiguration configuration)
 
bool DatabaseExists (string databaseName)
 
bool DeleteDatabase (string databaseName)
 

Package Functions

 DatabaseSystem (ISystemContext context, IEnumerable< ModuleInfo > modules)
 
void RemoveDatabase (Database database)
 

Properties

IEnumerable< ModuleInfoModules [get, private set]
 
IEventSource IEventSource. ParentSource [get]
 
IEnumerable< KeyValuePair< string, object > > IEventSource. Metadata [get]
 
IContext IEventSource. Context [get]
 
ISystemContext Context [get, private set]
 
IConfiguration Configuration [get]
 
- Properties inherited from Deveel.Data.ISystem
IEnumerable< ModuleInfoModules [get]
 
new ISystemContext Context [get]
 
- Properties inherited from Deveel.Data.Diagnostics.IEventSource
IContext Context [get]
 
IEventSource ParentSource [get]
 Gets an optional parent source. More...
 
IEnumerable< KeyValuePair< string, object > > Metadata [get]
 Gets the list of metadata associated to the source. More...
 

Private Member Functions

 ~DatabaseSystem ()
 
void CreateMetadata ()
 
void Dispose (bool disposing)
 

Private Attributes

IDictionary< string, object > metadata
 
IDictionary< string, IDatabasedatabases
 

Detailed Description

Definition at line 26 of file DatabaseSystem.cs.

Constructor & Destructor Documentation

Deveel.Data.DatabaseSystem.DatabaseSystem ( ISystemContext  context,
IEnumerable< ModuleInfo modules 
)
inlinepackage

Definition at line 31 of file DatabaseSystem.cs.

31  {
32  Context = context;
33  Modules = modules;
35  }
IContext IEventSource. Context
IEnumerable< ModuleInfo > Modules
Deveel.Data.DatabaseSystem.~DatabaseSystem ( )
inlineprivate

Definition at line 37 of file DatabaseSystem.cs.

37  {
38  Dispose(false);
39  }

Member Function Documentation

IDatabase Deveel.Data.DatabaseSystem.CreateDatabase ( IConfiguration  configuration,
string  adminUser,
string  adminPassword 
)
inline

Implements Deveel.Data.ISystem.

Definition at line 132 of file DatabaseSystem.cs.

132  {
133  lock (this) {
134  if (configuration == null)
135  throw new ArgumentNullException("configuration");
136 
137  var databaseName = configuration.GetString("database.name");
138  if (String.IsNullOrEmpty(databaseName))
139  throw new ArgumentException("The configuration must specify a database name.");
140 
141  if (DatabaseExists(databaseName))
142  throw new InvalidOperationException(String.Format("Database '{0}' already exists in the system.", databaseName));
143 
144  var dbContext = Context.CreateDatabaseContext(configuration);
145  var database = new Database(this, dbContext);
146 
147  if (database.Exists)
148  throw new InvalidOperationException(String.Format("The database '{0}' was already created.", databaseName));
149 
150  database.Create(adminUser, adminPassword);
151  database.Open();
152 
153  if (databases == null)
154  databases = new Dictionary<string, IDatabase>();
155 
156  databases[databaseName] = database;
157 
158  return database;
159  }
160  }
A long string in the system.
IContext IEventSource. Context
IDictionary< string, IDatabase > databases
bool DatabaseExists(string databaseName)
void Deveel.Data.DatabaseSystem.CreateMetadata ( )
inlineprivate

Definition at line 41 of file DatabaseSystem.cs.

41  {
42  metadata = new Dictionary<string, object>();
43 
44 #if !PCL
45  metadata["[env]:os.platform"] = Environment.OSVersion.Platform;
46  metadata["[env]:os.version"] = Environment.OSVersion.VersionString;
47  metadata["[env]:os.sp"] = Environment.OSVersion.ServicePack;
48  metadata["[env]:runtime.version"] = Environment.Version.ToString();
49  metadata["[env]:machineName"] = Environment.MachineName;
50  metadata["[env]:hostName"] = Dns.GetHostName();
51 
52 #endif
53  metadata["[env]processors"] = Environment.ProcessorCount;
54 
55  foreach (var config in Configuration) {
56  metadata[String.Format("[config]:{0}", config.Key)] = config.Value;
57  }
58 
59  foreach (var module in Modules) {
60  metadata[String.Format("[module]:{0}", module.ModuleName)] = module.Version;
61  }
62  }
A long string in the system.
IDictionary< string, object > metadata
IEnumerable< ModuleInfo > Modules
bool Deveel.Data.DatabaseSystem.DatabaseExists ( string  databaseName)
inline

Implements Deveel.Data.ISystem.

Definition at line 183 of file DatabaseSystem.cs.

183  {
184  lock (this) {
185  if (String.IsNullOrEmpty(databaseName))
186  throw new ArgumentNullException("databaseName");
187 
188  if (databases == null)
189  return false;
190 
191  return databases.ContainsKey(databaseName);
192  }
193  }
A long string in the system.
IDictionary< string, IDatabase > databases
bool Deveel.Data.DatabaseSystem.DeleteDatabase ( string  databaseName)
inline

Implements Deveel.Data.ISystem.

Definition at line 195 of file DatabaseSystem.cs.

195  {
196  lock (this) {
197  if (String.IsNullOrEmpty(databaseName))
198  throw new ArgumentNullException("databaseName");
199 
200  if (databases == null)
201  return false;
202 
203  IDatabase database;
204  if (!databases.TryGetValue(databaseName, out database))
205  return false;
206 
207  if (!database.Exists)
208  return false;
209 
210  // TODO: Implement the delete function in the IDatabase
211 
212  return databases.Remove(databaseName);
213  }
214  }
A long string in the system.
IDictionary< string, IDatabase > databases
void Deveel.Data.DatabaseSystem.Dispose ( )
inline

Definition at line 87 of file DatabaseSystem.cs.

87  {
88  Dispose(true);
89  GC.SuppressFinalize(this);
90  }
void Deveel.Data.DatabaseSystem.Dispose ( bool  disposing)
inlineprivate

Definition at line 92 of file DatabaseSystem.cs.

92  {
93  if (disposing) {
94  lock (this) {
95  if (databases != null) {
96  foreach (var database in databases.Values) {
97  if (database != null)
98  database.Dispose();
99  }
100 
101  databases.Clear();
102  }
103 
104  if (Context != null)
105  Context.Dispose();
106  }
107  }
108 
109  databases = null;
110  Context = null;
111  }
IContext IEventSource. Context
IDictionary< string, IDatabase > databases
IDatabase Deveel.Data.DatabaseSystem.GetDatabase ( string  databaseName)
inline

Implements Deveel.Data.IDatabaseHandler.

Definition at line 64 of file DatabaseSystem.cs.

64  {
65  lock (this) {
66  if (databases == null)
67  return null;
68 
69  IDatabase database;
70  if (!databases.TryGetValue(databaseName, out database))
71  return null;
72 
73  return database;
74  }
75  }
IDictionary< string, IDatabase > databases
IEnumerable<string> Deveel.Data.DatabaseSystem.GetDatabases ( )
inline

Implements Deveel.Data.ISystem.

Definition at line 123 of file DatabaseSystem.cs.

123  {
124  lock (this) {
125  if (databases == null)
126  return new string[0];
127 
128  return databases.Keys;
129  }
130  }
IDictionary< string, IDatabase > databases
IDatabase Deveel.Data.DatabaseSystem.OpenDatabase ( IConfiguration  configuration)
inline

Implements Deveel.Data.ISystem.

Definition at line 162 of file DatabaseSystem.cs.

162  {
163  lock (this) {
164  if (configuration == null)
165  throw new ArgumentNullException("configuration");
166 
167  var databaseName = configuration.GetString("database.name");
168  if (String.IsNullOrEmpty(databaseName))
169  throw new ArgumentException("The configuration must specify a database name.");
170 
171  IDatabase database;
172  if (databases == null ||
173  !databases.TryGetValue(databaseName, out database))
174  throw new InvalidOperationException(String.Format("Database '{0}' does not exist in the system.", databaseName));
175 
176  if (!database.IsOpen)
177  database.Open();
178 
179  return database;
180  }
181  }
A long string in the system.
IDictionary< string, IDatabase > databases
void Deveel.Data.DatabaseSystem.RemoveDatabase ( Database  database)
inlinepackage

Definition at line 216 of file DatabaseSystem.cs.

216  {
217  lock (this) {
218 
219  databases.Remove(database.Name);
220  }
221  }
IDictionary< string, IDatabase > databases

Member Data Documentation

IDictionary<string, IDatabase> Deveel.Data.DatabaseSystem.databases
private

Definition at line 29 of file DatabaseSystem.cs.

IDictionary<string, object> Deveel.Data.DatabaseSystem.metadata
private

Definition at line 27 of file DatabaseSystem.cs.

Property Documentation

IConfiguration Deveel.Data.DatabaseSystem.Configuration
getprivate

Definition at line 119 of file DatabaseSystem.cs.

IContext IEventSource. Deveel.Data.DatabaseSystem.Context
getprivate

Definition at line 113 of file DatabaseSystem.cs.

ISystemContext Deveel.Data.DatabaseSystem.Context
getprivate set

Definition at line 117 of file DatabaseSystem.cs.

IEnumerable<KeyValuePair<string, object> > IEventSource. Deveel.Data.DatabaseSystem.Metadata
getprivate

Definition at line 83 of file DatabaseSystem.cs.

IEnumerable<ModuleInfo> Deveel.Data.DatabaseSystem.Modules
getprivate set

Definition at line 77 of file DatabaseSystem.cs.

IEventSource IEventSource. Deveel.Data.DatabaseSystem.ParentSource
getprivate

Definition at line 79 of file DatabaseSystem.cs.


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