Inheritance: System.Data.Common.DbConnectionStringBuilder
示例#1
0
        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));
        }
示例#2
0
 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);
 }
示例#3
0
 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);
     }
 }
示例#4
0
 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);
 }
示例#5
0
        public ConnectionClient(IClientConnector connector, DeveelDbConnectionStringBuilder settings)
        {
            if (connector == null)
                throw new ArgumentNullException("connector");

            Settings = settings;
            Connector = connector;
            Processor = connector.CreateProcessor();
            OwnsConnector = false;
        }
示例#6
0
        public ConnectionClient(IClientConnector connector, DeveelDbConnectionStringBuilder settings)
        {
            if (connector == null)
            {
                throw new ArgumentNullException("connector");
            }

            Settings      = settings;
            Connector     = connector;
            Processor     = connector.CreateProcessor();
            OwnsConnector = false;
        }
示例#7
0
        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);
        }
示例#8
0
        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);
     }
 }
示例#10
0
        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);
        }
示例#11
0
        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;
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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;
        }
示例#16
0
        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);
        }
示例#17
0
 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);
 }
示例#19
0
 public DeveelDbConnection(DeveelDbConnectionStringBuilder connectionString)
 {
     this.connectionString = connectionString;
     RowCache = new LocalRowCache(this);
 }
示例#20
0
 public ConnectionClient(DeveelDbConnectionStringBuilder settings)
 {
     Settings = settings;
 }
示例#21
0
        ///<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;
        }
示例#22
0
 public ConnectionClient(DeveelDbConnectionStringBuilder settings)
 {
     Settings = settings;
 }
示例#23
0
 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);
 }