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"); }
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"); }
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())); }
/// <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)); }
public string CacheHint <TResult>(IDatabaseQuery <TResult, TModel> query) { if (query == null) { throw new ArgumentNullException("query"); } return(query.CacheHint(model)); }
public LoadSubmission(IDataContext context, IDatabaseQuery databaseQuery) : base(context, databaseQuery) { Mapper.Initialize(cfg => { cfg.CreateMap <SelectedSubmission, Cmn.SelectedSubmission>(); cfg.CreateMap <Entry, Cmn.Entry>(); }); }
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); }
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(", ")); }
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; }
public UnitOfWork(IObjectFactory factory) { Scope = factory.CreateInnerFactory(); Manager = factory.Resolve <IDatabaseQueryManager>(); DatabaseQuery = Manager.BeginTransaction(); Scope.RegisterInstance(DatabaseQuery); Context = Scope.Resolve <IDataContext>(); }
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 ("); }
/// <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); }
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); } }
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> >(); }
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; }
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); }
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; }
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; }
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; }
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"); } }
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)); }
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); }
/// <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); }
//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); } }
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)); } }
/// <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); } }
/// <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()); }
/// <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)); }
/// <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()); } }
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()); }
/// <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()); }
public RaceQueryService(IDatabaseQuery dbQuery) { Races = dbQuery.GetQueryable<Race>(); }
public PersonEventQueryService(IDatabaseQuery dbQuery) { PersonEvents = dbQuery.GetQueryable<PersonEvent>(); }
public TestQuery(IDatabaseQuery databaseQuery) { query = databaseQuery.GetQueryable<TestTable>(); }
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"); }
public PersonQueryService(IDatabaseQuery dbQuery) { Person = dbQuery.GetQueryable<Person>(); }
public Scope(IObjectFactory factory, IDatabaseQuery query) { this.Factory = factory; this.Query = query; }