public static IDbConnection CreateDbConnection(this IDatabase database, string userName, string password) { if (database == null) { throw new ArgumentNullException("database"); } var dbHandler = database.Context.SystemContext as IDatabaseHandler; if (dbHandler == null) { dbHandler = new SingleDatabaseHandler(database); } var serverConnector = new EmbeddedServerConnector(dbHandler); var clientConnector = new EmbeddedClientConnector(serverConnector); var settings = new DeveelDbConnectionStringBuilder { UserName = userName, Password = password, Database = database.Name }; return(new DeveelDbConnection(clientConnector, settings)); }
public void StandardParseFromString() { const string connString = "Host=Heap;UserID=SA;Password=123456;Database=testdb"; DeveelDbConnectionStringBuilder connectionString = new DeveelDbConnectionStringBuilder(connString); Assert.AreEqual("Heap", connectionString.Host); Assert.AreEqual("SA", connectionString.UserName); Assert.AreEqual("123456", connectionString.Password); Assert.AreEqual("testdb", connectionString.Database); }
public LocalRowCache(DeveelDbConnection connection) { this.connection = connection; if (connection.Settings != null) { rowCache = new SizeLimitedCache (connection.Settings.RowCacheSize); } else { int defaultCacheSize = new DeveelDbConnectionStringBuilder ().RowCacheSize; rowCache = new SizeLimitedCache (defaultCacheSize); } }
public void NonStandardParseFromString() { const string connString = "DataSource=Heap;UserName=SA;Password=123456;Database=testdb;BootOrCreate=true"; DeveelDbConnectionStringBuilder connectionString = new DeveelDbConnectionStringBuilder(connString); Assert.AreEqual("Heap", connectionString.Host); Assert.AreEqual("SA", connectionString.UserName); Assert.AreEqual("123456", connectionString.Password); Assert.AreEqual("testdb", connectionString.Database); Assert.AreEqual(true, connectionString.BootOrCreate); }
public ConnectionClient(IClientConnector connector, DeveelDbConnectionStringBuilder settings) { if (connector == null) throw new ArgumentNullException("connector"); Settings = settings; Connector = connector; Processor = connector.CreateProcessor(); OwnsConnector = false; }
public ConnectionClient(IClientConnector connector, DeveelDbConnectionStringBuilder settings) { if (connector == null) { throw new ArgumentNullException("connector"); } Settings = settings; Connector = connector; Processor = connector.CreateProcessor(); OwnsConnector = false; }
private static DeveelDbConnectionStringBuilder BuildConnectionString(IConfiguration configuration) { var settings = new DeveelDbConnectionStringBuilder(); foreach (var pair in configuration) { try { switch (pair.Key.ToUpperInvariant()) { case "DATABASE.NAME": case "DBNAME": settings.Database = configuration.GetString(pair.Key); break; case "USERNAME": case "USERID": case "USER.NAME": case "USER.ID": case "CONNECTION.USERNAME": case "CONNECTION.USER": case "CONNECTION.USERID": settings.UserName = configuration.GetString(pair.Key); break; case "PASSWORD": case "PASS": case "USER.PASSWORD": case "SECRET": case "CONNECTION.PASSWORD": case "CONNECTION.PASS": settings.Password = configuration.GetString(pair.Key); break; case "PARAMETERSTYLE": case "PARAMSTYLE": case "CONNECTION.PARAMETERSTYLE": settings.ParameterStyle = configuration.GetValue <QueryParameterStyle>(pair.Key); break; case "IGNORECASE": case "CONNECTION.IGNORECASE": case "IGNOREIDENTIFIERSCASE": case "CONNECTION.IGNOREIDENTIFIERSCASE": settings.IgnoreIdentifiersCase = configuration.GetBoolean(pair.Key); break; } } catch (Exception ex) { throw new ArgumentException(String.Format("An error occurred while setting the key '{0}' into the connection string.", pair.Key)); } } return(settings); }
protected override void OnAfterSetup(string testName) { var connString = new DeveelDbConnectionStringBuilder { UserName = AdminUserName, Password = AdminPassword, DataSource = "memory", Database = DatabaseName, Schema = "APP", Create = true }; connection = (DeveelDbConnection)Database.CreateDbConnection(AdminUserName, AdminPassword); }
public LocalRowCache(DeveelDbConnection connection) { this.connection = connection; if (connection.Settings != null) { rowCache = new SizeLimitedCache(connection.Settings.RowCacheSize); } else { int defaultCacheSize = new DeveelDbConnectionStringBuilder().RowCacheSize; rowCache = new SizeLimitedCache(defaultCacheSize); } }
private IConfiguration CreateDbConfig(DeveelDbConnectionStringBuilder settings) { var config = new Configuration.Configuration(); var databaseName = settings.Database; var dataSource = settings.DataSource; var schema = settings.Schema; if (String.IsNullOrEmpty(schema)) { schema = "APP"; } config.SetValue("database.name", databaseName); config.SetValue("database.defaultSchema", schema); if (IsInMemory(dataSource)) { config.SetValue("database.storeType", "memory"); } else if (IsSingleFile(dataSource)) { var index = dataSource.IndexOf('='); var fileName = dataSource.Substring(index + 1); config.SetValue("database.storeType", "file"); config.SetValue("database.path", fileName); } else if (IsJournaled(dataSource)) { var index = dataSource.IndexOf('='); var path = dataSource.Substring(index + 1); config.SetValue("database.storeType", "journaled"); config.SetValue("database.path", path); } foreach (KeyValuePair <string, object> pair in settings) { var key = pair.Key; var value = pair.Value; // TODO: normalize the key and convert the value to set into the configuration config.SetValue(key, value); } return(config); }
private static DeveelDbConnectionStringBuilder BuildConnectionString(IConfiguration configuration) { var settings = new DeveelDbConnectionStringBuilder(); foreach (var pair in configuration) { try { switch (pair.Key.ToUpperInvariant()) { case "DATABASE.NAME": case "DBNAME": settings.Database = configuration.GetString(pair.Key); break; case "USERNAME": case "USERID": case "USER.NAME": case "USER.ID": case "CONNECTION.USERNAME": case "CONNECTION.USER": case "CONNECTION.USERID": settings.UserName = configuration.GetString(pair.Key); break; case "PASSWORD": case "PASS": case "USER.PASSWORD": case "SECRET": case "CONNECTION.PASSWORD": case "CONNECTION.PASS": settings.Password = configuration.GetString(pair.Key); break; case "PARAMETERSTYLE": case "PARAMSTYLE": case "CONNECTION.PARAMETERSTYLE": settings.ParameterStyle = configuration.GetValue<QueryParameterStyle>(pair.Key); break; case "IGNORECASE": case "CONNECTION.IGNORECASE": case "IGNOREIDENTIFIERSCASE": case "CONNECTION.IGNOREIDENTIFIERSCASE": settings.IgnoreIdentifiersCase = configuration.GetBoolean(pair.Key); break; } } catch (Exception ex) { throw new ArgumentException(String.Format("An error occurred while setting the key '{0}' into the connection string.", pair.Key)); } } return settings; }
public void OpenForAdmin() { var connString = new DeveelDbConnectionStringBuilder { UserName = AdminUserName, Password = AdminPassword, DataSource = "memory", Database = DatabaseName, Schema = "APP", Create = true }; var connection = new DeveelDbConnection(connString); Assert.AreEqual(ConnectionState.Closed, connection.State); Assert.DoesNotThrow(() => connection.Open()); Assert.AreEqual(ConnectionState.Open, connection.State); Assert.DoesNotThrow(() => connection.Close()); Assert.AreEqual(ConnectionState.Closed, connection.State); }
public static IDbConnection CreateDbConnection(this IDatabase database, string userName, string password) { if (database == null) throw new ArgumentNullException("database"); var dbHandler = database.DatabaseContext.SystemContext as IDatabaseHandler; if (dbHandler == null) dbHandler = new SingleDatabaseHandler(database); var serverConnector = new EmbeddedServerConnector(dbHandler); var clientConnector = new EmbeddedClientConnector(serverConnector); var settings = new DeveelDbConnectionStringBuilder { UserName = userName, Password = password, Database = database.Name() }; return new DeveelDbConnection(clientConnector, settings); }
private IConfiguration CreateDbConfig(DeveelDbConnectionStringBuilder settings) { var config = new Configuration.Configuration(); var databaseName = settings.Database; var dataSource = settings.DataSource; var schema = settings.Schema; if (String.IsNullOrEmpty(schema)) schema = "APP"; config.SetValue("database.name", databaseName); config.SetValue("database.defaultSchema", schema); if (IsInMemory(dataSource)) { config.SetValue("database.storeType", "memory"); } else if (IsSingleFile(dataSource)) { var index = dataSource.IndexOf('='); var fileName = dataSource.Substring(index + 1); config.SetValue("database.storeType", "file"); config.SetValue("database.path", fileName); } else if (IsJournaled(dataSource)) { var index = dataSource.IndexOf('='); var path = dataSource.Substring(index + 1); config.SetValue("database.storeType", "journaled"); config.SetValue("database.path", path); } foreach (KeyValuePair<string, object> pair in settings) { var key = pair.Key; var value = pair.Value; // TODO: normalize the key and convert the value to set into the configuration config.SetValue(key, value); } return config; }
protected override void OnAfterSetup(string testName) { var connString = new DeveelDbConnectionStringBuilder { UserName = AdminUserName, Password = AdminPassword, DataSource = "memory", Database = DatabaseName, Schema = "APP", Create = true }; connection = (DeveelDbConnection) Database.CreateDbConnection(AdminUserName, AdminPassword); }
internal DeveelDbConnection(IClientConnector connector, DeveelDbConnectionStringBuilder settings) { Client = new ConnectionClient(connector,settings); connectionString = settings; RowCache = new LocalRowCache(this); }
public DeveelDbConnection(DeveelDbConnectionStringBuilder connectionString) { this.connectionString = connectionString; RowCache = new LocalRowCache(this); }
public ConnectionClient(DeveelDbConnectionStringBuilder settings) { Settings = settings; }
///<summary> /// Makes a connection to the database and returns a <see cref="IDbConnection"/> /// object that can be used to execute queries on the database. ///</summary> ///<param name="schema">The initial database schema to start the connection in.</param> ///<param name="username">The user to login to the database under.</param> ///<param name="password">The password of the user.</param> /// <remarks> /// This is a standard connection that talks directly with the database without /// having to go through any communication protocol layers. /// <para> /// For example, if this control is for a database server, the <see cref="IDbConnection"/> /// returned here does not go through the TCP/IP connection. For this reason certain database /// configuration constraints (such as number of concurrent connection on the database) may not /// apply to this connection. /// </para> /// </remarks> ///<returns> /// Returns a <see cref="IDbConnection"/> instance used to access the database. /// </returns> /// <exception cref="DataException"> /// Thrown if the login fails with the credentials given. /// </exception> public IDbConnection GetConnection(string schema, string username, string password) { // Create the database interface for an internal database connection. var localSystem = new LocalSystem(controller); var localDatabase = localSystem.ControlDatabase(name); // Create the DeveelDbConnection object (very minimal cache settings for an // internal connection). var s = new DeveelDbConnectionStringBuilder { Database = name, Schema = schema, UserName = username, Password = password, RowCacheSize = 8, MaxCacheSize = 4092000, BootOrCreate = true }; if (Config.IsHeapStorageSystem()) { s.Host = "Heap"; } else { s.Host = "Local"; s.Path = Config.DatabaseFullPath(); } int id = ++internalCounter; var connection = new DeveelDbConnection(s.ToString(), localDatabase); connection.StateChange += (sender, args) => { if (args.CurrentState == ConnectionState.Open) { if (connections == null) connections = new Dictionary<int, DeveelDbConnection>(); connections[id] = connection; } else if (args.CurrentState == ConnectionState.Closed) { connections.Remove(id); } }; connection.Disposed += (sender, args) => { // TODO: do further disposal }; // Attempt to log in with the given username and password (default schema) connection.Open(); if (connection.State != ConnectionState.Open) throw new InvalidOperationException("Unable to open the connection."); // And return the new connection return connection; }
internal DeveelDbConnection(IClientConnector connector, DeveelDbConnectionStringBuilder settings) : this(settings) { Client = new ConnectionClient(connector, settings); }
internal DeveelDbConnection(IClientConnector connector, DeveelDbConnectionStringBuilder settings) : this(settings) { Client = new ConnectionClient(connector,settings); }