DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SystemBuilder.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 using System.Linq;
20 
21 using Deveel.Data.Caching;
23 using Deveel.Data.Routines;
24 using Deveel.Data.Security;
25 using Deveel.Data.Services;
26 using Deveel.Data.Sql;
27 using Deveel.Data.Sql.Compile;
28 using Deveel.Data.Sql.Query;
29 using Deveel.Data.Sql.Schemas;
30 using Deveel.Data.Sql.Sequences;
31 using Deveel.Data.Sql.Tables;
32 using Deveel.Data.Sql.Triggers;
33 using Deveel.Data.Sql.Variables;
34 using Deveel.Data.Sql.Views;
35 using Deveel.Data.Store;
36 
37 namespace Deveel.Data {
38  public class SystemBuilder {
39  public SystemBuilder()
40  : this(new Configuration.Configuration()) {
41  }
42 
43  public SystemBuilder(IConfiguration configuration) {
44  Configuration = configuration;
46  }
47 
48  public IConfiguration Configuration { get; set; }
49 
50  private ServiceContainer ServiceContainer { get; set; }
51 
52  private void RegisterDefaultServices() {
54 
56  .To<SystemFunctionsProvider>()
57  .InDatabaseScope();
58 
60  .To<SqlDefaultCompiler>()
61  .InSystemScope();
62 
64  .To<QueryPlanner>()
65  .InSystemScope();
66 
68  .To<TableCellCache>()
69  .InSystemScope();
70 
72  .To<TableManager>()
73  .WithKey(DbObjectType.Table)
74  .InTransactionScope();
75 
77  .To<ViewManager>()
78  .InTransactionScope()
79  .WithKey(DbObjectType.View);
80 
82  .To<SequenceManager>()
83  .WithKey(DbObjectType.Sequence)
84  .InTransactionScope();
85 
87  .To<TriggerManager>()
88  .WithKey(DbObjectType.Trigger)
89  .InTransactionScope();
90 
92  .To<SchemaManager>()
93  .WithKey(DbObjectType.Schema)
94  .InTransactionScope();
95 
97  .To<PersistentVariableManager>()
98  .WithKey(DbObjectType.Variable)
99  .InTransactionScope();
100 
102  .To<RoutineManager>()
103  .WithKey(DbObjectType.Routine)
104  .InTransactionScope();
105 
107  .To<InMemoryStorageSystem>()
109  .InDatabaseScope();
110 
112  .To<SingleFileStoreSystem>()
114  .InDatabaseScope();
115 
116 #if !PCL
118  .To<LocalFileSystem>()
119  .InSystemScope();
120 #endif
121  }
122 
123  private ISystemContext BuildContext(out IEnumerable<ModuleInfo> modules) {
124  RegisterDefaultServices();
125 
126  OnServiceRegistration(ServiceContainer);
127  modules = LoadModules();
128 
130  }
131 
132  private IEnumerable<ModuleInfo> LoadModules() {
133  var moduleInfo = new List<ModuleInfo>();
134 
135  var modules = ServiceContainer.ResolveAll<ISystemModule>();
136  foreach (var systemModule in modules) {
137  systemModule.Register(ServiceContainer);
138 
139  moduleInfo.Add(new ModuleInfo(systemModule.ModuleName, systemModule.Version));
140  }
141 
143  return moduleInfo;
144  }
145 
146  protected virtual void OnServiceRegistration(ServiceContainer container) {
147  }
148 
149  public ISystem BuildSystem() {
150  IEnumerable<ModuleInfo> modules;
151  var context = BuildContext(out modules);
152  return new DatabaseSystem(context, modules);
153  }
154  }
155 }
The system uses instances of this interface to resolve routines given a user invocation.
The execution context of a database system, that is defining the configurations and the components us...
virtual void OnServiceRegistration(ServiceContainer container)
void Register(ServiceRegistration registration)
bool Unregister(Type serviceType, object serviceName)
An object that creates and manages the IStore objects that the database engine uses to represent itse...
Definition: IStoreSystem.cs:31
This is the context of a database system, that handles the configurations and services used by all th...
SystemBuilder(IConfiguration configuration)
IEnumerable ResolveAll(Type serviceType)
Defines the contract for the configuration node of a component within the system or of the system its...
ISystemContext BuildContext(out IEnumerable< ModuleInfo > modules)
IEnumerable< ModuleInfo > LoadModules()
void Register(IScope systemScope)
Defines the contract for the business managers of database objects of a given type.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27