/// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTransactionalDataSource"/> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="isolationLevel">The isolation level.</param>
        /// <param name="forwardEvents">if set to <c>true</c> [forward events].</param>
        public PostgreSqlTransactionalDataSource(PostgreSqlDataSource dataSource, IsolationLevel?isolationLevel, bool forwardEvents)
            : base(new PostgreSqlDataSourceSettings {
            DefaultCommandTimeout = dataSource.DefaultCommandTimeout, StrictMode = dataSource.StrictMode, SuppressGlobalEvents = dataSource.SuppressGlobalEvents || forwardEvents
        })
        {
            Name = dataSource.Name;

            m_BaseDataSource = dataSource;
            m_Connection     = dataSource.CreateConnection();

            if (isolationLevel == null)
            {
                m_Transaction = m_Connection.BeginTransaction();
            }
            else
            {
                m_Transaction = m_Connection.BeginTransaction(isolationLevel.Value);
            }

            if (forwardEvents)
            {
                ExecutionStarted  += (sender, e) => dataSource.OnExecutionStarted(e);
                ExecutionFinished += (sender, e) => dataSource.OnExecutionFinished(e);
                ExecutionError    += (sender, e) => dataSource.OnExecutionError(e);
                ExecutionCanceled += (sender, e) => dataSource.OnExecutionCanceled(e);
            }
            AuditRules = dataSource.AuditRules;
            UserValue  = dataSource.UserValue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTransactionalDataSource"/> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="isolationLevel">The isolation level.</param>
        /// <param name="forwardEvents">if set to <c>true</c> [forward events].</param>
        public PostgreSqlTransactionalDataSource(PostgreSqlDataSource dataSource, IsolationLevel?isolationLevel, bool forwardEvents)
            : base(new PostgreSqlDataSourceSettings(dataSource, forwardEvents))
        {
            Name = dataSource.Name;

            m_BaseDataSource = dataSource;
            m_Connection     = dataSource.CreateConnection();

            if (isolationLevel == null)
            {
                m_Transaction = m_Connection.BeginTransaction();
            }
            else
            {
                m_Transaction = m_Connection.BeginTransaction(isolationLevel.Value);
            }

            if (forwardEvents)
            {
                ExecutionStarted  += (sender, e) => dataSource.OnExecutionStarted(e);
                ExecutionFinished += (sender, e) => dataSource.OnExecutionFinished(e);
                ExecutionError    += (sender, e) => dataSource.OnExecutionError(e);
                ExecutionCanceled += (sender, e) => dataSource.OnExecutionCanceled(e);
            }
            AuditRules = dataSource.AuditRules;
            UserValue  = dataSource.UserValue;
        }
Esempio n. 3
0
 static TestBase()
 {
     s_DataSource       = PostgreSqlDataSource.CreateFromConfig("PostgreSqlTestDatabase");
     s_StrictDataSource = s_DataSource.WithSettings(new PostgreSqlDataSourceSettings()
     {
         StrictMode = true
     });
 }
Esempio n. 4
0
        public PostgreSqlDataSource AttachSoftDeleteRulesWithUser(PostgreSqlDataSource source)
        {
            var currentUser1 = source.From(EmployeeTableName).WithLimits(1).ToObject <Employee>().Execute();

            return(source.WithRules(
                       new SoftDeleteRule("DeletedFlag", true),
                       new UserDataRule("DeletedByKey", "EmployeeKey", OperationTypes.Delete),
                       new DateTimeRule("DeletedDate", DateTimeKind.Local, OperationTypes.Delete)
                       ).WithUser(currentUser1));
        }
Esempio n. 5
0
 //public string TableFunction2Name { get { return "Sales.CustomersByStateInline"; } }
 public PostgreSqlDataSource AttachRules(PostgreSqlDataSource source)
 {
     return(source.WithRules(
                new DateTimeRule("CreatedDate", DateTimeKind.Local, OperationTypes.Insert),
                new DateTimeRule("UpdatedDate", DateTimeKind.Local, OperationTypes.InsertOrUpdate),
                new UserDataRule("CreatedByKey", "EmployeeKey", OperationTypes.Insert),
                new UserDataRule("UpdatedByKey", "EmployeeKey", OperationTypes.InsertOrUpdate),
                new ValidateWithValidatable(OperationTypes.InsertOrUpdate)
                ));
 }
Esempio n. 6
0
        internal PostgreSqlOpenDataSource(PostgreSqlDataSource dataSource, NpgsqlConnection connection, NpgsqlTransaction?transaction) : base(new PostgreSqlDataSourceSettings(dataSource))
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null.");
            }

            m_BaseDataSource = dataSource;
            m_Connection     = connection;
            m_Transaction    = transaction;
        }
Esempio n. 7
0
        internal PostgreSqlOpenDataSource(PostgreSqlDataSource dataSource, NpgsqlConnection connection, NpgsqlTransaction transaction) : base(new PostgreSqlDataSourceSettings() { DefaultCommandTimeout = dataSource.DefaultCommandTimeout, StrictMode = dataSource.StrictMode, SuppressGlobalEvents = dataSource.SuppressGlobalEvents })
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection), $"{nameof(connection)} is null.");
            }

            m_BaseDataSource = dataSource;
            m_Connection     = connection;
            m_Transaction    = transaction;
        }
Esempio n. 8
0
        internal PostgreSqlDataSourceSettings(PostgreSqlDataSource dataSource, bool forwardEvents)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException(nameof(dataSource), $"{nameof(dataSource)} is null.");
            }

            DefaultCommandTimeout = dataSource.DefaultCommandTimeout;
            StrictMode            = dataSource.StrictMode;
            SuppressGlobalEvents  = dataSource.SuppressGlobalEvents || forwardEvents;
        }
Esempio n. 9
0
 static TestBase()
 {
     Setup.AssemblyInit();
     foreach (ConnectionStringSettings con in ConfigurationManager.ConnectionStrings)
     {
         var ds = new PostgreSqlDataSource(con.Name, con.ConnectionString);
         if (s_PrimaryDataSource == null)
         {
             s_PrimaryDataSource = ds;
         }
         s_DataSources.Add(con.Name, ds);
     }
 }
Esempio n. 10
0
        static TestBase()
        {
            var configuration = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json").Build();

            foreach (var con in configuration.GetSection("ConnectionStrings").GetChildren())
            {
                var ds = new PostgreSqlDataSource(con.Key, con.Value);
                s_DataSources.Add(con.Key, ds);
                if (s_PrimaryDataSource == null)
                {
                    s_PrimaryDataSource = ds;
                }
            }
            BuildEmployeeSearchKey1000(s_PrimaryDataSource);
        }
Esempio n. 11
0
        public static void AssemblyInit(TestContext context)
        {
            var configuration = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json").Build();

            SqlServerConnectionString = configuration.GetSection("ConnectionStrings")["SqlServerTestDatabase"];
            PrimaryDataSource         = new SqlServerDataSource(SqlServerConnectionString);

            PostgreSqlConnectionString = configuration.GetSection("ConnectionStrings")["PostgreSqlTestDatabase"];
            PostgreSqlDataSource       = new PostgreSqlDataSource(PostgreSqlConnectionString);

            try
            {
                (new Setup()).Warmup_SqlServer();
                (new Setup()).Warmup_PostgreSql();
            }
            catch { }
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTransactionalDataSource" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="forwardEvents">if set to <c>true</c> [forward events].</param>
        /// <param name="connection">The connection.</param>
        /// <param name="transaction">The transaction.</param>
        internal PostgreSqlTransactionalDataSource(PostgreSqlDataSource dataSource, bool forwardEvents, NpgsqlConnection connection, NpgsqlTransaction transaction)
            : base(new PostgreSqlDataSourceSettings(dataSource, forwardEvents))
        {
            Name = dataSource.Name;

            m_BaseDataSource = dataSource;
            m_Connection     = connection;
            m_Transaction    = transaction;

            if (forwardEvents)
            {
                ExecutionStarted  += (sender, e) => dataSource.OnExecutionStarted(e);
                ExecutionFinished += (sender, e) => dataSource.OnExecutionFinished(e);
                ExecutionError    += (sender, e) => dataSource.OnExecutionError(e);
                ExecutionCanceled += (sender, e) => dataSource.OnExecutionCanceled(e);
            }
            AuditRules = dataSource.AuditRules;
            UserValue  = dataSource.UserValue;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PostgreSqlTransactionalDataSource" /> class.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// <param name="forwardEvents">if set to <c>true</c> [forward events].</param>
        /// <param name="connection">The connection.</param>
        /// <param name="transaction">The transaction.</param>
        internal PostgreSqlTransactionalDataSource(PostgreSqlDataSource dataSource, bool forwardEvents, NpgsqlConnection connection, NpgsqlTransaction transaction)
            : base(new PostgreSqlDataSourceSettings {
            DefaultCommandTimeout = dataSource.DefaultCommandTimeout, StrictMode = dataSource.StrictMode, SuppressGlobalEvents = dataSource.SuppressGlobalEvents || forwardEvents
        })
        {
            Name = dataSource.Name;

            m_BaseDataSource = dataSource;
            m_Connection     = connection;
            m_Transaction    = transaction;

            if (forwardEvents)
            {
                ExecutionStarted  += (sender, e) => dataSource.OnExecutionStarted(e);
                ExecutionFinished += (sender, e) => dataSource.OnExecutionFinished(e);
                ExecutionError    += (sender, e) => dataSource.OnExecutionError(e);
                ExecutionCanceled += (sender, e) => dataSource.OnExecutionCanceled(e);
            }
            AuditRules = dataSource.AuditRules;
            UserValue  = dataSource.UserValue;
        }
Esempio n. 14
0
        internal static void SetupTestBase()
        {
            if (s_PrimaryDataSource != null)
            {
                return; //run once check
            }
            Setup.CreateDatabase();

            var configuration = new ConfigurationBuilder().SetBasePath(AppContext.BaseDirectory).AddJsonFile("appsettings.json").Build();

            foreach (var con in configuration.GetSection("ConnectionStrings").GetChildren())
            {
                var ds = new PostgreSqlDataSource(con.Key, con.Value);
                if (s_PrimaryDataSource == null)
                {
                    s_PrimaryDataSource = ds;
                }

                s_DataSources.Add(con.Key, ds);
            }
            BuildEmployeeSearchKey1000(s_PrimaryDataSource);
        }
Esempio n. 15
0
    public PostgreSqlDataSource WithSettings(PostgreSqlDataSourceSettings?settings)
    {
        var mergedSettings = new PostgreSqlDataSourceSettings()
        {
            DefaultCommandTimeout = settings?.DefaultCommandTimeout ?? DefaultCommandTimeout,
            SuppressGlobalEvents  = settings?.SuppressGlobalEvents ?? SuppressGlobalEvents,
            StrictMode            = settings?.StrictMode ?? StrictMode,
            SequentialAccessMode  = settings?.SequentialAccessMode ?? SequentialAccessMode
        };
        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);
    }
Esempio n. 16
0
 public void Warmup_PostgreSql()
 {
     //Preload all of the database metadata to warmup the data source
     PostgreSqlDataSource.DatabaseMetadata.Preload();
     PostgreSqlDataSource.From("HR.EmployeeClassification", "1=0").Compile().ToObjectOrNull <EmployeeClassification>().Execute();
 }