Пример #1
0
        public Task InitializeAsync(object key, ISessionImplementor session, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled <object>(cancellationToken));
            }
            try
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format("initializing collection: {0} using named query: {1}", persister.Role, queryName));
                }

                //TODO: is there a more elegant way than downcasting?
                AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedSQLQuery(queryName);
                if (query.NamedParameters.Length > 0)
                {
                    query.SetParameter(query.NamedParameters[0], key, persister.KeyType);
                }
                else
                {
                    query.SetParameter(0, key, persister.KeyType);
                }
                return(query.SetCollectionKey(key).SetFlushMode(FlushMode.Manual).ListAsync(cancellationToken));
            }
            catch (System.Exception ex)
            {
                return(Task.FromException <object>(ex));
            }
        }
Пример #2
0
        public async Task <object> LoadAsync(object id, object optionalObject, ISessionImplementor session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("loading entity: {0} using named query: {1}", persister.EntityName, queryName));
            }

            AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedQuery(queryName);

            if (query.HasNamedParameters)
            {
                query.SetParameter(query.NamedParameters[0], id, persister.IdentifierType);
            }
            else
            {
                query.SetParameter(0, id, persister.IdentifierType);
            }
            query.SetOptionalId(id);
            query.SetOptionalEntityName(persister.EntityName);
            query.SetOptionalObject(optionalObject);
            query.SetFlushMode(FlushMode.Manual);
            await(query.ListAsync(cancellationToken)).ConfigureAwait(false);

            // now look up the object we are really interested in!
            // (this lets us correctly handle proxies and multi-row
            // or multi-column queries)
            return(session.PersistenceContext.GetEntity(session.GenerateEntityKey(id, persister)));
        }
Пример #3
0
        public object Load(object id, object optionalObject, ISessionImplementor session)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("loading entity: {0} using named query: {1}", persister.EntityName, queryName));
            }

            AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedQuery(queryName);

            if (query.HasNamedParameters)
            {
                query.SetParameter(query.NamedParameters[0], id, persister.IdentifierType);
            }
            else
            {
                query.SetParameter(0, id, persister.IdentifierType);
            }
            query.SetOptionalId(id);
            query.SetOptionalEntityName(persister.EntityName);
            query.SetOptionalObject(optionalObject);
            query.SetFlushMode(FlushMode.Never);
            query.List();

            // now look up the object we are really interested in!
            // (this lets us correctly handle proxies and multi-row
            // or multi-column queries)
            return(session.PersistenceContext.GetEntity(new EntityKey(id, persister, session.EntityMode)));
        }
        public void Initialize(object key, ISessionImplementor session, IEntityPersister OwnerEntityPersister, object owner)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("initializing collection: {0} using named query: {1}", persister.Role, queryName));
            }

            //TODO: is there a more elegant way than downcasting?
            AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedSQLQuery(queryName);


            if (query.NamedParameters.Length > 0)
            {
                //این قسمت به دلیل حل نمودن مشکل
                //not all named parameters have been set
                //اضافه شده است
                #region MyCode
                try
                {
                    foreach (string parameter in query.NamedParameters)
                    {
                        string alias  = parameter.Split('.')[0];
                        int    length = parameter.Split('.').Length;
                        if (session.EnabledFilters.ContainsKey(alias))
                        {
                            query.SetParameter(parameter, session.GetFilterParameterValue(parameter));
                        }
                        else
                        {
                            if (length > 1)
                            {
                                string paramName = parameter.Split('.')[1];
                                object value     = OwnerEntityPersister.GetPropertyValue(owner, paramName, EntityMode.Poco);
                                if (value != null)
                                {
                                    query.SetParameter(parameter, value);
                                }
                            }
                            else
                            {
                                query.SetParameter(parameter, key, persister.KeyType);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format("{0}: {1}", "NamedQueryCollectionInitializer.Initialize", "خطا در کد نوشته شده توسط صفری نیا"), ex);
                }
                #endregion
            }
            query.SetCollectionKey(key).SetFlushMode(FlushMode.Never).List();
        }
Пример #5
0
        public void Initialize(object key, ISessionImplementor session)
        {
            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format("initializing collection: {0} using named query: {1}", persister.Role, queryName));
            }

            //TODO: is there a more elegant way than downcasting?
            AbstractQueryImpl query = (AbstractQueryImpl)session.GetNamedSQLQuery(queryName);

            if (query.NamedParameters.Length > 0)
            {
                query.SetParameter(query.NamedParameters[0], key, persister.KeyType);
            }
            else
            {
                query.SetParameter(0, key, persister.KeyType);
            }
            query.SetCollectionKey(key).SetFlushMode(FlushMode.Manual).List();
        }