/// <summary>
 /// Create a new instance of <see cref="QueryRowsCounter"/>.
 /// </summary>
 /// <param name="hqlRowsCount">The HQL.</param>
 /// <remarks>
 /// If the query is invalid an exception is throw only when <see cref="IRowsCounter.GetRowsCount(ISession)"/>
 /// is called.
 /// </remarks>
 /// <exception cref="ArgumentNullException">If <paramref name="hqlRowsCount"/> is null or empty.</exception>
 public QueryRowsCounter(string hqlRowsCount)
 {
     if(string.IsNullOrEmpty(hqlRowsCount))
     {
         throw new ArgumentNullException(hqlRowsCount);
     }
     detachedQuery = new DetachedQuery(hqlRowsCount);
 }
        /// <summary>
        /// Create a new instance of <see cref="QueryRowsCounter"/>.
        /// </summary>
        /// <param name="queryRowCount">The query.</param>
        /// <remarks>
        /// If the query is invalid an exception is throw only when <see cref="IRowsCounter.GetRowsCount(ISession)"/>
        /// is called.
        /// </remarks>
        /// <exception cref="ArgumentNullException">If <paramref name="queryRowCount"/> is null.</exception>
        public QueryRowsCounter(IDetachedQuery queryRowCount)
        {
            if (queryRowCount == null)
            {
                throw new ArgumentNullException("queryRowCount");
            }

            dq = queryRowCount;
        }
Example #3
0
        /// <summary>
        /// Copy all properties to a given <see cref="IDetachedQuery"/>.
        /// </summary>
        /// <param name="destination">The given <see cref="IDetachedQuery"/>.</param>
        /// <remarks>
        /// The method use <see cref="IDetachedQuery"/> to set properties of <paramref name="destination"/>.
        /// </remarks>
        public void CopyTo(IDetachedQuery destination)
        {
            destination.SetMaxResults(selection.MaxRows)
                .SetFirstResult(selection.FirstRow)
                .SetCacheable(cacheable)
                .SetReadOnly(readOnly)
                .SetTimeout(selection.Timeout)
                .SetFlushMode(flushMode);
            if (!string.IsNullOrEmpty(cacheRegion))
                destination.SetCacheRegion(cacheRegion);
            if (cacheMode.HasValue)
                destination.SetCacheMode(cacheMode.Value);
            if (resultTransformer != null)
                destination.SetResultTransformer(resultTransformer);
            foreach (KeyValuePair<string, LockMode> mode in lockModes)
                destination.SetLockMode(mode.Key, mode.Value);

            SetParametersTo(destination);
        }
Example #4
0
        /// <summary>
        /// Check if there is any records in the db for the target type
        /// </summary>
        /// <param name="targetType">The target type.</param>
        /// <param name="detachedQuery"></param>
        /// <returns><c>true</c> if there's at least one row</returns>
        protected internal static bool Exists(Type targetType, IDetachedQuery detachedQuery)
        {
            Array array = SlicedFindAll(targetType, 0, 1, detachedQuery);

            return array.Length > 0;
        }
 public NoFooPaginable(ISession session, IDetachedQuery detachedQuery) : base(session, detachedQuery)
 {
     detachedQuery.SetResultTransformer(
         new PositionalToBeanResultTransformer(typeof(NoFoo), new string[] { "name", "description" }));
 }
Example #6
0
 public static Blog[] SlicedFindAll(int FirstResult, int MaxResult, IDetachedQuery dq)
 {
     return (Blog[]) SlicedFindAll(typeof(Blog), FirstResult, MaxResult, dq);
 }
Example #7
0
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// </summary>
 /// <param name="targetType">The target type</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 protected internal static object FindOne(Type targetType, IDetachedQuery detachedQuery)
 {
     Array array = SlicedFindAll(targetType, 0, 2, detachedQuery);
     if (array.Length > 1)
     {
         throw new ActiveRecordException(
             string.Concat(
                 new object[] { targetType.Name, ".FindOne returned ", array.Length, " rows. Expecting one or none" }));
     }
     if (array.Length != 0)
     {
         return array.GetValue(0);
     }
     return null;
 }
 public WrongImplementation(IDetachedQuery dq)
 {
     this.dq = dq;
 }
Example #9
0
 /// <summary>
 /// Returns all instances found for the specified type according to the criteria
 /// </summary>
 /// <param name="detachedQuery">The query expression.</param>
 /// <returns>All entities that match the query</returns>
 public static T[] FindAll(IDetachedQuery detachedQuery)
 {
     return((T[])FindAll(typeof(T), detachedQuery));
 }
Example #10
0
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// </summary>
 /// <param name="targetType">The target type</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 public static object FindOne(Type targetType, IDetachedQuery detachedQuery)
 {
     return(ActiveRecordBase.FindOne(targetType, detachedQuery));
 }
 /// <summary>
 /// Check if any instance matches the query.
 /// </summary>
 /// <param name="targetType">target Type</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists(Type targetType, IDetachedQuery detachedQuery)
 {
     return ActiveRecordBase.Exists(targetType, detachedQuery);
 }
Example #12
0
 /// <summary>
 /// Check if any instance matches the query.
 /// </summary>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists <T>(IDetachedQuery detachedQuery) where T : class
 {
     return(AR.CurrentScope().Exists <T>(detachedQuery));
 }
Example #13
0
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// </summary>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 public static T FindOne <T>(IDetachedQuery detachedQuery) where T : class
 {
     return(AR.CurrentScope().FindOne <T>(detachedQuery));
 }
		/// <summary>
		/// Set only parameters to a given <see cref="IDetachedQuery"/>.
		/// </summary>
		/// <param name="destination">The given <see cref="IDetachedQuery"/>.</param>
		/// <remarks>
		/// The method use <see cref="IDetachedQuery"/> to set properties of <paramref name="destination"/>.
		/// Existing parameters in <paramref name="destination"/> are merged/overriden.
		/// </remarks>
		public void SetParametersTo(IDetachedQuery destination)
		{
			foreach (var obj in optionalUntypeParams)
				destination.SetProperties(obj);

			// Set untyped positional parameters
			foreach (var pup in posUntypeParams)
				destination.SetParameter(pup.Key, pup.Value);

			// Set untyped named parameters
			foreach (var nup in namedUntypeParams)
				destination.SetParameter(nup.Key, nup.Value);

			// Set untyped named parameters list
			foreach (var nulp in namedUntypeListParams)
				destination.SetParameterList(nulp.Key, nulp.Value);

			// Set typed positional parameters
			foreach (var pp in posParams)
				destination.SetParameter(pp.Key, pp.Value.Value, pp.Value.Type);

			// Set typed named parameters
			foreach (var np in namedParams)
				destination.SetParameter(np.Key, np.Value.Value, np.Value.Type);

			// Set typed named parameters List
			foreach (var nlp in namedListParams)
				destination.SetParameterList(nlp.Key, (IEnumerable) nlp.Value.Value, nlp.Value.Type);
		}
Example #15
0
 /// <summary>
 /// Returns a portion of the query results (sliced)
 /// </summary>
 /// <param name="firstResult">The number of the first row to retrieve.</param>
 /// <param name="maxResults">The maximum number of results retrieved.</param>
 /// <returns>The sliced query results.</returns>
 /// <param name="detachedQuery">The query expression</param>
 public static T[] SlicedFindAll(int firstResult, int maxResults, IDetachedQuery detachedQuery)
 {
     return((T[])SlicedFindAll(typeof(T), firstResult, maxResults, detachedQuery));
 }
Example #16
0
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// <param name="detachedQuery">The query expression</param>
 /// </summary>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 public static T FindOne(IDetachedQuery detachedQuery)
 {
     return((T)FindOne(typeof(T), detachedQuery));
 }
 public new void CopyTo(IDetachedQuery destination)
 {
     base.CopyTo(destination);
 }
Example #18
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)
 {
     return(ActiveRecordBase.SlicedFindAll(targetType, firstResult, maxResults, detachedQuery));
 }
Example #19
0
 public T FindUnique(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(Session).UniqueResult <T>());
 }
Example #20
0
 private IList <T> InternalExecute(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(GetSession()).List <T>());
 }
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// </summary>
 /// <param name="targetType">The target type</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 public static object FindOne(Type targetType, IDetachedQuery detachedQuery)
 {
     return ActiveRecordBase.FindOne(targetType, detachedQuery);
 }
Example #22
0
 public static Blog FindOne(IDetachedQuery dq)
 {
     return (Blog) FindOne(typeof(Blog), dq);
 }
Example #23
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)
 {
     return(ActiveRecordBase.FindAll(targetType, detachedQuery));
 }
Example #24
0
 /// <summary>
 /// Check if any instance matching the query exists in the database.
 /// </summary>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns>true if an instance is found; otherwise false.</returns>
 public static bool Exists(IDetachedQuery detachedQuery)
 {
     return(Exists(typeof(T), detachedQuery));
 }
Example #25
0
 public static Blog[] FindAll(IDetachedQuery dq)
 {
     return (Blog[]) FindAll(typeof(Blog), dq);
 }
Example #26
0
 /// <summary>
 /// Check if any instance matches the query.
 /// </summary>
 /// <param name="targetType">target Type</param>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists(Type targetType, IDetachedQuery detachedQuery)
 {
     return(ActiveRecordBase.Exists(targetType, detachedQuery));
 }
Example #27
0
 public static bool Exists(IDetachedQuery dq)
 {
     return Exists(typeof(Blog), dq);
 }
			public new void CopyTo(IDetachedQuery destination)
			{
				base.CopyTo(destination);
			}
Example #29
0
 /// <summary>
 /// Searches and returns the first row.
 /// </summary>
 /// <param name="targetType">The target type.</param>
 /// <param name="detachedQuery">The expression query.</param>
 /// <returns>A <c>targetType</c> instance or <c>null.</c></returns>
 protected internal static object FindFirst(Type targetType, IDetachedQuery detachedQuery)
 {
     Array array = SlicedFindAll(targetType, 0, 1, detachedQuery);
     if ((array != null) && (array.Length > 0))
     {
         return array.GetValue(0);
     }
     return null;
 }
Example #30
0
 public static Blog[] FindAll(IDetachedQuery dq)
 {
     return((Blog[])FindAll(typeof(Blog), dq));
 }
Example #31
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);
     }
 }
Example #32
0
 public static Blog FindOne(IDetachedQuery dq)
 {
     return((Blog)FindOne(typeof(Blog), dq));
 }
Example #33
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);
            }
        }
Example #34
0
 public static bool Exists(IDetachedQuery dq)
 {
     return(Exists(typeof(Blog), dq));
 }
		/// <summary>
		/// Set only parameters to a given <see cref="IDetachedQuery"/>.
		/// </summary>
		/// <param name="destination">The given <see cref="IDetachedQuery"/>.</param>
		/// <remarks>
		/// The method use <see cref="IDetachedQuery"/> to set properties of <paramref name="destination"/>.
		/// Existing parameters in <paramref name="destination"/> are merged/overriden.
		/// </remarks>
		public void SetParametersTo(IDetachedQuery destination)
		{
			foreach (object obj in optionalUntypeParams)
				destination.SetProperties(obj);

			// Set untyped positional parameters
			foreach (KeyValuePair<int, object> pup in posUntypeParams)
				destination.SetParameter(pup.Key, pup.Value);

			// Set untyped named parameters
			foreach (KeyValuePair<string, object> nup in namedUntypeParams)
				destination.SetParameter(nup.Key, nup.Value);

			// Set untyped named parameters list
			foreach (KeyValuePair<string, ICollection> nulp in namedUntypeListParams)
				destination.SetParameterList(nulp.Key, nulp.Value);

			// Set typed positional parameters
			foreach (KeyValuePair<int, TypedValue> pp in posParams)
				destination.SetParameter(pp.Key, pp.Value.Value, pp.Value.Type);

			// Set typed named parameters
			foreach (KeyValuePair<string, TypedValue> np in namedParams)
				destination.SetParameter(np.Key, np.Value.Value, np.Value.Type);

			// Set typed named parameters List
			foreach (KeyValuePair<string, TypedValue> nlp in namedListParams)
				destination.SetParameterList(nlp.Key, (ICollection)nlp.Value.Value, nlp.Value.Type);
		}
Example #36
0
 public static Blog[] SlicedFindAll(int FirstResult, int MaxResult, IDetachedQuery dq)
 {
     return((Blog[])SlicedFindAll(typeof(Blog), FirstResult, MaxResult, dq));
 }
Example #37
0
 public IList <T> Find(IDetachedQuery query)
 {
     return(query.GetExecutableQuery(Session).List <T>());
 }
Example #38
0
 /// <summary>
 /// Searches and returns a row. If more than one is found,
 /// throws <see cref="ActiveRecordException"/>
 /// <param name="detachedQuery">The query expression</param>
 /// </summary>
 /// <returns>A <c>targetType</c> instance or <c>null</c></returns>
 public static T FindOne(IDetachedQuery detachedQuery)
 {
     return(AR.CurrentScope().FindOne <T>(detachedQuery));
 }
Example #39
0
 // Override this method to check the type of 'query' param to provide some type of
 // PaginableRowCount.
 // for example:
 // -secure if query is the implementation of DetachedDynQuery you can use PaginableDynQuery
 // -some times if the query is an implementation of DetachedQuery (see PaginableRowsCounterQuery for instance)
 public virtual IPaginable <T> GetPaginable(IDetachedQuery query)
 {
     return(new PaginableQuery <T>(Session, query));
 }
Example #40
0
 /// <summary>
 /// Returns all instances found for the specified type according to the criteria
 /// </summary>
 /// <param name="detachedQuery">The query expression.</param>
 /// <returns>All entities that match the query</returns>
 public static IEnumerable <T> FindAll(IDetachedQuery detachedQuery)
 {
     return(AR.CurrentScope().FindAll <T>(detachedQuery));
 }
 /// <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)
 {
     return ActiveRecordBase.FindAll(targetType, detachedQuery);
 }
Example #42
0
 /// <summary>
 /// Returns a portion of the query results (sliced)
 /// </summary>
 /// <param name="firstResult">The number of the first row to retrieve.</param>
 /// <param name="maxResults">The maximum number of results retrieved.</param>
 /// <returns>The sliced query results.</returns>
 /// <param name="detachedQuery">The query expression</param>
 public static IEnumerable <T> SlicedFindAll(int firstResult, int maxResults, IDetachedQuery detachedQuery)
 {
     return(AR.CurrentScope().SlicedFindAll <T>(firstResult, maxResults, detachedQuery));
 }
 /// <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)
 {
     return ActiveRecordBase.SlicedFindAll(targetType, firstResult, maxResults, detachedQuery);
 }
Example #44
0
 /// <summary>
 /// Check if any instance matches the query.
 /// </summary>
 /// <param name="detachedQuery">The query expression</param>
 /// <returns><c>true</c> if an instance is found; otherwise <c>false</c>.</returns>
 public static bool Exists(IDetachedQuery detachedQuery)
 {
     return(AR.CurrentScope().Exists <T>(detachedQuery));
 }