예제 #1
0
        /// <summary>
        /// Returns all instances found for the specified type according to the criteria
        /// </summary>
        /// <param name="targetType">The target type.</param>
        /// <param name="detachedQuery">The query expression</param>
        /// <returns>The <see cref="Array"/> of results.</returns>
        public static Array FindAll(Type targetType, IDetachedQuery detachedQuery)
        {
            EnsureInitialized(targetType);

            ISession session = holder.CreateSession(targetType);

            try
            {
                IQuery executableQuery = detachedQuery.GetExecutableQuery(session);
                return(SupportingUtils.BuildArray(targetType, executableQuery.List()));
            }
            catch (ValidationException)
            {
                holder.FailSession(session);
                throw;
            }
            catch (Exception exception)
            {
                holder.FailSession(session);
                throw new ActiveRecordException("Could not perform FindAll for " + targetType.Name, exception);
            }
            finally
            {
                holder.ReleaseSession(session);
            }
        }
예제 #2
0
        private IList <T> InternalExecute(IDetachedQuery query)
        {
            ISession session = GetSession();

            if (session == null)
            {
                throw new ArgumentException("The NHibernate session is null; not available during pagination.");
            }
            return(query.GetExecutableQuery(session).List <T>());
        }
        /// <summary>
        /// Get the row count.
        /// </summary>
        /// <param name="session">The <see cref="ISession"/>.</param>
        /// <returns>The row count.</returns>
        public long GetRowsCount(ISession session)
        {
            IQuery q = dq.GetExecutableQuery(session);

            try
            {
                return((long)q.UniqueResult());
            }
            catch (Exception e)
            {
                throw new HibernateException(string.Format("Invalid RowsCounter query:{0}", q.QueryString), e);
            }
        }
예제 #4
0
 public T FindUnique(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(Session).UniqueResult <T>());
 }
예제 #5
0
 public IList <T> Find(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(Session).List <T>());
 }
예제 #6
0
        /// <summary>
        /// Returns all instances found for the specified type according to the criteria
        /// </summary>
        /// <param name="targetType">The target type.</param>
        /// <param name="detachedQuery">The query expression</param>
        /// <returns>The <see cref="Array"/> of results.</returns>
        protected internal static Array FindAll(Type targetType, IDetachedQuery detachedQuery)
        {
            EnsureInitialized(targetType);

            ISession session = holder.CreateSession(targetType);
            try
            {
                IQuery executableQuery = detachedQuery.GetExecutableQuery(session);
                return SupportingUtils.BuildArray(targetType, executableQuery.List());
            }
            catch (ValidationException)
            {
                holder.FailSession(session);
                throw;
            }
            catch (Exception exception)
            {
                holder.FailSession(session);
                throw new ActiveRecordException("Could not perform FindAll for " + targetType.Name, exception);
            }
            finally
            {
                holder.ReleaseSession(session);
            }
        }
예제 #7
0
 /// <summary>
 /// Returns a portion of the query results (sliced)
 /// </summary>
 /// <param name="targetType">The target type.</param>
 /// <param name="firstResult">The number of the first row to retrieve.</param>
 /// <param name="maxResults">The maximum number of results retrieved.</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>The sliced query results.</returns>
 public static Array SlicedFindAll(Type targetType, int firstResult, int maxResults, IDetachedQuery detachedQuery)
 {
     EnsureInitialized(targetType);
     ISession session = holder.CreateSession(targetType);
     try
     {
         IQuery executableQuery = detachedQuery.GetExecutableQuery(session);
         executableQuery.SetFirstResult(firstResult);
         executableQuery.SetMaxResults(maxResults);
         return SupportingUtils.BuildArray(targetType, executableQuery.List());
     }
     catch (ValidationException)
     {
         holder.FailSession(session);
         throw;
     }
     catch (Exception exception)
     {
         holder.FailSession(session);
         throw new ActiveRecordException("Could not perform SlicedFindAll for " + targetType.Name, exception);
     }
     finally
     {
         holder.ReleaseSession(session);
     }
 }
예제 #8
0
 private IList <T> InternalExecute(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(GetSession()).List <T>());
 }