/// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlDataSource"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">connectionString is null or empty.;connectionString</exception>
        public PostgreSqlDataSource(string name, string connectionString, PostgreSqlDataSourceSettings settings = null)
            : base(settings)
        {
            if (string.IsNullOrEmpty(connectionString))
                throw new ArgumentException("connectionString is null or empty.", "connectionString");

            m_ConnectionBuilder = new NpgsqlConnectionStringBuilder(connectionString);
            if (string.IsNullOrEmpty(name))
                Name = m_ConnectionBuilder.Database;
            else
                Name = name;

            m_DatabaseMetadata = new PostgreSqlMetadataCache(m_ConnectionBuilder);
            m_ExtensionCache = new ConcurrentDictionary<Type, object>();
            m_Cache = DefaultCache;
        }
        public PostgreSqlDataSource WithSettings(PostgreSqlDataSourceSettings settings)
        {
            var mergedSettings = new PostgreSqlDataSourceSettings()
            {
                DefaultCommandTimeout = settings?.DefaultCommandTimeout ?? DefaultCommandTimeout,
                SuppressGlobalEvents  = settings?.SuppressGlobalEvents ?? SuppressGlobalEvents,
                StrictMode            = settings?.StrictMode ?? StrictMode
            };
            var result = new PostgreSqlDataSource(Name, m_ConnectionBuilder, mergedSettings, m_DatabaseMetadata, m_Cache, m_ExtensionCache);

            result.m_DatabaseMetadata = m_DatabaseMetadata;
            result.AuditRules         = AuditRules;
            result.UserValue          = UserValue;

            result.ExecutionStarted  += (sender, e) => OnExecutionStarted(e);
            result.ExecutionFinished += (sender, e) => OnExecutionFinished(e);
            result.ExecutionError    += (sender, e) => OnExecutionError(e);
            result.ExecutionCanceled += (sender, e) => OnExecutionCanceled(e);

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlDataSource"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentException">connectionString is null or empty.;connectionString</exception>
        public PostgreSqlDataSource(string name, string connectionString, PostgreSqlDataSourceSettings settings = null)
            : base(settings)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("connectionString is null or empty.", "connectionString");
            }

            m_ConnectionBuilder = new NpgsqlConnectionStringBuilder(connectionString);
            if (string.IsNullOrEmpty(name))
            {
                Name = m_ConnectionBuilder.Database;
            }
            else
            {
                Name = name;
            }

            m_DatabaseMetadata = new PostgreSqlMetadataCache(m_ConnectionBuilder);
            m_ExtensionCache   = new ConcurrentDictionary <Type, object>();
            m_Cache            = DefaultCache;
        }
        PostgreSqlDataSource(string name, NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings, PostgreSqlMetadataCache databaseMetadata, ICacheAdapter cache, ConcurrentDictionary <Type, object> extensionCache)
            : base(settings)
        {
            m_ConnectionBuilder = connectionBuilder ?? throw new ArgumentNullException(nameof(connectionBuilder), $"{nameof(connectionBuilder)} is null.");
            if (string.IsNullOrEmpty(name))
            {
                Name = m_ConnectionBuilder.Database;
            }
            else
            {
                Name = name;
            }

            m_DatabaseMetadata = databaseMetadata;
            m_ExtensionCache   = extensionCache;
            m_Cache            = cache;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PostgreSqlDataSource"/> class.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="settings">The settings.</param>
 public PostgreSqlDataSource(string connectionString, PostgreSqlDataSourceSettings settings = null)
     : this(null, connectionString, settings)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PostgreSqlDataSource" /> class.
 /// </summary>
 /// <param name="connectionBuilder">The connection builder.</param>
 /// <param name="settings">The settings.</param>
 public PostgreSqlDataSource(NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings = null)
     : this(null, connectionBuilder, settings)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlDataSource" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="connectionBuilder">The connection builder.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public PostgreSqlDataSource(string name, NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings = null)
            : base(settings)
        {
            m_ConnectionBuilder = connectionBuilder ?? throw new ArgumentNullException(nameof(connectionBuilder), $"{nameof(connectionBuilder)} is null.");
            if (string.IsNullOrEmpty(name))
            {
                Name = m_ConnectionBuilder.Database;
            }
            else
            {
                Name = name;
            }

            m_DatabaseMetadata = new PostgreSqlMetadataCache(m_ConnectionBuilder);
            m_ExtensionCache   = new ConcurrentDictionary <Type, object>();
            m_Cache            = DefaultCache;
        }
        private PostgreSqlDataSource(string name, NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings, PostgreSqlMetadataCache databaseMetadata, ICacheAdapter cache, ConcurrentDictionary<Type, object> extensionCache)
            : base(settings)
        {
            if (connectionBuilder == null)
                throw new ArgumentNullException(nameof(connectionBuilder), $"{nameof(connectionBuilder)} is null.");

            m_ConnectionBuilder = connectionBuilder;
            if (string.IsNullOrEmpty(name))
                Name = m_ConnectionBuilder.Database;
            else
                Name = name;

            m_DatabaseMetadata = databaseMetadata;
            m_ExtensionCache = extensionCache;
            m_Cache = cache;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PostgreSqlDataSource"/> class.
 /// </summary>
 /// <param name="connectionString">The connection string.</param>
 /// <param name="settings">The settings.</param>
 public PostgreSqlDataSource(string connectionString, PostgreSqlDataSourceSettings settings = null)
     : this(null, connectionString, settings)
 {
 }
        public PostgreSqlDataSource WithSettings(PostgreSqlDataSourceSettings settings)
        {
            var mergedSettings = new PostgreSqlDataSourceSettings()
            {
                DefaultCommandTimeout = settings?.DefaultCommandTimeout ?? DefaultCommandTimeout,
                SuppressGlobalEvents = settings?.SuppressGlobalEvents ?? SuppressGlobalEvents,
                StrictMode = settings?.StrictMode ?? StrictMode
            };
            var result = new PostgreSqlDataSource(Name, m_ConnectionBuilder, mergedSettings, m_DatabaseMetadata, m_Cache, m_ExtensionCache);
            result.m_DatabaseMetadata = m_DatabaseMetadata;
            result.AuditRules = AuditRules;
            result.UserValue = UserValue;

            result.ExecutionStarted += (sender, e) => OnExecutionStarted(e);
            result.ExecutionFinished += (sender, e) => OnExecutionFinished(e);
            result.ExecutionError += (sender, e) => OnExecutionError(e);
            result.ExecutionCanceled += (sender, e) => OnExecutionCanceled(e);

            return result;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PostgreSqlDataSource" /> class.
 /// </summary>
 /// <param name="connectionBuilder">The connection builder.</param>
 /// <param name="settings">The settings.</param>
 public PostgreSqlDataSource(NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings = null)
     : this(null, connectionBuilder, settings)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlDataSource" /> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="connectionBuilder">The connection builder.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public PostgreSqlDataSource(string name, NpgsqlConnectionStringBuilder connectionBuilder, PostgreSqlDataSourceSettings settings = null)
            : base(settings)
        {
            if (connectionBuilder == null)
                throw new ArgumentNullException(nameof(connectionBuilder), $"{nameof(connectionBuilder)} is null.");

            m_ConnectionBuilder = connectionBuilder;
            if (string.IsNullOrEmpty(name))
                Name = m_ConnectionBuilder.Database;
            else
                Name = name;

            m_DatabaseMetadata = new PostgreSqlMetadataCache(m_ConnectionBuilder);
            m_ExtensionCache = new ConcurrentDictionary<Type, object>();
            m_Cache = DefaultCache;
        }