Пример #1
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 {
                OrmHelper.CloseDataReader(record);
            }

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

            return(EntityPropertyUtil.setEntityProperty(condition.State, results, hashtable));
        }
Пример #2
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 {
                OrmHelper.CloseDataReader( record );
            }

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

            return EntityPropertyUtil.setEntityProperty( condition.State, results, hashtable );
        }
Пример #3
0
        /// <summary>
        /// 返回符合查询条件的前 n 条结果
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public IList list(int count)
        {

            processQueryString();
            SqlBuilder builder = new SqlBuilder(_state.EntityInfo.Type);
            String sql = builder.GetFindConditionSql(_selectItems, _whereStr, _namedParameters, count);

            // cache
            IList list = ObjectPool.FindByQuery(_state.EntityInfo.Type, sql, _namedParameters);
            if (list != null) return list;

            logger.Sql(LoggerUtil.SqlPrefix + "[FindBy]" + sql);

            ConditionInfo conditionInfo = new ConditionInfo();
            conditionInfo.Type = _state.EntityInfo.Type;
            conditionInfo.State = _state;
            conditionInfo.SelectedItem = _selectItems;
            conditionInfo.WhereString = _whereStr;
            conditionInfo.Parameters = _namedParameters;
            conditionInfo.Count = count;
            conditionInfo.Sql = sql;

            IList parentResults = FindByOperation.Find(conditionInfo);
            if (parentResults.Count > 0 && _state.EntityInfo.ChildEntityList.Count > 0 && _state.IsFindChild)
            {
                parentResults = findFromChild(parentResults);
            }

            // cache
            if ("*".Equals(_selectItems))
                ObjectPool.AddQueryList(_state.EntityInfo.Type, sql, _namedParameters, parentResults);

            return parentResults;
        }
Пример #4
0
 public IList FindByQuery( ConditionInfo condition )
 {
     return getListFromCache( CacheKey.getQuery( condition.Type, condition.Sql, condition.Parameters ), condition.Type );
 }
Пример #5
0
 public static IList FindByQuery( ConditionInfo condition ) {
     foreach (IObjectPool pool in pools) {
         IList result = pool.FindByQuery( condition );
         if (result != null) return result;
     }
     return null;
 }