Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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&lt;PersistentStorageAllocationTable&gt; query = new QueryParams&lt;PersistentStorageAllocationTable&gt;(
        ///         GetAllocationTableCriteria(), 1);
        /// IList&lt;PersistentStorageAllocationTable> resultList = QueryHelper.Query&lt;PersistentStorageAllocationTable&gt;(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));
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
 /// <summary>
 /// Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 public bool Equals(QueryParamsBase other)
 {
     return(Equals((object)other));
 }
Exemple #6
0
 /// <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&lt;EntityBase&gt; 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));
 }
Exemple #7
0
 /// <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&lt;People&gt; qpPeople = new QueryParams&lt;People&gt;(
 ///     new ArithmeticCriteria("id", new EntityId(1, 1, 2)));
 /// IList&lt;People&gt; resultListPeople = QueryHelper.Query&lt;People&gt;(session, qpPeople);
 /// </code>
 /// </example>
 public static IListSpecialized <TEntity> Query <TEntity>(ISession session, QueryParamsBase queryData) where TEntity : EntityBaseWithoutId
 {
     return(Query <TEntity>(session, queryData, LOG_QUERY));
 }
Exemple #8
0
        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);
        }