Пример #1
0
		public void EndQuery(IDatabaseQuery query, bool success)
		{
			if (query == null)
				return;
			bool failure = false;
			bool released = false;
			if (query.InTransaction)
			{
				NpgsqlTransaction transaction;
				if (!OpenTransactions.TryRemove(query, out transaction))
					throw new FrameworkException("Can't find query transaction");

				var conn = transaction.Connection;
				if (conn != null)
				{
					if (success)
						transaction.Commit();
					else
						transaction.Rollback();
					Connections.Release(conn, success);
					released = true;
				}
				else failure = success;
			}
			NpgsqlConnection connection;
			if (OpenConnections.TryRemove(query, out connection) && !released)
				Connections.Release(connection, success);
			if (failure)
				throw new FrameworkException("Transaction can't be committed since connection is null");
		}
Пример #2
0
		public void EndQuery(IDatabaseQuery query, bool success)
		{
			if (query == null)
				return;
			bool failure = false;
			if (query.InTransaction)
			{
				OracleTransaction transaction;
				if (!OpenTransactions.TryRemove(query, out transaction))
					throw new FrameworkException("Can't find query transaction");

				var conn = transaction.Connection;
				if (conn != null)
				{
					if (success)
						transaction.Commit();
					else
						transaction.Rollback();
					conn.Close();
				}
				else failure = success;
			}
			OracleConnection connection;
			OpenConnections.TryRemove(query, out connection);
			if (connection != null && connection.State == ConnectionState.Open)
				connection.Close();
			if (failure)
				throw new FrameworkException("Transaction can't be committed since connection is null");
		}
Пример #3
0
 public static IDatabaseQuery <T> WhereNotIn <T, K>(this IDatabaseQuery <T> query, Expression <Func <T, object> > property,
                                                    IDatabaseQuery <K> subquery, Expression <Func <K, object> > targetProperty)
     where T : IEntity
     where K : IEntity
 {
     return((IDatabaseQuery <T>)query.WhereNotIn(property.GetPropertyPath(),
                                                 subquery, targetProperty.GetPropertyPath()));
 }
Пример #4
0
        /// <summary>
        /// Applies DB query selection of records for the specified map.
        /// </summary>
        private void ApplyFilterMap(IDatabaseQuery <Record> query, IPlayableMap map)
        {
            var mapHash  = map.Detail.Hash;
            var gameMode = ((int)map.PlayableMode).ToString();

            query.Where(d => d["MapHash"].ToString().Equals(mapHash, StringComparison.Ordinal))
            .Where(d => d["GameMode"].ToString().Equals(gameMode, StringComparison.Ordinal));
        }
Пример #5
0
 public string CacheHint <TResult>(IDatabaseQuery <TResult, TModel> query)
 {
     if (query == null)
     {
         throw new ArgumentNullException("query");
     }
     return(query.CacheHint(model));
 }
Пример #6
0
 public LoadSubmission(IDataContext context, IDatabaseQuery databaseQuery) : base(context, databaseQuery)
 {
     Mapper.Initialize(cfg =>
     {
         cfg.CreateMap <SelectedSubmission, Cmn.SelectedSubmission>();
         cfg.CreateMap <Entry, Cmn.Entry>();
     });
 }
Пример #7
0
 protected MetaDataPopulator(IDatabaseComponent database, IDatabaseQuery query, bool reportProgress, ITransactionSource transaction)
     : base(reportProgress)
 {
     this.Database    = database;
     this.Transaction = transaction;
     this.Query       = query;
     this.Writer      = new MetaDataWriter(this.Database, this.Query, this.Transaction);
 }
Пример #8
0
        public virtual string GenerateSort(IDatabaseQuery query)
        {
            var parts = new List <string>();

            parts.AddRange(query.OrderByParts.Select(p => query.Column(p.Property) + " DESC".OnlyWhen(p.Descending)));

            return(parts.ToString(", "));
        }
Пример #9
0
 public TableCreateQuery(IDatabaseQuery dbTerm, string table, string datacenter, string primaryKey, double?cacheSize)
 {
     this.dbTerm     = dbTerm;
     this.table      = table;
     this.datacenter = datacenter;
     this.primaryKey = primaryKey;
     this.cacheSize  = cacheSize;
 }
Пример #10
0
 public UnitOfWork(IObjectFactory factory)
 {
     Scope         = factory.CreateInnerFactory();
     Manager       = factory.Resolve <IDatabaseQueryManager>();
     DatabaseQuery = Manager.BeginTransaction();
     Scope.RegisterInstance(DatabaseQuery);
     Context = Scope.Resolve <IDataContext>();
 }
Пример #11
0
 internal BulkReader(IServiceProvider locator, IDatabaseQuery query, ChunkedMemoryStream stream)
 {
     this.Locator = locator;
     this.Query   = query;
     this.Stream  = stream;
     this.Writer  = stream.GetWriter();
     Stream.Reset();
     Writer.Write("SELECT (");
 }
Пример #12
0
        /// <summary>
        /// Rollback started transaction.
        /// </summary>
        /// <param name="manager">query manager</param>
        /// <param name="query">ADO.NET driver</param>
        public static void Rollback(this IDatabaseQueryManager manager, IDatabaseQuery query)
        {
            Contract.Requires(manager != null);
            Contract.Requires(query != null);

            if (!query.InTransaction)
                throw new ArgumentException("Only queries in transaction can be rollbacked");
            manager.EndQuery(query, false);
        }
Пример #13
0
        public override string GenerateSort(IDatabaseQuery query)
        {
            if (query.PageSize.HasValue && query.OrderByParts.None())
            {
                return("(SELECT NULL)");
            }

            return(base.GenerateSort(query));
        }
 public UserRepository(string clusterName, string dbName, string tableName)
 {
     if (!string.IsNullOrEmpty(clusterName) && !string.IsNullOrEmpty(dbName) && !string.IsNullOrEmpty(tableName))
     {
         _connectionFactory = ConfigurationAssembler.CreateConnectionFactory(clusterName);
         _db = Query.Db(dbName);
         _table = _db.Table<User>(tableName);
     }
 }
Пример #15
0
 protected MetaDataPopulator(IDatabaseComponent database, IDatabaseQuery query, bool reportProgress, ITransactionSource transaction)
     : base(reportProgress)
 {
     this.Database    = database;
     this.Transaction = transaction;
     this.Query       = query;
     this.Writer      = new MetaDataWriter(this.Database, this.Query, this.Transaction);
     this.Warnings    = new ConcurrentDictionary <IFileData, IList <string> >();
 }
Пример #16
0
        public InputRepository(IServiceProvider locator, IDatabaseQuery query, IEagerNotification Notifications, IDataCache <global::FormABC.Input> DataCache)

        {
            this.Locator       = locator;
            this.DatabaseQuery = query;

            this.Notifications = Notifications;

            this.DataCache = DataCache;
        }
Пример #17
0
        public override string GeneratePagination(IDatabaseQuery query)
        {
            var result = query.TakeTop.ToStringOrEmpty().WithPrefix(" LIMIT ");

            result += query.PageStartIndex.ToString()
                      .OnlyWhen(query.PageStartIndex > 0)
                      .WithPrefix(" OFFSET ");

            return(result);
        }
Пример #18
0
        public CustomerRepository(IServiceProvider locator, IDatabaseQuery query, IEagerNotification Notifications, IDataCache <global::UseCase1.Customer> DataCache)

        {
            this.Locator       = locator;
            this.DatabaseQuery = query;

            this.Notifications = Notifications;

            this.DataCache = DataCache;
        }
Пример #19
0
        public XYZRepository(IServiceProvider locator, IDatabaseQuery query, IEagerNotification Notifications, IDataCache <global::Test.XYZ> DataCache)

        {
            this.Locator       = locator;
            this.DatabaseQuery = query;

            this.Notifications = Notifications;

            this.DataCache = DataCache;
        }
Пример #20
0
 protected BaseServerCommand(IServiceProvider locator, IDataContext context, IDatabaseQuery databaseQuery, IDomainModel domainModel, IWireSerialization serialization, ICommandConverter converter)
 {
     //TODO Is it bad to have a base Command like this that injects many of these:
     this.locator       = locator;
     this.context       = context;
     this.databaseQuery = databaseQuery;
     this.domainModel   = domainModel;
     this.serialization = serialization;
     this.converter     = converter;
 }
Пример #21
0
        public void EndQuery(IDatabaseQuery query, bool success)
        {
            if (query == null)
            {
                return;
            }
            bool failure = false;

            if (query.InTransaction)
            {
                NpgsqlTransaction transaction;
                if (!OpenTransactions.TryRemove(query, out transaction))
                {
                    throw new FrameworkException("Can't find query transaction");
                }

                var conn = transaction.Connection;
                if (conn != null)
                {
                    if (success)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                    conn.Close();
                }
                else
                {
                    failure = success;
                }
            }
            NpgsqlConnection connection;

            OpenConnections.TryRemove(query, out connection);
            try
            {
                if (connection != null && connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                var log = LogFactory.Create("Postgres database layer - end query");
                log.Error(ex.ToString());
                log.Info("Transactions: {0}, connections: {1}".With(OpenTransactions.Count, OpenConnections.Count));
            }
            if (failure)
            {
                throw new FrameworkException("Transaction can't be committed since connection is null");
            }
        }
Пример #22
0
        public IAsyncEnumerator <T> ExecuteAsyncEnumerator <T>(ITableConfig table, IDatabaseQuery query, DatabaseParameterHandler parameters, ITransactionSource transaction = null)
        {
            var reader     = this.ExecuteReader(query, parameters, transaction);
            var mapper     = new EntityMapper(table);
            var visitor    = new EntityCompoundEnumeratorVisitor();
            var enumerable = new EntityCompoundEnumerator(this, table, mapper, visitor);
            var buffer     = new EntityEnumeratorBuffer(this);
            var sink       = new EntityEnumeratorSink(table);

            return(enumerable.AsEnumerableAsync <T>(buffer, sink, reader, true));
        }
Пример #23
0
        public override string GeneratePagination(IDatabaseQuery query)
        {
            var result = string.Empty;

            if (query.PageSize > 0)
            {
                result = $" OFFSET {query.PageStartIndex} ROWS FETCH NEXT {query.PageSize} ROWS ONLY";
            }

            return(result);
        }
Пример #24
0
        /// <summary>
        /// Rollback started transaction.
        /// </summary>
        /// <param name="manager">query manager</param>
        /// <param name="query">ADO.NET driver</param>
        public static void Rollback(this IDatabaseQueryManager manager, IDatabaseQuery query)
        {
            Contract.Requires(manager != null);
            Contract.Requires(query != null);

            if (!query.InTransaction)
            {
                throw new ArgumentException("Only queries in transaction can be rollbacked");
            }
            manager.EndQuery(query, false);
        }
Пример #25
0
        //private readonly IRepositoryBulkReader BulkReader;
        //private readonly Lazy<World>[] LazyWorlds = new Lazy<World>[512];

        public Context(IObjectFactory factory, IDatabaseQueryManager manager)
        {
            QueryManager = manager;
            var scope = factory.CreateScope(null);

            Query = manager.StartQuery(false);
            scope.RegisterInterfaces(Query);
            WorldRepository   = scope.Resolve <IPersistableRepository <World> >();
            FortuneRepository = scope.Resolve <IQueryableRepository <Fortune> >();
            //BulkReader = scope.BulkRead(ChunkedMemoryStream.Static());
        }
        public TResult Execute <TResult>(IDatabaseQuery <SqlConnection, TResult> query)
        {
            using (var connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                var result = query.Execute(connection);
                connection.Close();

                return(result);
            }
        }
Пример #27
0
        private void WriteLocks(IDatabaseQuery database)
        {
            Console.WriteLine("LOCKS:");
            var info = database.Query <dynamic>("SELECT * FROM sys.lock_information;").ToList();

            foreach (var row in info)
            {
                Console.WriteLine(string.Format("> {0} {1} {2} {3} {4} {5} {6}", row.request_spid,
                                                row.resource_type, row.resource_description, row.request_mode, row.resource_table,
                                                row.resource_table_id, row.request_status));
            }
        }
Пример #28
0
 /// <summary>
 /// Gets the list of specified records.
 /// </summary>
 public virtual async Task <IEnumerable <IEntity> > GetList(IDatabaseQuery query)
 {
     using (var reader = await ExecuteGetListReader(query))
     {
         var result = new List <IEntity>();
         while (reader.Read())
         {
             result.Add(Parse(reader));
         }
         return(result);
     }
 }
Пример #29
0
        /// <summary>
        /// Execute query on the database and fill DataTable with the result.
        /// Connection and transaction information will be appended to the provided command.
        /// </summary>
        /// <param name="query">ADO.NET driver</param>
        /// <param name="command">command to execute</param>
        /// <param name="parameters">sql additional parameters</param>
        /// <returns>populated table</returns>
        public static DataTable Fill(
            this IDatabaseQuery query,
            IDbCommand command)
        {
            Contract.Requires(query != null);
            Contract.Requires(command != null);

            var ds = new DataSet();

            query.Fill(command, ds);
            return(ds.Tables.Count > 0 ? ds.Tables[0] : new DataTable());
        }
Пример #30
0
        /// <summary>
        /// Execute query on the database without the regards for result.
        /// Connection and transaction information will be appended to the provided command.
        /// </summary>
        /// <param name="query">ADO.NET driver</param>
        /// <param name="sql">sql to execute</param>
        /// <param name="parameters">sql parameters</param>
        /// <returns>comand.Execute() result</returns>
        public static int Execute(
            this IDatabaseQuery query,
            string sql,
            params object[] parameters)
        {
            Contract.Requires(query != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(sql));

            var com = query.CreateCommand(sql, parameters);

            return(query.Execute(com));
        }
Пример #31
0
        /// <summary>
        /// Execute query on the database and loop through the reader.
        /// Connection and transaction information will be appended to the provided command.
        /// Provided parameters will be inserted into the command.
        /// command.ExecuteDataReader() will be called.
        /// </summary>
        /// <param name="query">ADO.NET driver</param>
        /// <param name="sql">sql to execute</param>
        /// <param name="action">datareader converter</param>
        /// <param name="parameters">command parameters</param>
        public static void Execute(
            this IDatabaseQuery query,
            string sql,
            Action <IDataReader> action,
            params object[] parameters)
        {
            Contract.Requires(query != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(sql));

            var com = query.CreateCommand(sql, parameters);

            query.Execute(com, action);
        }
 /// <summary>
 /// Executes a command against the database that has no output.
 /// </summary>
 /// <param name="connection">The database connection in which to execute the command.</param>
 /// <param name="query">The query to be executed against the database.</param>
 internal void ExecuteNonQuery(IDatabaseConnection connection, IDatabaseQuery query)
 {
     // exhausts the result set to avoid unexecuted statements
     using (IDatabaseResult result = this.ExecuteQuery(connection, query))
     {
         do
         {
             while (result.Read())
             {
             }
         }while (result.NextResult());
     }
 }
Пример #33
0
        public override string GenerateSelectCommand(IDatabaseQuery iquery, string tables, string fields)
        {
            var query = (DatabaseQuery)iquery;

            var r = new StringBuilder("SELECT");

            r.AppendLine($" {fields} FROM {tables}");
            r.AppendLine(GenerateWhere(query));
            r.AppendLine(GenerateSort(query).WithPrefix(" ORDER BY "));
            r.AppendLine(GeneratePagination(query));

            return(r.ToString());
        }
Пример #34
0
        /// <summary>
        /// Execute query on the database and fill DataTable with the result.
        /// Connection and transaction information will be appended to the provided command.
        /// </summary>
        /// <param name="query">ADO.NET driver</param>
        /// <param name="sql">sql to execute</param>
        /// <param name="parameters">sql additional parameters</param>
        /// <returns>populated table</returns>
        public static DataTable Fill(
            this IDatabaseQuery query,
            string sql,
            params object[] parameters)
        {
            Contract.Requires(query != null);
            Contract.Requires(!string.IsNullOrWhiteSpace(sql));

            var com = query.CreateCommand(sql, parameters);
            var ds  = new DataSet();

            query.Fill(com, ds);
            return(ds.Tables.Count > 0 ? ds.Tables[0] : new DataTable());
        }
Пример #35
0
 public RaceQueryService(IDatabaseQuery dbQuery)
 {
     Races = dbQuery.GetQueryable<Race>();
 }
 public PersonEventQueryService(IDatabaseQuery dbQuery)
 {
     PersonEvents = dbQuery.GetQueryable<PersonEvent>();
 }
Пример #37
0
 public TestQuery(IDatabaseQuery databaseQuery)
 {
     query = databaseQuery.GetQueryable<TestTable>();
 }
Пример #38
0
        public void EndQuery(IDatabaseQuery query, bool success)
        {
            if (query == null)
                return;
            bool failure = false;
            if (query.InTransaction)
            {
                NpgsqlTransaction transaction;
                if (!OpenTransactions.TryRemove(query, out transaction))
                    throw new FrameworkException("Can't find query transaction");

                var conn = transaction.Connection;
                if (conn != null)
                {
                    if (success)
                        transaction.Commit();
                    else
                        transaction.Rollback();
                    conn.Close();
                }
                else failure = success;
            }
            NpgsqlConnection connection;
            OpenConnections.TryRemove(query, out connection);
            try
            {
                if (connection != null && connection.State == ConnectionState.Open)
                    connection.Close();
            }
            catch (Exception ex)
            {
                var log = LogFactory.Create("Postgres database layer - end query");
                log.Error(ex.ToString());
                log.Info("Transactions: {0}, connections: {1}".With(OpenTransactions.Count, OpenConnections.Count));
            }
            if (failure)
                throw new FrameworkException("Transaction can't be committed since connection is null");
        }
Пример #39
0
 public PersonQueryService(IDatabaseQuery dbQuery)
 {
     Person = dbQuery.GetQueryable<Person>();
 }
Пример #40
0
 public Scope(IObjectFactory factory, IDatabaseQuery query)
 {
     this.Factory = factory;
     this.Query = query;
 }