Example #1
0
        public static Object Populate( IDataRecord rd, ObjectInfo state )
        {
            IEntity obj = Entity.New( state.EntityInfo.Type.FullName );
            // state
            //obj.state.Order = state.Order;

            for (int i = 0; i < rd.FieldCount; i++) {

                Object fdvalue = rd[i];

                if (fdvalue == null || fdvalue == DBNull.Value) continue;

                EntityPropertyInfo ep = state.EntityInfo.GetPropertyByColumn( rd.GetName( i ) );
                if (ep == null) continue;

                try {
                    if (ep.IsEntity || ep.IsAbstractEntity) {
                        setEntityPropertyValueById( obj, state, ep, rd.GetInt32( i ) );
                    }
                    else {
                        ep.SetValue( obj, getReaderValue( fdvalue, ep.Type ) );
                    }

                }
                catch (Exception ex) {
                    logger.Error( ex.Message + "=" + ep.Name + "_" + ep.Type );
                    logger.Error( ex.StackTrace );
                    throw ex;
                }

            }

            return obj;
        }
Example #2
0
 private static void setEntityPropertyValueById( IEntity obj, ObjectInfo state, EntityPropertyInfo property, int pid )
 {
     if (!property.IsAbstractEntity) {
         IEntity objValue = Entity.New( property.Type.FullName );
         objValue.Id = pid;
         // state
         //objValue.state = new ObjectInfo( property.Type ).Copy( state );
         IEntity objCache = ObjectPool.FindOne( property.Type, objValue.Id );
         if (objCache != null) {
             objValue = objCache;
         }
         obj.set( property.Name, objValue );
     }
 }
Example #3
0
        public static IList FindList( ObjectInfo state, String sql ) {
            IList results = new ArrayList();
            IDataReader rd = null;
            Hashtable hashtable = new Hashtable();
            IDbCommand command = DataFactory.GetCommand( sql, DbContext.getConnection( state.EntityInfo ) );
            try {
                rd = command.ExecuteReader();
                while (rd.Read()) {
                    IDataRecord record = rd;
                    Fill_EntityProperty_Ids( record, state.Includer.EntityPropertyList, ref hashtable );

                    int id = Convert.ToInt32( record["Id"] );
                    Object cache = ObjectPool.FindOne( state.EntityInfo.Type, id );

                    if (cache != null) {
                        results.Add( cache );
                    }
                    else {
                        results.Add( FillUtil.Populate( record, state ) );
                    }
                }
            }
            catch (Exception ex) {
                logger.Error( "sql=>" + sql );
                logger.Error( ex.Message );
                logger.Error( ex.StackTrace );
                throw ex;
            }
            finally
            {
                if (command.Connection.State != ConnectionState.Closed)
                {
                    command.Connection.Close();
                    command.Connection.Dispose();
                    OrmHelper.clostCount++;
                    LogManager.GetLogger("Class:System.ORM.Operation.EntityPropertyUtil Method:FindList").Info("数据库连接已关闭【" + OrmHelper.clostCount + "】");
                }
                OrmHelper.CloseDataReader(rd);
            }


            if (results.Count == 0) {
                return results;
            }
            return setEntityProperty( state, results, hashtable );
        }
Example #4
0
 public static IList setEntityProperty( ObjectInfo state, IList results, Hashtable _entityProperty_ids ) {
     Hashtable selectColumn = null;
     if (strUtil.HasText( state.Includer.SelectedProperty ) && (state.Includer.SelectedProperty != "*")) {
         selectColumn = SqlBuilder.GetIncludeSelectColumn( state.Includer.SelectedProperty, state.EntityInfo.EntityPropertyList );
     }
     else {
         selectColumn = Includer.getSelectColumnFromInclude( state.Includer.EntityPropertyList );
     }
     Hashtable propertyList = getEntityPropertyList( state.Includer.EntityPropertyList, _entityProperty_ids, selectColumn, state.Order );
     fillPropertyObjectToResultList( ref results, state.EntityInfo.Type, state.Includer.EntityPropertyList, propertyList );
     return results;
 }
Example #5
0
 public Query( String queryString, ObjectInfo state ) {
     _whereStr = queryString.Trim();
     _state = state;
 }
Example #6
0
        private void queryChildObjects( int parentResultsCount, ArrayList results, IList oldParentsList, String _no_cached_Ids ) {
            int icount = 0;
            foreach (EntityInfo info in _state.EntityInfo.ChildEntityList) {
                if (icount >= parentResultsCount) {
                    break;
                }


                ObjectInfo state = new ObjectInfo( info );
                IList list = ObjectDb.Find( state, String.Format( "Id in ({0})", _no_cached_Ids ) ).select( _selectItems ).list();

                for (int i = 0; i < list.Count; i++) {
                    IEntity objc = list[i] as IEntity;
                    // state
                    //objc.state = new ObjectInfo( objc.GetType() ).Copy( _state );
                    results.Add( objc );
                    oldParentsList.RemoveAt( getIndexOfObject( oldParentsList, objc ) );
                    ObjectPool.Add( objc );
                }

                if (list.Count > 0) {
                    icount += list.Count;
                }

            }
        }
Example #7
0
        public static IList FindBySql( String sql, Type type ) {

            IDatabaseDialect dialect = Entity.GetInfo( type ).Dialect;
            sql = dialect.GetLimit( sql );

            logger.Info( String.Format( "{0}[FindBySql]{1}", LoggerUtil.SqlPrefix, sql ) );

            ObjectInfo state = new ObjectInfo( type );// EntityFactory.New( type.FullName ).state;
            state.Includer.IncludeAll();
            return EntityPropertyUtil.FindList( state, sql );
        }
Example #8
0
 public static IList FindPage( ObjectInfo state, String condition ) {
     return FindPageOperation.FindPage( state, condition );
 }
Example #9
0
 public static Query Find( ObjectInfo obj, String condition ) {
     return FindByOperation.Find( condition, obj );
 }
Example #10
0
 public static IList FindAll(ObjectInfo state)
 {
     return(FindAllOperation.FindAll(state));
 }
Example #11
0
 public static IEntity FindById( int id, ObjectInfo state ) {
     return FindByIdOperation.FindById( id, state );
 }
Example #12
0
 public ObjectInfo Copy( ObjectInfo state ) {
     CacheMinutes = state.CacheMinutes;
     Order = state.Order;
     IsFindChild = state.IsFindChild;
     return this;
 }
Example #13
0
 public static IList FindPage(ObjectInfo state, String condition)
 {
     return(FindPageOperation.FindPage(state, condition));
 }
Example #14
0
 public static Query Find(ObjectInfo obj, String condition)
 {
     return(FindByOperation.Find(condition, obj));
 }
Example #15
0
        public static Hashtable getEntityPropertyList( IList _includeEntityPropertyList, Hashtable _ep_ids, Hashtable selectColumn, String order ) {
            Hashtable hashtable = new Hashtable();

            if (_includeEntityPropertyList == null) return hashtable;

            foreach (EntityPropertyInfo info in _includeEntityPropertyList) {
                String epIds = "";
                String[] arrIds = new String[] { };
                if (_ep_ids[info.ColumnName] != null)
                    arrIds = _ep_ids[info.ColumnName].ToString().Trim().TrimEnd( ',' ).Split( ',' );

                foreach (String strId in arrIds) {
                    IEntity cacheObj = ObjectPool.FindOne( info.EntityInfo.Type, cvt.ToInt( strId ) );
                    if (cacheObj != null) {
                        hashtable[getPropertyObjectKey( info.Name, cacheObj.Id )] = cacheObj;
                    }
                    else {
                        epIds = epIds + strId + ",";
                    }
                }
                epIds = epIds.TrimEnd( ',' );

                if (strUtil.IsNullOrEmpty( epIds )) continue;

                String col = selectColumn[info.Name].ToString().Trim().TrimEnd( ',' );
                if (string.Compare( col, "Id", true ) != 0) {
                    if (!col.Equals( "*" ) && (("," + col + ",").ToLower().IndexOf( ",id," ) < 0)) {
                        col = "Id," + col;
                    }

                    ObjectInfo cstate = new ObjectInfo( info.EntityInfo );
                    cstate.IsFindChild = true;
                    IList list = ObjectDb.Find( cstate, String.Format( "Id in ({0})", epIds ) ).list();

                    foreach (IEntity objItem in list) {
                        hashtable[getPropertyObjectKey( info.Name, objItem.Id )] = objItem;
                        ObjectPool.Add( objItem );
                    }

                }
            }

            return hashtable;
        }
Example #16
0
 public static IList FindAll( ObjectInfo state ) {
     return FindAllOperation.FindAll( state );
 }
Example #17
0
 public static IEntity FindById(int id, ObjectInfo state)
 {
     return(FindByIdOperation.FindById(id, state));
 }