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; }
/// <summary> /// 查询 t 类型对象的所有数据 /// </summary> /// <param name="t"></param> /// <returns></returns> public static IList findAll( Type t ) { ObjectInfo state = new ObjectInfo( t ); state.includeAll(); IList objList = ObjectPool.FindAll( t ); if (objList == null) { objList = ObjectDB.FindAll( state ); ObjectPool.AddAll( t, objList ); } return objList; }
/// <summary> /// 根据 id 查询对象 /// </summary> /// <param name="t">对象的类型</param> /// <param name="id">对象的 id</param> /// <returns></returns> public static IEntity findById( Type t, long id ) { if (id < 0) return null; IEntity objCache = ObjectPool.FindOne( t, id ); if (objCache == null) { ObjectInfo state = new ObjectInfo( t ); objCache = ObjectDB.FindById( id, state ); ObjectPool.Add( objCache ); } return objCache; }
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 ); } }
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) { Object objId = rd.GetValue( i ); setEntityPropertyValueById( obj, state, ep, cvt.ToLong( objId ) ); } else { ep.SetValue( obj, getReaderValue( rd, i, fdvalue, ep.Type ) ); } } catch (Exception ex) { String msg = string.Format( "{0}=>{1}_{2}", ex.Message, ep.Type.FullName, ep.Name ); logger.Error( msg ); logger.Error( ex.StackTrace ); throw new OrmException( msg, ex ); } } return obj; }
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 ); long id = Convert.ToInt64( 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 new OrmException( ex.Message, ex ); } finally { OrmHelper.CloseDataReader( rd ); } if (results.Count == 0) { return results; } return setEntityProperty( state, results, hashtable ); }
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; }
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.ToLong( 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; }
public static IList FindPage( ObjectInfo state, String condition ) { return FindPageOperation.FindPage( state, condition ); }
/// <summary> /// ���ݲ�ѯ���������ط�ҳ���ݼ��� /// </summary> /// <param name="t"></param> /// <param name="condition">��ѯ����</param> /// <param name="pageSize">ÿҳ����</param> /// <returns>��ҳ�����б��������ǰҳ���ܼ�¼������ҳ����</returns> public static IPageList findPage( Type t, String condition, int pageSize ) { ObjectInfo state = new ObjectInfo( t ); state.includeAll(); if (pageSize > 0) state.Pager.setSize( pageSize ); IList list = ObjectDB.FindPage( state, condition ); IPageList result = new PageList(); result.Results = list; result.PageCount = state.Pager.PageCount; result.RecordCount = state.Pager.RecordCount; result.Size = pageSize>0 ? pageSize: state.Pager.getSize(); result.PageBar = state.Pager.PageBar; result.Current = state.Pager.getCurrent(); return result; }
public static IList FindAll( ObjectInfo state ) { return FindAllOperation.FindAll( state ); }
public static Query Find( ObjectInfo obj, String condition ) { return FindByOperation.Find( condition, obj ); }
public ObjectInfo Copy(ObjectInfo state) { CacheMinutes = state.CacheMinutes; Order = state.Order; IsFindChild = state.IsFindChild; return this; }
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; } } }
public static IEntity FindById( int id, ObjectInfo state ) { return FindByIdOperation.FindById( id, state ); }
public Query( String queryString, ObjectInfo state ) { _whereStr = queryString.Trim(); _state = state; }
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 ); }
/// <summary> /// ����������ѯ /// </summary> /// <param name="t"></param> /// <param name="condition">��ѯ����</param> /// <returns>���ز�ѯ����Query�����Խ�һ����������ֵ�����õ����</returns> public static Query find( Type t, String condition ) { ObjectInfo state = new ObjectInfo( t ); return ObjectDB.Find( state, condition ); }
public Query(String queryString, ObjectInfo state) { _whereStr = queryString.Trim(); _state = state; }