/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public virtual object Clone() { QueryParamsBase cloned = (QueryParamsBase)this.GetType().GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance | BindingFlags.Instance, null, new Type[] { typeof(Type) }, null).Invoke(new object[] { this.mEntityType }); cloned.mMaxResults = this.mMaxResults; return(cloned); }
/// <summary> /// Queries the specified session. /// </summary> /// <param name="session">The session.</param> /// <param name="queryData">The query data.</param> /// <param name="logQuery">if set to <c>true</c> [log query].</param> /// <returns>The result list</returns> public static IListSpecialized <EntityBaseWithoutId> Query(ISession session, QueryParamsBase queryData, bool logQuery) { IList queryResult = (System.Collections.IList)mGenericQueryMethod.MakeGenericMethod(queryData.EntityType).Invoke(null, new object[] { session, queryData, logQuery }); IListSpecialized <EntityBaseWithoutId> result = new ListSpecialized <EntityBaseWithoutId>(); foreach (object b in queryResult) { result.Add((EntityBaseWithoutId)b); } return(result); }
/// <summary> /// Queries the specified session. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="session">The session.</param> /// <param name="queryData">The query data.</param> /// <param name="logQuery">if set to <c>true</c> [log query].</param> /// <returns>The result list</returns> /// <example> /// <code> /// QueryParams<PersistentStorageAllocationTable> query = new QueryParams<PersistentStorageAllocationTable>( /// GetAllocationTableCriteria(), 1); /// IList<PersistentStorageAllocationTable> resultList = QueryHelper.Query<PersistentStorageAllocationTable>(session, query, LOG_QUERY); /// if (resultList.Count == 0) /// { /// this.mAllocationTable = new ItemTable(); /// } /// </code> /// </example> public static IListSpecialized <TEntity> Query <TEntity>(ISession session, QueryParamsBase queryData, bool logQuery) where TEntity : EntityBaseWithoutId { if (session == null) { ThrowHelper.ThrowArgumentNullException("session"); } if (queryData == null) { ThrowHelper.ThrowArgumentNullException("queryData"); } DetachedCriteria dc = queryData.GetDetachedCriteria(); ICriteria criteria = dc.GetExecutableCriteria(session); queryData.PrepareCriteria(criteria); return(ExecuteQuery <TEntity>(session, queryData, dc, criteria, logQuery)); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (ReferenceEquals(this, obj)) { return(true); } if (!obj.GetType().Equals(GetType())) { return(false); } QueryParamsBase other = (QueryParamsBase)obj; return(other.mMaxResults == this.mMaxResults); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public bool Equals(QueryParamsBase other) { return(Equals((object)other)); }
/// <summary> /// Queries the specified session. /// </summary> /// <param name="session">The session.</param> /// <param name="queryData">The query data.</param> /// <returns>The result list</returns> /// <example> /// <code> /// IList<EntityBase> queryResult = QueryHelper.Query(session, new QueryParams(entityRule.EntityType)); /// </code> /// </example> public static IListSpecialized <EntityBaseWithoutId> Query(ISession session, QueryParamsBase queryData) { return(Query(session, queryData, LOG_QUERY)); }
/// <summary> /// Queries the specified session. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="session">The session.</param> /// <param name="queryData">The query data.</param> /// <returns>The result list</returns> /// <example> /// <code> /// QueryParams<People> qpPeople = new QueryParams<People>( /// new ArithmeticCriteria("id", new EntityId(1, 1, 2))); /// IList<People> resultListPeople = QueryHelper.Query<People>(session, qpPeople); /// </code> /// </example> public static IListSpecialized <TEntity> Query <TEntity>(ISession session, QueryParamsBase queryData) where TEntity : EntityBaseWithoutId { return(Query <TEntity>(session, queryData, LOG_QUERY)); }
private static ListSpecialized <TEntity> ExecuteQuery <TEntity>(ISession session, QueryParamsBase queryData, DetachedCriteria dc, ICriteria criteria, bool logQuery) where TEntity : EntityBaseWithoutId { if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) BEGIN --->", queryData.Id)); } if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("(ID: {0}) {1}: {2}", queryData.Id, queryData.EntityType.FullName, criteria.ToString())); } } ListSpecialized <TEntity> result = null; try { result = new ListSpecialized <TEntity>(criteria.List <TEntity>()); if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) END, SIZE OF THE RESULT SET: {1} --->", queryData.Id, result == null ? "0" : result.Count.ToString())); } } } catch (Exception ex) { if (logQuery) { if (LOGGER.IsDebugEnabled) { LOGGER.Debug(String.Format("<--- QUERY (ID: {0}) END, FAILED --->", queryData.Id)); } } throw new QueryException(ex.Message, ex); } if (result == null) { result = new ListSpecialized <TEntity>(); } else { for (int i = 0; i < result.Count; i++) { EntityBaseWithoutId eb = result[i]; if (eb is INHibernateProxy) { result[i] = (TEntity)session.GetSessionImplementation().PersistenceContext.UnproxyAndReassociate(eb); } } } return(result); }