Beispiel #1
0
        public void TestMappedStatementQueryWithReadWriteCacheWithSession()
        {
            IMappedStatement statement = sqlMap.GetMappedStatement("GetRWNSCachedAccountsViaResultMap");
            ISqlMapSession   session   = new SqlMapSession(sqlMap);

            session.OpenConnection();

            int firstId  = 0;
            int secondId = 0;

            try
            {
                // execute the statement twice; the second call should result in a cache hit
                IList list = statement.ExecuteQueryForList(session, null);
                firstId = HashCodeProvider.GetIdentityHashCode(list);

                list     = statement.ExecuteQueryForList(session, null);
                secondId = HashCodeProvider.GetIdentityHashCode(list);
            }
            finally
            {
                session.CloseConnection();
            }

            Assert.AreEqual(firstId, secondId);
        }
        public object GetValue(RequestScope request, ResultProperty mapping, ref IDataReader reader, object keys)
        {
            IMappedStatement mappedStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select);

            if (mapping.MemberType == typeof(IList))
            {
                reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
                return(mappedStatement.ExecuteQueryForList(request.Session, keys));
            }
            reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
            object obj2 = request.DataExchangeFactory.ObjectFactory.CreateFactory(mapping.MemberType, Type.EmptyTypes).CreateInstance(null);

            mappedStatement.ExecuteQueryForList(request.Session, keys, (IList)obj2);
            return(obj2);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="localPageSize"></param>
        /// <returns></returns>
        private IList GetList(int index, int localPageSize)
        {
            bool isSessionLocal = false;

            ISqlMapSession session = _mappedStatement.SqlMap.LocalSession;

            if (session == null)
            {
                session = new SqlMapSession(_mappedStatement.SqlMap);
                session.OpenConnection();
                isSessionLocal = true;
            }

            IList list = null;

            try
            {
                list = _mappedStatement.ExecuteQueryForList(session, _parameterObject, (index) * _pageSize, localPageSize);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (isSessionLocal)
                {
                    session.CloseConnection();
                }
            }

            return(list);
        }
Beispiel #4
0
 /// <summary>
 /// Executes a Sql SELECT statement that returns data to populate
 /// a number of result objects.
 /// <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="T"></typeparam>
 /// <param name="statementId">The statement id.</param>
 /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
 /// <returns>A List of result objects.</returns>
 public IList <T> QueryForList <T>(string statementId, object parameterObject)
 {
     using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
     {
         IMappedStatement statement = GetMappedStatement(statementId);
         return(statement.ExecuteQueryForList <T>(sessionScope.Session, parameterObject));
     }
 }
        /// <summary>
        /// Gets the value of an argument constructor.
        /// </summary>
        /// <param name="request">The current <see cref="RequestScope"/>.</param>
        /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
        /// <param name="reader">The current <see cref="IDataReader"/>.</param>
        /// <param name="keys">The keys</param>
        /// <returns>The paremeter value.</returns>
        public object GetValue(RequestScope request, ResultProperty mapping,
                               ref IDataReader reader, object keys)
        {
            // Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            if (mapping.MemberType == typeof(IList))
            {
                reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
                return(selectStatement.ExecuteQueryForList(request.Session, keys));
            }
            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
            IFactory factory = request.DataExchangeFactory.ObjectFactory.CreateFactory(mapping.MemberType, Type.EmptyTypes);
            object   values  = factory.CreateInstance(null);

            selectStatement.ExecuteQueryForList(request.Session, keys, (IList)values);
            return(values);
        }
Beispiel #6
0
        /// <summary>
        /// Executes a Sql SELECT statement that returns data to populate
        /// a number of result objects.
        /// <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="T"></typeparam>
        /// <param name="statementId">The statement id.</param>
        /// <param name="parameterObject">The object used to set the parameters in the SQL.</param>
        /// <param name="resultObject">An Ilist object used to hold the objects.</param>
        public void QueryForList <T>(string statementId, object parameterObject, IList <T> resultObject)
        {
            if (resultObject == null)
            {
                throw new DataMapperException("resultObject parameter must be instantiated before being passed to SqlMapper.QueryForList");
            }

            using (var sessionScope = new DataMapperLocalSessionScope(sessionStore, sessionFactory))
            {
                IMappedStatement statement = GetMappedStatement(statementId);
                statement.ExecuteQueryForList(sessionScope.Session, parameterObject, resultObject);
            }
        }
Beispiel #7
0
            public void Run()
            {
                try
                {
                    IMappedStatement statement = _sqlMap.GetMappedStatement(_statementName);
                    ISqlMapSession   session   = new SqlMapSession(sqlMap);
                    session.OpenConnection();
                    IList list = statement.ExecuteQueryForList(session, null);

                    //int firstId = HashCodeProvider.GetIdentityHashCode(list);

                    list = statement.ExecuteQueryForList(session, null);
                    int secondId = HashCodeProvider.GetIdentityHashCode(list);

                    _results["id"]   = secondId;
                    _results["list"] = list;
                    session.CloseConnection();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
Beispiel #8
0
            public void Run()
            {
                try
                {
                    IMappedStatement statement = ((IModelStoreAccessor)dataMapper).ModelStore.GetMappedStatement(statementName);
                    ISession         session   = sessionFactory.OpenSession();
                    session.OpenConnection();

                    IList list = statement.ExecuteQueryForList(session, null);

                    int firstId = HashCodeProvider.GetIdentityHashCode(list);

                    list = statement.ExecuteQueryForList(session, null);
                    int secondId = HashCodeProvider.GetIdentityHashCode(list);

                    results["id"]   = secondId;
                    results["list"] = list;
                    session.Close();
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        public object GetValue(RequestScope request, ResultProperty mapping, ref IDataReader reader, object keys)
        {
            IMappedStatement mappedStatement = request.MappedStatement.SqlMap.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.DataSource.DbProvider);
            IList list  = mappedStatement.ExecuteQueryForList(request.Session, keys);
            Array array = Array.CreateInstance(mapping.MemberType.GetElementType(), list.Count);
            int   count = list.Count;

            for (int i = 0; i < count; i++)
            {
                array.SetValue(list[i], i);
            }
            return(array);
        }
        /// <summary>
        /// Gets the value of an argument constructor.
        /// </summary>
        /// <param name="request">The current <see cref="RequestScope"/>.</param>
        /// <param name="mapping">The <see cref="ResultProperty"/> with the argument infos.</param>
        /// <param name="reader">The current <see cref="IDataReader"/>.</param>
        /// <param name="keys">The keys</param>
        /// <returns>The paremeter value.</returns>
        public object GetValue(RequestScope request, ResultProperty mapping,
                               ref IDataReader reader, object keys)
        {
            // Get the select statement
            IMappedStatement selectStatement = request.MappedStatement.ModelStore.GetMappedStatement(mapping.Select);

            reader = DataReaderTransformer.Transform(reader, request.Session.SessionFactory.DataSource.DbProvider);
            IList values = selectStatement.ExecuteQueryForList(request.Session, keys);

            Type  elementType = mapping.MemberType.GetElementType();
            Array array       = Array.CreateInstance(elementType, values.Count);
            int   count       = values.Count;

            for (int i = 0; i < count; i++)
            {
                array.SetValue(values[i], i);
            }
            return(array);
        }