DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DatabaseExtensions.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.Data;
19 
20 using Deveel.Data;
21 using Deveel.Data.Protocol;
22 
23 namespace Deveel.Data.Client {
24  public static class DatabaseExtensions {
25  public static IDbConnection CreateDbConnection(this IDatabase database, string userName, string password) {
26  if (database == null)
27  throw new ArgumentNullException("database");
28 
29  var dbHandler = database.Context.SystemContext as IDatabaseHandler;
30  if (dbHandler == null)
31  dbHandler = new SingleDatabaseHandler(database);
32 
33  var serverConnector = new EmbeddedServerConnector(dbHandler);
34  var clientConnector = new EmbeddedClientConnector(serverConnector);
35 
36  var settings = new DeveelDbConnectionStringBuilder {
37  UserName = userName,
38  Password = password,
39  Database = database.Name
40  };
41 
42  return new DeveelDbConnection(clientConnector, settings);
43  }
44  }
45 }
The default implementation of a database in a system.
Definition: Database.cs:38
string Name
Gets the name of the database.
Definition: IDatabase.cs:44
The representation of a single database in the system.
Definition: IDatabase.cs:40
new IDatabaseContext Context
Gets the context that contains this database.
Definition: IDatabase.cs:50
static IDbConnection CreateDbConnection(this IDatabase database, string userName, string password)
ISystemContext SystemContext
Gets the context of the database system that handles this database.