Example #1
0
 /// <summary>
 /// Initializes the <see cref="MapStrategy"/> class.
 /// </summary>
 static MapStrategy()
 {
     resultMapStrategy = new ResultMapStrategy();
     groupByStrategy = new GroupByStrategy();
     cirularStrategy = new CirularStrategy();
     dataTableStrategy = new DataRowStrategy();
 }
Example #2
0
        internal static DataTable RunQueryForDataTable(IStatement statement, RequestScope request, ISession session, object parameterObject)
        {
            IResultStrategy resultStrategy = ResultStrategyFactory.Get(statement);
            DataTable       dataTable      = new DataTable("DataTable");

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();

                try
                {
                    // Get Results
                    while (reader.Read())
                    {
                        DataRow dataRow = dataTable.NewRow();
                        dataTable.Rows.Add(dataRow);
                        resultStrategy.Process(request, ref reader, dataRow);
                    }
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }

                // do we need ??
                //ExecuteDelayedLoad(request);

                // do we need ??
                //RetrieveOutputParameters(request, session, command, parameterObject);
            }

            return(dataTable);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResultClassStrategy"/> class.
 /// </summary>
 public ResultClassStrategy()
 {
     _simpleTypeStrategy = new SimpleTypeStrategy();
     _dictionaryStrategy = new DictionaryStrategy();
     _listStrategy = new ListStrategy();
     _autoMapStrategy = new AutoMapStrategy();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResultClassStrategy"/> class.
 /// </summary>
 public ResultClassStrategy()
 {
     _simpleTypeStrategy = new SimpleTypeStrategy();
     _dictionaryStrategy = new DictionaryStrategy();
     _listStrategy       = new ListStrategy();
     _autoMapStrategy    = new AutoMapStrategy();
 }
Example #5
0
 /// <summary>
 /// Initializes the <see cref="MapStrategy"/> class.
 /// </summary>
 static MapStrategy()
 {
     resultMapStrategy = new ResultMapStrategy();
     groupByStrategy   = new GroupByStrategy();
     cirularStrategy   = new CirularStrategy();
     dataTableStrategy = new DataRowStrategy();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MappedStatement"/> class.
 /// </summary>
 /// <param name="modelStore">The model store.</param>
 /// <param name="statement">The statement.</param>
 public MappedStatement(IModelStore modelStore, IStatement statement)
 {
     this.modelStore = modelStore;
     this.statement  = statement;
     preparedCommand = new DefaultPreparedCommand();
     resultStrategy  = ResultStrategyFactory.Get(this.statement);
 }
Example #7
0
 internal MappedStatement(ISqlMapper sqlMap, IStatement statement)
 {
     this._sqlMap          = sqlMap;
     this._statement       = statement;
     this._preparedCommand = PreparedCommandFactory.GetPreparedCommand(false);
     this._resultStrategy  = ResultStrategyFactory.Get(this._statement);
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ResultClassStrategy"/> class.
 /// </summary>
 public ResultClassStrategy()
 {
     simpleTypeStrategy = new SimpleTypeStrategy();
     dictionaryStrategy = new DictionaryStrategy();
     listStrategy       = new ListStrategy();
     autoMapStrategy    = new AutoMapStrategy();
     dataTableStrategy  = new DataRowStrategy();
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="ResultClassStrategy"/> class.
		/// </summary>
		public ResultClassStrategy()
		{
			simpleTypeStrategy = new SimpleTypeStrategy();
			dictionaryStrategy = new DictionaryStrategy();
			listStrategy = new ListStrategy();
			autoMapStrategy = new AutoMapStrategy();
            dataTableStrategy = new DataRowStrategy();
		}
Example #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResultClassStrategy"/> class.
        /// </summary>
        public ResultClassStrategy()
        {
            _simpleTypeStrategy = new SimpleTypeStrategy();
            _dictionaryStrategy = new DictionaryStrategy();
            _listStrategy       = new ListStrategy();

            //*********************** Added ***********************
            _dataTableStrategy = new DataTableStrategy();
            _autoMapStrategy   = new AutoMapStrategy();
        }
Example #11
0
        internal static T RunQueryForObject <T>(IStatement statement, RequestScope request, ISession session, object parameterObject, T resultObject)
        {
            IResultStrategy resultStrategy = ResultStrategyFactory.Get(statement);
            T result = resultObject;

            using (IDbCommand command = request.IDbCommand)
            {
                IDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        object obj = resultStrategy.Process(request, ref reader, resultObject);
                        if (obj != BaseStrategy.SKIP)
                        {
                            result = (T)obj;
                        }
                    }
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }

                ExecuteDelayedLoad(request);

                #region remark
                // If you are using the OleDb data provider, you need to close the
                // DataReader before output parameters are visible.
                #endregion

                RetrieveOutputParameters(request, session, command, parameterObject);
            }

            return(result);
        }
 /// <summary>
 /// Initializes the <see cref="MapStrategy"/> class.
 /// </summary>
 static MapStrategy()
 {
     _resultMapStrategy = new ResultMapStrategy();
     _groupByStrategy   = new GroupByStrategy();
 }
Example #13
0
 /// <summary>
 /// Initializes the <see cref="ResultStrategyFactory"/> class.
 /// </summary>
 static ResultStrategyFactory()
 {
     _mapStrategy         = new MapStrategy();
     _resultClassStrategy = new ResultClassStrategy();
     _objectStrategy      = new ObjectStrategy();
 }
 /// <summary>
 /// Initializes the <see cref="ResultStrategyFactory"/> class.
 /// </summary>
 static ResultStrategyFactory()
 {
     _mapStrategy = new MapStrategy();
     _resultClassStrategy = new ResultClassStrategy();
     _objectStrategy = new ObjectStrategy();
 }
Example #15
0
 /// <summary>
 /// Initializes the <see cref="MapStrategy"/> class.
 /// </summary>
 static MapStrategy()
 {
     _resultMapStrategy = new ResultMapStrategy();
     _groupByStrategy = new GroupByStrategy();
 }
Example #16
0
        internal static IList RunQueryForList(IStatement statement, RequestScope request, ISession session, object parameterObject, IList resultObject, RowDelegate rowDelegate)
        {
            IResultStrategy resultStrategy = ResultStrategyFactory.Get(statement);
            IList           list           = resultObject;

            using (IDbCommand command = request.IDbCommand)
            {
                if (resultObject == null)
                {
                    if (statement.ListClass == null)
                    {
                        list = new ArrayList();
                    }
                    else
                    {
                        list = statement.CreateInstanceOfListClass();
                    }
                }

                IDataReader reader = command.ExecuteReader();

                try
                {
                    do
                    {
                        if (rowDelegate == null)
                        {
                            //***
                            IList currentList = null;
                            if (request.Statement.ResultsMap.Count == 1)
                            {
                                currentList = list;
                            }
                            else
                            {
                                if (request.CurrentResultMap != null)
                                {
                                    Type genericListType = typeof(List <>).MakeGenericType(new Type[] { request.CurrentResultMap.Class });
                                    currentList = (IList)Activator.CreateInstance(genericListType);
                                }
                                else
                                {
                                    currentList = new ArrayList();
                                }
                                list.Add(currentList);
                            }
                            //***
                            while (reader.Read())
                            {
                                //将reader当前行中的所有字段加入到IList对象中,即obj中
                                object obj = resultStrategy.Process(request, ref reader, null);
                                if (obj != BaseStrategy.SKIP)
                                {
                                    //list.Add(obj);
                                    currentList.Add(obj);
                                }
                            }
                        }
                        else
                        {
                            while (reader.Read())
                            {
                                object obj = resultStrategy.Process(request, ref reader, null);
                                rowDelegate(obj, parameterObject, list);
                            }
                        }
                    }while (reader.NextResult());
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }

                ExecuteDelayedLoad(request);
                RetrieveOutputParameters(request, session, command, parameterObject);
            }

            return(list);
        }
Example #17
0
        internal static IList <T> RunQueryForList <T>(IStatement statement, RequestScope request, ISession session, object parameterObject, IList <T> resultObject, RowDelegate <T> rowDelegate)
        {
            IResultStrategy resultStrategy = ResultStrategyFactory.Get(statement);
            IList <T>       list           = resultObject;

            using (IDbCommand command = request.IDbCommand)
            {
                if (resultObject == null)
                {
                    if (statement.ListClass == null)
                    {
                        list = new List <T>();
                    }
                    else
                    {
                        list = statement.CreateInstanceOfGenericListClass <T>();
                    }
                }

                IDataReader reader = command.ExecuteReader();
                try
                {
                    do
                    {
                        if (rowDelegate == null)
                        {
                            while (reader.Read())
                            {
                                try
                                {
                                    object obj = resultStrategy.Process(request, ref reader, null);
                                    if (obj != BaseStrategy.SKIP)
                                    {
                                        list.Add((T)obj);
                                    }
                                }
                                catch (Exception ed)
                                {
                                    string ms = ed.Message;
                                }
                            }
                        }
                        else
                        {
                            while (reader.Read())
                            {
                                T obj = (T)resultStrategy.Process(request, ref reader, null);
                                rowDelegate(obj, parameterObject, list);
                            }
                        }
                    }while (reader.NextResult());
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }

                ExecuteDelayedLoad(request);
                RetrieveOutputParameters(request, session, command, parameterObject);
            }

            return(list);
        }