Exemplo n.º 1
0
        public virtual async Task <IEnumerable <T> > QueryAsync(Query query, CancellationToken cancellationToken)
        {
            var sqlCompiled = connectionProvider.QueryCompiler.Compile(query);

            using (var connection = await connectionProvider.GetConnectionAsync(cancellationToken))
            {
                var mapper = GetMapper();
                if (mapper != null)
                {
                    return(await connection.QueryAsync <T>(sqlCompiled.Sql, ChildTypes, GetMapper(), sqlCompiled.NamedBindings, splitOn : splitOn));
                }
                return(await connection.QueryAsync <T>(sqlCompiled.Sql, sqlCompiled.NamedBindings));
            }
        }
        public async Task <DbConnection> GetConnectionAsync(CancellationToken cancellationToken)
        {
            var connection = await _connectionProvider.GetConnectionAsync(cancellationToken);

            return(_externalStorageConnectionProvider == null
                ? connection
                : new HybridStorageConnection(connection, _externalStorageConnectionProvider.GetProvider()));
        }
Exemplo n.º 3
0
        public async Task ExecuteAsync(Action <string> scriptAction, bool execute, bool justDrop, TextWriter exportOutput, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            await(InitializeAsync(cancellationToken)).ConfigureAwait(false);
            DbConnection        connection         = null;
            TextWriter          fileOutput         = exportOutput;
            IConnectionProvider connectionProvider = null;

            try
            {
                if (fileOutput == null && outputFile != null)
                {
                    fileOutput = new StreamWriter(outputFile);
                }

                if (execute)
                {
                    var props = new Dictionary <string, string>();
                    foreach (var de in dialect.DefaultProperties)
                    {
                        props[de.Key] = de.Value;
                    }

                    if (configProperties != null)
                    {
                        foreach (var de in configProperties)
                        {
                            props[de.Key] = de.Value;
                        }
                    }

                    connectionProvider = ConnectionProviderFactory.NewConnectionProvider(props);
                    connection         = await(connectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false);
                }

                await(ExecuteAsync(scriptAction, execute, justDrop, connection, fileOutput, cancellationToken)).ConfigureAwait(false);
            }
            catch (OperationCanceledException) { throw; }
            catch (HibernateException)
            {
                // So that we don't wrap HibernateExceptions in HibernateExceptions
                throw;
            }
            catch (Exception e)
            {
                log.Error(e, e.Message);
                throw new HibernateException(e.Message, e);
            }
            finally
            {
                if (connection != null)
                {
                    connectionProvider.CloseConnection(connection);
                    connectionProvider.Dispose();
                }
            }
        }
        public async Task <DbConnection> GetConnectionAsync(CancellationToken cancellationToken)
        {
            var connection = await _base.GetConnectionAsync(cancellationToken);

            if (_provider == null)
            {
                return(connection);
            }

            return(new ExternalBlobDbConnectionWrapper(connection, _provider.GetConnection()));
        }
Exemplo n.º 5
0
        public async Task AllowDeletionOfImmutableObjectAsync()
        {
            using (ISession session = OpenSession())
            {
                Assert.DoesNotThrowAsync(async() =>
                {
                    using (ITransaction trans = session.BeginTransaction())
                    {
                        var entity = await(session.GetAsync <DomainClass>(1));
                        await(session.DeleteAsync(entity));

                        await(trans.CommitAsync());
                    }
                });
            }

            using (IConnectionProvider prov = ConnectionProviderFactory.NewConnectionProvider(cfg.Properties))
            {
                var conn = await(prov.GetConnectionAsync(CancellationToken.None));

                try
                {
                    using (var comm = conn.CreateCommand())
                    {
                        comm.CommandText = "SELECT Id FROM DomainClass WHERE Id=1 AND Label='TEST record'";
                        object result = await(comm.ExecuteScalarAsync());

                        Assert.That(result == null, "Immutable object has not been deleted!");
                    }
                }
                finally
                {
                    prov.CloseConnection(conn);
                }
            }
        }
Exemplo n.º 6
0
        private async Task InitConnectionAndExecuteAsync(Action <string> scriptAction, bool execute, bool justDrop, DbConnection connection, TextWriter exportOutput, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            await(InitializeAsync(cancellationToken)).ConfigureAwait(false);
            TextWriter          fileOutput         = exportOutput;
            IConnectionProvider connectionProvider = null;

            try
            {
                if (fileOutput == null && outputFile != null)
                {
                    fileOutput = new StreamWriter(outputFile);
                }

                if (execute && connection == null)
                {
                    if (_requireTenantConnection)
                    {
                        throw new ArgumentException("When Database multi-tenancy is enabled you need to provide explicit connection. Please use overload with connection parameter.");
                    }

                    var props = new Dictionary <string, string>();
                    foreach (var de in dialect.DefaultProperties)
                    {
                        props[de.Key] = de.Value;
                    }

                    if (configProperties != null)
                    {
                        foreach (var de in configProperties)
                        {
                            props[de.Key] = de.Value;
                        }
                    }

                    connectionProvider = ConnectionProviderFactory.NewConnectionProvider(props);
                    connection         = await(connectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false);
                }

                await(ExecuteAsync(scriptAction, execute, justDrop, connection, fileOutput, cancellationToken)).ConfigureAwait(false);
            }
            catch (OperationCanceledException) { throw; }
            catch (HibernateException)
            {
                // So that we don't wrap HibernateExceptions in HibernateExceptions
                throw;
            }
            catch (Exception e)
            {
                log.Error(e, e.Message);
                throw new HibernateException(e.Message, e);
            }
            finally
            {
                if (connectionProvider != null)
                {
                    connectionProvider.CloseConnection(connection);
                    connectionProvider.Dispose();
                }
            }
        }