示例#1
0
        /// <summary>
        /// Executes the SQL and retuns all rows selected in a map that is keyed on the property named
        /// in the keyProperty parameter.  The value at each key will be the value of the property specified
        /// in the valueProperty parameter.  If valueProperty is null, the entire result object will be entered.
        /// </summary>
        /// <param name="request">The request scope.</param>
        /// <param name="session">The session used to execute the statement</param>
        /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
        /// <param name="keyProperty">The property of the result object to be used as the key.</param>
        /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
        /// <param name="rowDelegate">A delegate called once per row in the QueryForMapWithRowDelegate method</param>
        /// <returns>A IDictionary of object containing the rows keyed by keyProperty.</returns>
        ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
        internal IDictionary <TKey, TValue> RunQueryForDictionary <TKey, TValue>(RequestScope request,
                                                                                 ISession session,
                                                                                 object parameterObject,
                                                                                 string keyProperty,
                                                                                 string valueProperty,
                                                                                 DictionaryRowDelegate <TKey, TValue> rowDelegate)
        {
            IDictionary <TKey, TValue> map = new Dictionary <TKey, TValue>();

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    if (rowDelegate == null)
                    {
                        while (reader.Read())
                        {
                            object obj   = resultStrategy.Process(request, ref reader, null);
                            TKey   key   = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
                            TValue value = default(TValue);
                            if (valueProperty != null)
                            {
                                value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
                            }
                            else
                            {
                                value = (TValue)obj;
                            }
                            map.Add(key, value);
                        }
                    }
                    else
                    {
                        while (reader.Read())
                        {
                            object obj   = resultStrategy.Process(request, ref reader, null);
                            TKey   key   = (TKey)ObjectProbe.GetMemberValue(obj, keyProperty, request.DataExchangeFactory.AccessorFactory);
                            TValue value = default(TValue);
                            if (valueProperty != null)
                            {
                                value = (TValue)ObjectProbe.GetMemberValue(obj, valueProperty, request.DataExchangeFactory.AccessorFactory);
                            }
                            else
                            {
                                value = (TValue)obj;
                            }
                            rowDelegate(key, value, parameterObject, map);
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
                ExecuteDelayedLoad(request);
            }
            return(map);
        }
 protected IDictionary QueryForMapWithRowDelegate(string statementName, object parameterObject,
                                                  string keyProperty,
                                                  string valueProperty,
                                                  DictionaryRowDelegate rowDelegate)
 {
     return
         (mapper.QueryForMapWithRowDelegate(statementName, parameterObject, keyProperty, valueProperty,
                                            rowDelegate));
 }
 /// <summary>
 /// Runs a query with a custom object that gets a chance
 /// to deal with each row as it is processed.
 /// </summary>
 /// <param name="session">The session used to execute the statement</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
 /// <param name="keyProperty">The property of the result object to be used as the key. </param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate"></param>
 /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public override IDictionary ExecuteQueryForMapWithRowDelegate(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
 {
     throw new DataMapperException("Update statement cannot be executed as a query for row delegate.");
 }
示例#4
0
 /// <summary>
 /// Runs a query with a custom object that gets a chance
 /// to deal with each row as it is processed.
 /// </summary>
 /// <param name="session">The session used to execute the statement</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
 /// <param name="keyProperty">The property of the result object to be used as the key. </param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate"></param>
 /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 /// <exception cref="IBatisNet.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public IDictionary ExecuteQueryForMapWithRowDelegate(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
 {
     return(_mappedStatement.ExecuteQueryForMapWithRowDelegate(session, parameterObject, keyProperty, valueProperty, rowDelegate));
 }
示例#5
0
 /// <summary>
 /// Runs a query with a custom object that gets a chance to deal
 /// with each row as it is processed.
 /// <p/>
 /// The parameter object is generally used to supply the input
 /// data for the WHERE clause parameter(s) of the SELECT statement.
 /// </summary>
 /// <typeparam name="K"></typeparam>
 /// <typeparam name="V"></typeparam>
 /// <param name="statementId">The statement id.</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 /// <param name="keyProperty">The property of the result object to be used as the key.</param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate">A delegate called once per row in the QueryForDictionary method&gt;</param>
 /// <returns>
 /// A IDictionary (Hashtable) of object containing the rows keyed by keyProperty.
 /// </returns>
 /// <exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public IDictionary <K, V> QueryForDictionary <K, V>(string statementId, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate <K, V> rowDelegate)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteQueryForDictionary(sessionScope.Session, parameterObject, keyProperty, valueProperty, rowDelegate));
     }
 }
        public IDictionary QueryForMapWithRowDelegate(string statementName, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
        {
            bool           flag         = false;
            ISqlMapSession localSession = this._sessionStore.LocalSession;
            IDictionary    dictionary   = null;

            if (localSession == null)
            {
                localSession = this.CreateSqlMapSession();
                flag         = true;
            }
            try
            {
                dictionary = this.GetMappedStatement(statementName).ExecuteQueryForMapWithRowDelegate(localSession, parameterObject, keyProperty, valueProperty, rowDelegate);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (flag)
                {
                    localSession.CloseConnection();
                }
            }
            return(dictionary);
        }
示例#7
0
 /// <summary>
 /// Runs a query with a custom object that gets a chance
 /// to deal with each row as it is processed.
 /// </summary>
 /// <remarks>
 /// This method always bypasses the cache.
 /// </remarks>
 /// <param name="session">The session used to execute the statement</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
 /// <param name="keyProperty">The property of the result object to be used as the key. </param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate"></param>
 /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 /// <exception cref="MyBatis.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public IDictionary ExecuteQueryForMapWithRowDelegate(ISession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
 {
     // TODO: investigate allow the cached data to be processed by a different rowDelegate...add rowDelegate to the CacheKey ???
     return(mappedStatement.ExecuteQueryForMapWithRowDelegate(session, parameterObject, keyProperty, valueProperty, rowDelegate));
 }
示例#8
0
 /// <summary>
 /// Runs a query with a custom object that gets a chance
 /// to deal with each row as it is processed.
 /// </summary>
 /// <remarks>
 /// This method always bypasses the cache.
 /// </remarks>
 /// <param name="session">The session used to execute the statement</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
 /// <param name="keyProperty">The property of the result object to be used as the key. </param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate"></param>
 /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 /// <exception cref="MyBatis.DataMapper.Exceptions.DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public IDictionary <K, V> ExecuteQueryForDictionary <K, V>(ISession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate <K, V> rowDelegate)
 {
     return(mappedStatement.ExecuteQueryForDictionary(session, parameterObject, keyProperty, valueProperty, rowDelegate));
 }
 /// <summary>
 /// Runs a query with a custom object that gets a chance 
 /// to deal with each row as it is processed.
 /// </summary>
 /// <param name="session">The session used to execute the statement</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
 /// <param name="keyProperty">The property of the result object to be used as the key. </param>
 /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
 /// <param name="rowDelegate"></param>
 /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
 ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
 public override IDictionary ExecuteQueryForMapWithRowDelegate(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate )
 {
     throw new DataMapperException("Insert statements cannot be executed as a query for row delegate.");
 }
示例#10
0
        internal IDictionary RunQueryForMap(RequestScope request, ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
        {
            IDictionary dictionary = new Hashtable();

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    object obj5;
                    if (rowDelegate != null)
                    {
                        goto Label_00C4;
                    }
                    while (reader.Read())
                    {
                        object obj2 = this._resultStrategy.Process(request, ref reader, null);
                        object obj3 = ObjectProbe.GetMemberValue(obj2, keyProperty, request.DataExchangeFactory.AccessorFactory);
                        object obj4 = obj2;
                        if (valueProperty != null)
                        {
                            obj4 = ObjectProbe.GetMemberValue(obj2, valueProperty, request.DataExchangeFactory.AccessorFactory);
                        }
                        dictionary.Add(obj3, obj4);
                    }
                    goto Label_00E0;
Label_0072:
                    obj5 = this._resultStrategy.Process(request, ref reader, null);
                    object key  = ObjectProbe.GetMemberValue(obj5, keyProperty, request.DataExchangeFactory.AccessorFactory);
                    object obj7 = obj5;
                    if (valueProperty != null)
                    {
                        obj7 = ObjectProbe.GetMemberValue(obj5, valueProperty, request.DataExchangeFactory.AccessorFactory);
                    }
                    rowDelegate(key, obj7, parameterObject, dictionary);
Label_00C4:
                    if (reader.Read())
                    {
                        goto Label_0072;
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
Label_00E0:
                this.ExecutePostSelect(request);
            }
            return(dictionary);
        }
示例#11
0
        internal IDictionary <K, V> RunQueryForDictionary <K, V>(RequestScope request, ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate <K, V> rowDelegate)
        {
            IDictionary <K, V> dictionary = new Dictionary <K, V>();

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    object obj3;
                    if (rowDelegate != null)
                    {
                        goto Label_00F6;
                    }
                    while (reader.Read())
                    {
                        object obj2   = this._resultStrategy.Process(request, ref reader, null);
                        K      local  = (K)ObjectProbe.GetMemberValue(obj2, keyProperty, request.DataExchangeFactory.AccessorFactory);
                        V      local2 = default(V);
                        if (valueProperty != null)
                        {
                            local2 = (V)ObjectProbe.GetMemberValue(obj2, valueProperty, request.DataExchangeFactory.AccessorFactory);
                        }
                        else
                        {
                            local2 = (V)obj2;
                        }
                        dictionary.Add(local, local2);
                    }
                    goto Label_0112;
Label_008B:
                    obj3 = this._resultStrategy.Process(request, ref reader, null);
                    K key    = (K)ObjectProbe.GetMemberValue(obj3, keyProperty, request.DataExchangeFactory.AccessorFactory);
                    V local4 = default(V);
                    if (valueProperty != null)
                    {
                        local4 = (V)ObjectProbe.GetMemberValue(obj3, valueProperty, request.DataExchangeFactory.AccessorFactory);
                    }
                    else
                    {
                        local4 = (V)obj3;
                    }
                    rowDelegate(key, local4, parameterObject, dictionary);
Label_00F6:
                    if (reader.Read())
                    {
                        goto Label_008B;
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }
Label_0112:
                this.ExecutePostSelect(request);
            }
            return(dictionary);
        }
示例#12
0
        public virtual IDictionary ExecuteQueryForMapWithRowDelegate(ISqlMapSession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate rowDelegate)
        {
            RequestScope request = this._statement.Sql.GetRequestScope(this, parameterObject, session);

            if (rowDelegate == null)
            {
                throw new DataMapperException("A null DictionaryRowDelegate was passed to QueryForMapWithRowDelegate.");
            }
            this._preparedCommand.Create(request, session, this.Statement, parameterObject);
            return(this.RunQueryForMap(request, session, parameterObject, keyProperty, valueProperty, rowDelegate));
        }
示例#13
0
        /// <summary>
        /// Runs a query with a custom object that gets a chance
        /// to deal with each row as it is processed.
        /// </summary>
        /// <param name="session">The session used to execute the statement</param>
        /// <param name="parameterObject">The object used to set the parameters in the SQL. </param>
        /// <param name="keyProperty">The property of the result object to be used as the key. </param>
        /// <param name="valueProperty">The property of the result object to be used as the value (or null)</param>
        /// <param name="rowDelegate">A delegate called once per row in the QueryForDictionary method</param>
        /// <returns>A hashtable of object containing the rows keyed by keyProperty.</returns>
        ///<exception cref="DataMapperException">If a transaction is not in progress, or the database throws an exception.</exception>
        public virtual IDictionary <K, V> ExecuteQueryForDictionary <K, V>(ISession session, object parameterObject, string keyProperty, string valueProperty, DictionaryRowDelegate <K, V> rowDelegate)
        {
            if (rowDelegate == null)
            {
                throw new DataMapperException("A null DictionaryRowDelegate was passed to QueryForDictionary.");
            }

            return(Execute(PreSelectEventKey, PostSelectEventKey, session, parameterObject,
                           (r, p) => RunQueryForDictionary(r, session, p, keyProperty, valueProperty, rowDelegate)));
        }