Esempio n. 1
0
 public LocalDatabase(LocalSystem system, string databaseName)
 {
     System = system;
     this.databaseName = databaseName;
 }
Esempio n. 2
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;
        }