Пример #1
0
        public static IList FindPage(ObjectInfo state, String queryString)
        {
            // see: System/Web/Mvc/Routes/RouteTool.cs, line 211

            if (state.Pager.getCurrent() <= 0)
            {
                int page = CurrentRequest.getCurrentPage();
                state.Pager.setCurrent(page);
            }

            if (queryString != null && queryString.ToLower().StartsWith("order "))
            {
                queryString = " " + queryString;
            }

            PageCondition pc = new PageCondition();

            pc.ConditionStr = queryString;
            pc.Property     = state.Includer.SelectedProperty;
            pc.CurrentPage  = state.Pager.getCurrent();
            pc.Size         = state.Pager.getSize();
            pc.OrderStr     = state.Order;
            pc.Pager        = state.Pager;

            String sql = new SqlBuilder(state.EntityInfo).GetPageSql(pc);

            return(EntityPropertyUtil.FindList(state, sql));
        }
Пример #2
0
        private static IList findAllPrivate(ObjectInfo state)
        {
            String sql = "select * from " + state.EntityInfo.TableName;

            logger.Info(LoggerUtil.SqlPrefix + "[" + state.EntityInfo.Name + "_FindAll]" + sql);

            return(EntityPropertyUtil.FindList(state, sql));
        }
Пример #3
0
        internal static IList Find(ConditionInfo condition)
        {
            IList results = ObjectPool.FindByQuery(condition);

            if (results != null)
            {
                return(results);
            }

            if ("*".Equals(condition.SelectedItem))
            {
                condition.State.includeAll();
            }
            else
            {
                condition.State.include(SqlBuilder.GetIncludeProperty(condition.SelectedItem));
            }

            IList      includeEntityPropertyList = condition.State.Includer.EntityPropertyList;
            IDbCommand cmd = DataFactory.GetCommand(condition.Sql, DbContext.getConnection(condition.State.EntityInfo));

            foreach (String key in condition.Parameters.Keys)
            {
                DataFactory.SetParameter(cmd, key, condition.Parameters[key]);
            }

            Hashtable   hashtable = new Hashtable();
            IDataReader record    = null;

            results = new ArrayList();
            try {
                record = cmd.ExecuteReader();
                while (record.Read())
                {
                    EntityPropertyUtil.Fill_EntityProperty_Ids(record, includeEntityPropertyList, ref hashtable);
                    results.Add(FillUtil.Populate(record, condition.State));
                }
            }
            catch (Exception ex) {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                throw new OrmException(ex.Message, ex);
            }
            finally {
                OrmHelper.CloseDataReader(record);
            }

            if (results.Count == 0)
            {
                return(results);
            }

            return(EntityPropertyUtil.setEntityProperty(condition.State, results, hashtable));
        }
Пример #4
0
        internal static IList Find(ConditionInfo condition)
        {
            IList results = ObjectPool.FindByQuery(condition);

            if (results != null)
            {
                return(results);
            }

            if ("*".Equals(condition.SelectedItem))
            {
                condition.State.includeAll();
            }
            else
            {
                condition.State.include(SqlBuilder.GetIncludeProperty(condition.SelectedItem));
            }

            IList      includeEntityPropertyList = condition.State.Includer.EntityPropertyList;
            IDbCommand cmd = DataFactory.GetCommand(condition.Sql, DbContext.getConnection(condition.State.EntityInfo));

            foreach (String key in condition.Parameters.Keys)
            {
                DataFactory.SetParameter(cmd, key, condition.Parameters[key]);
            }

            Hashtable   hashtable = new Hashtable();
            IDataReader record    = null;

            results = new ArrayList();
            try
            {
                record = cmd.ExecuteReader();
                while (record.Read())
                {
                    EntityPropertyUtil.Fill_EntityProperty_Ids(record, includeEntityPropertyList, ref hashtable);
                    results.Add(FillUtil.Populate(record, condition.State));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
                throw ex;
            }
            finally
            {
                if (!DbContext.shouldTransaction())
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                        cmd.Connection.Dispose();
                        OrmHelper.clostCount++;
                        LogManager.GetLogger("Class:System.ORM.Operation.FindByOperation Method:Find").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】");
                    }
                }
                OrmHelper.CloseDataReader(record);
            }

            if (results.Count == 0)
            {
                return(results);
            }

            return(EntityPropertyUtil.setEntityProperty(condition.State, results, hashtable));
        }