Пример #1
0
        //public void IgnoreAndContinue()
        //{
        //    Ignore();
        //    this.session.Transaction.Begin();
        //}

        public T Execute <T>(string queryName, Dictionary <string, object> parameters = null)
        {
            if (parameters != null && !Contract.ForAll(parameters, (KeyValuePair <string, object> p) => p.Value != null))
            {
                throw new ArgumentException("The parameter array has a null element", "parameters");
            }

            T result = default(T);
            IStatelessSession session = this.Session;

            try
            {
                //session.BeginTransaction();
                IQuery query = session.GetNamedQuery(queryName);
                if (parameters != null)
                {
                    foreach (var item in parameters)
                    {
                        query.SetParameter(item.Key, item.Value);
                    }
                }
                result = query.UniqueResult <T>();
                //session.Transaction.Commit();
            }
            catch
            {
                //session.Transaction.Rollback();
                throw new Exception(string.Format("Failed for execute named query '{0}'.", queryName));
            }
            finally
            {
                // Do Nothing
            }
            return(result);
        }
Пример #2
0
 public List <T> ExecuteList <T>(string queryName, Dictionary <string, object> parameters = null)
 {
     if (parameters != null && parameters.Any(p => p.Value == null))
     {
         throw new ArgumentException("The parameter array has a null element", "parameters");
     }
     lock (this)
     {
         var result = new List <T>();
         IStatelessSession session = this.Session;
         try
         {
             IQuery query = session.GetNamedQuery(queryName);
             if (parameters != null)
             {
                 foreach (var item in parameters)
                 {
                     query.SetParameter(item.Key, item.Value);
                 }
             }
             result = query.List <T>().ToList();
         }
         catch
         {
             throw new Exception(string.Format("Failed for execute named query '{0}'.", queryName));
         }
         finally
         {
             // Do Nothing
         }
         return(result);
     }
 }
Пример #3
0
        static bool HandIsNotYetInDatabase(IPokerHand convertedHand, IStatelessSession statelessSession)
        {
            IQuery query = statelessSession.GetNamedQuery(FindConvertedPokerHandByGameIdAndSite);

            return(SetParametersForFindConvertedPokerHand(query, convertedHand.GameId, convertedHand.Site)
                   .UniqueResult <IConvertedPokerHand>() == null);
        }
Пример #4
0
        LoadEventDescriptorsForAggregate(Guid aggregateId)
        {
            var query = _session.GetNamedQuery("LoadEventDescriptors")
                        .SetGuid("aggregateId", aggregateId);

            return(Transact(() => query.List <EventDescriptor>()));
        }
Пример #5
0
        /// <summary>
        /// Führt eine Abfrage durch und gibt das Ergebnis als DataTable zurück.
        /// </summary>
        /// <param name="session">IStatelessSession in der die Abfrage ausgeführt wird.</param>
        /// <param name="name">Name der Abfrage.</param>
        /// <param name="parameters">Parameter für die Abfrage.</param>
        /// <returns>Ergebnis der Abfrage.</returns>
        public virtual DataTable DynamicQuery(IStatelessSession session, string name, IDictionary <string, object> parameters)
        {
            var result = new DataTable(name);

            var query = session.GetNamedQuery(name) as SqlQueryImpl;

            if (query == null)
            {
                throw new NotSupportedException($"Die angegebene Abfrage '{name}' ist ungültig. Es muss der Name einer native SQL-Abfrage angegeben werden.");
            }

            foreach (var param in parameters)
            {
                if (Array.IndexOf(query.NamedParameters, param.Key) != -1)
                {
                    query.SetParameter(param.Key, param.Value);
                }
            }

            query.SetResultTransformer(new DataTableSqlTransformer(result, query));

            foreach (DataRow row in query.List())
            {
                result.Rows.Add(row);
            }

            return(result);
        }
 public IQuery GetNamedQuery(string name)
 {
     if (_isStateless)
     {
         return(_wrapStateless.GetNamedQuery(name));
     }
     else
     {
         return(_wrap.GetNamedQuery(name));
     }
 }
Пример #7
0
        /// <summary>
        /// Finds all with named HQL query using IStatelessSession.
        /// </summary>
        /// <param name="namedQuery">The named query.</param>
        /// <param name="firstRow">The number of the first row to retrieve.</param>
        /// <param name="maxRows">The maximum number of results retrieved.</param>
        /// <returns></returns>
        public virtual Array FindAllWithNamedQueryStateless(string namedQuery, int firstRow, int maxRows)
        {
            if (string.IsNullOrEmpty(namedQuery))
            {
                throw new ArgumentNullException("namedQuery");
            }

            using (IStatelessSession session = GetStatelessSession())
            {
                try
                {
                    IQuery query = session.GetNamedQuery(namedQuery);
                    if (query == null)
                    {
                        throw new ArgumentException("Cannot find named query", "namedQuery");
                    }

                    if (firstRow != int.MinValue)
                    {
                        query.SetFirstResult(firstRow);
                    }
                    if (maxRows != int.MinValue)
                    {
                        query.SetMaxResults(maxRows);
                    }
                    IList result = query.List();
                    if (result == null || result.Count == 0)
                    {
                        return(null);
                    }

                    Array array = Array.CreateInstance(result[0].GetType(), result.Count);
                    result.CopyTo(array, 0);

                    return(array);
                }
                catch (Exception ex)
                {
                    throw new DataException("Could not perform FindAllWithNamedQueryStateless: " + namedQuery, ex);
                }
            }
        }
        static IPlayerIdentity FindPlayerIdentityFor(string name, string site, IStatelessSession statelessSession)
        {
            IQuery query = statelessSession.GetNamedQuery(FindPlayerIdentityByNameAndSite);

            return(SetQueryParametersAndReturnResultFor(query, name, site));
        }
 public IQuery GetNamedQuery(string queryName)
 {
     return(_Session.GetNamedQuery(queryName));
 }