Exemplo n.º 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;
        }
Exemplo n.º 2
0
 /// <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;
 }
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
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 );
     }
 }
Exemplo n.º 5
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) {

                        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;
        }
Exemplo n.º 6
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 );

                    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 );
        }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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.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;
        }
Exemplo n.º 9
0
 public static IList FindPage( ObjectInfo state, String condition )
 {
     return FindPageOperation.FindPage( state, condition );
 }
Exemplo n.º 10
0
        /// <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;
        }
Exemplo n.º 11
0
 public static IList FindAll( ObjectInfo state )
 {
     return FindAllOperation.FindAll( state );
 }
Exemplo n.º 12
0
 public static Query Find( ObjectInfo obj, String condition )
 {
     return FindByOperation.Find( condition, obj );
 }
Exemplo n.º 13
0
 public ObjectInfo Copy(ObjectInfo state)
 {
     CacheMinutes = state.CacheMinutes;
     Order = state.Order;
     IsFindChild = state.IsFindChild;
     return this;
 }
Exemplo n.º 14
0
Arquivo: Query.cs Projeto: jmyd/oms
        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;
                }

            }
        }
Exemplo n.º 15
0
 public static IEntity FindById( int id, ObjectInfo state )
 {
     return FindByIdOperation.FindById( id, state );
 }
Exemplo n.º 16
0
Arquivo: Query.cs Projeto: jmyd/oms
 public Query( String queryString, ObjectInfo state )
 {
     _whereStr = queryString.Trim();
     _state = state;
 }
Exemplo n.º 17
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 );
        }
Exemplo n.º 18
0
 /// <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 );
 }
Exemplo n.º 19
0
 public Query(String queryString, ObjectInfo state)
 {
     _whereStr = queryString.Trim();
     _state    = state;
 }