예제 #1
0
            /// <summary>
            /// Initializes a new instance of the <see cref="DatabaseConnection"/> class.
            /// </summary>
            /// <param name="connectionString">The SQLite connection string.</param>
            /// <param name="statementCachingSize">The size of the statement cache pool.</param>
            /// <param name="busyTimeout">The timeout value in milliseconds for waiting on a busy database resource.</param>
            /// <param name="connectionManager">The connection managed that has the connection pool from which this connection has been initialized.</param>
            public DatabaseConnection(string connectionString, int statementCachingSize, int busyTimeout, DataAccess.Sqlite.ConnectionManager connectionManager)
            {
                ThrowIf.NullOrWhiteSpace(connectionString, "sqlConnection");

                if (statementCachingSize < 1)
                {
                    throw new ArgumentOutOfRangeException("statementCachingSize", "Statement caching size must be positive.");
                }

                if (busyTimeout < 0)
                {
                    throw new ArgumentOutOfRangeException("busyTimeout", "Busy timeout must be greater or equal to 0.");
                }

                this.ConnectionString   = connectionString;
                this.statementCacheSize = statementCachingSize;
                this.busyTimeout        = busyTimeout;
                this.connectionManager  = connectionManager;
                this.SqlConnection      = null;
                this.isDisposed         = false;
                this.inUse                   = false;
                this.markedForRemoval        = false;
                this.attachedDatabaseCounter = 0;
                this.statementCache          = new Dictionary <string, SqlStatement>(StringComparer.OrdinalIgnoreCase);
            }
 /// <summary>
 /// Disposes the database provider including its connection manager.
 /// </summary>
 public void Dispose()
 {
     if (this.connectionManager != null)
     {
         lock (this)
         {
             if (this.connectionManager != null)
             {
                 this.connectionManager.Dispose();
                 this.connectionManager = null;
             }
         }
     }
 }
            /// <summary>
            /// Update configuration parameters.
            /// </summary>
            /// <param name="configuration">The data access configuration.</param>
            public void Configure(SqliteConfiguration configuration)
            {
                ThrowIf.Null(configuration, "dataAccessConfiguration");
                configuration.Validate();

                lock (this)
                {
                    if (this.connectionManager != null)
                    {
                        throw new InvalidOperationException("This instance has already been configured and its configuration values cannot be reset.");
                    }

                    this.connectionManager = new DataAccess.Sqlite.ConnectionManager(configuration);
                }
            }
예제 #4
0
            /// <summary>
            /// Releases the resources used by the instance.
            /// </summary>
            internal void ReleaseResources()
            {
                // we are disposing the connection
                if (this.statementCache != null)
                {
                    foreach (SqlStatement statement in this.statementCache.Values)
                    {
                        statement.Dispose();
                    }

                    this.statementCache.Clear();
                    this.statementCache = null;
                }

                this.DiposeSqliteConnection();

                this.connectionManager = null;

                this.isDisposed = true;
            }