AgileEAS.NET之ORM访问器
生活随笔
收集整理的這篇文章主要介紹了
AgileEAS.NET之ORM访问器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
上一篇文章AgileEAS.NET之數據關系映射ORM簡單介紹了一下AgileEAS.NET平臺中ORM對象的組織機構體系,但并沒有對其所執行的數據存取操作介紹,在AgileEAS.NET中,我對ORM實體及其上的數據操作實現進行了分離,實體對象只呈現數據,而實體的增加、修改、更新、刪除、緩存操作都通過ORM訪問器實現。 在AgileEAS.NET兩個訪問器IOrmAccessor和ICacheAccessor訪問器。 IOrmAccessor完成ORM對象(實體和表)和數據庫的交互工作:查詢、增加、修改、刪除極其輔助任務,其接口詳細定義如下: /// <summary>/// 定義ORM訪問器接口。 /// </summary>public interface IOrmAccessor : IOrmEnvironment{/// <summary>/// 保存數據實體。/// </summary>/// <param name="entity">數據實體。</param>void Save(IEntity entity);/// <summary>/// 保存數據表。/// </summary>/// <param name="table">表。</param>void Save(ITable table);/// <summary>/// 保存數據表。/// </summary>/// <param name="table">表。</param>/// <param name="force">是否強制同步到數據庫。</param>void Save(ITable table,bool force);/// <summary>/// 保存數據表。/// </summary>/// <param name="table">表。</param>/// <param name="force">是否強制同步到數據庫。</param>/// <param name="transaction">數據同步過程中是否使用事務。</param>void Save(ITable table, bool force, bool transaction);/// <summary>/// 保存數據架構。/// </summary>/// <param name="schema">架構。</param>void Save(ISchema schema);/// <summary>/// 保存數據架構。/// </summary>/// <param name="schema">架構。</param>/// <param name="force">是否強制同步到數據庫。</param> void Save(ISchema schema, bool force);/// <summary>/// 保存數據架構。/// </summary>/// <param name="schema">架構。</param>/// <param name="force">是否強制同步到數據庫。</param> /// <param name="transaction">數據同步過程中是否使用事務。</param>void Save(ISchema schema, bool force, bool transaction);/// <summary>/// 插入數據實體。/// </summary>/// <param name="entity">實體。</param>void Insert(IEntity entity);/// <summary>/// 修改數據實體。/// </summary>/// <param name="entity">實體。</param>void Update(IEntity entity);/// <summary>/// 刪除數據實體。/// </summary>/// <param name="entity">實體。</param>void Delete(IEntity entity);/// <summary>/// 刪除數據表。/// </summary>/// <param name="table">數據表。</param>/// <remarks>/// 本方法相當于數據批量刪除,一次性刪除多條記錄。/// </remarks>/// <remarks>刪除的記錄數。</remarks> int Delete(ITable table);/// <summary>/// 根據條件刪除數據表中記錄。/// </summary>/// <param name="table">數據表。</param>/// <param name="condition">數據過濾條件。</param> /// <remarks>刪除的記錄數。</remarks>int Delete(ITable table, Condition condition);/// <summary>/// 刪除數據架構。/// </summary>/// <param name="schema">架構。</param>/// <remarks>/// 本方法相當于數據批量刪除,一次刪除多表多條記錄。/// </remarks> void Delete(ISchema schema); /// <summary>/// 刷新數據實體。/// </summary>/// <param name="entity">實體。</param>/// <returns>數據庫中存在指定的數據體則返回true。</returns>bool Refresh(IEntity entity);/// <summary>/// 查詢數據實體。/// </summary>/// <param name="entity">實體。</param>/// <returns>數據庫中存在指定的數據體則返回true。</returns>bool Query(IEntity entity);/// <summary>/// 判讀實體是否存在于數據庫。/// </summary>/// <param name="entity">實體。</param>bool ExistsInDb(IEntity entity);/// <summary>/// 表查詢。/// </summary>/// <param name="table">表。</param>void Query(ITable table);/// <summary>/// 表查詢。/// </summary>/// <param name="table">表。</param> /// <param name="top">Top查詢。</param>void Query(ITable table,int top);/// <summary>/// 表查詢。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>void Query(ITable table, Condition condition);/// <summary>/// 表查詢。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>/// <param name="top">Top查詢。</param>void Query(ITable table, Condition condition, int top);/// <summary>/// 查詢數據表。/// </summary>/// <param name="table">表。</param>DataTable GetDataTable(ITable table);/// <summary>/// 查詢數據表。/// </summary>/// <param name="table">表。</param> /// <param name="top">Top查詢。</param>DataTable GetDataTable(ITable table, int top);/// <summary>/// 查詢數據表。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>DataTable GetDataTable(ITable table, Condition condition);/// <summary>/// 查詢數據表。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>/// <param name="top">Top查詢。</param>DataTable GetDataTable(ITable table, Condition condition, int top);}
} ICacheAccessor完成ORM對象的緩存查詢及其輔助任務,其接口詳細定義如下: /// <summary>/// 緩存訪問器接口。/// </summary>/// <remarks>/// 為ORM對象提供緩存查詢能力。/// </remarks>public interface ICacheAccessor : IOrmEnvironment{/// <summary>/// 緩存刷新實體。/// </summary>/// <param name="entity">實體。</param>void CacheRefresh(IEntity entity);/// <summary>/// 表緩存查詢。/// </summary>/// <param name="table">表。</param>void CacheQuery(ITable table);/// <summary>/// 表緩存查詢。/// </summary>/// <param name="table">表。</param> /// <param name="top">Top查詢。</param>void CacheQuery(ITable table, int top);/// <summary>/// 表緩存查詢。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>void CacheQuery(ITable table, Condition condition);/// <summary>/// 表緩存查詢。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>/// <param name="top">Top查詢。</param>void CacheQuery(ITable table, Condition condition, int top);/// <summary>/// 緩存查詢數據表。/// </summary>/// <param name="table">表。</param>DataTable GetCacheDataTable(ITable table);/// <summary>/// 緩存查詢數據表。/// </summary>/// <param name="table">表。</param> /// <param name="top">Top查詢。</param>DataTable GetCacheDataTable(ITable table, int top);/// <summary>/// 緩存查詢數據表。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>DataTable GetCacheDataTable(ITable table, Condition condition);/// <summary>/// 緩存查詢數據表。/// </summary>/// <param name="table">表。</param>/// <param name="condition">數據查詢條件。</param>/// <param name="top">Top查詢。</param>DataTable GetCacheDataTable(ITable table, Condition condition, int top);}
IOrmAccessor和ICacheAccessor都基于一個共同的接口IOrmEnvironment,IOrmEnvironment寓意為ORM操縱環境,根據類圖可以看到IOrmAccessor和ICacheAccessor也堅決的繼續于接口ISessionResource(會話資源),關我在后面的文章中專門介紹。 關于IOrmAccessor和ICacheAccessor詳細方法和具體的實現思路我在本文暫時不做介紹,在AgileEAS.NET實現了基于本地數據訪問器IDataAccessor的ORM實現,也實現了基于分布式WebService和Remoting的ORM訪問器實現,在開發和使用過程中,同一實體對象可以在不同的ORM訪問器中進行切換,只需要修改配置文件: 使用本地數據訪問器: <object name="MasterDbConnection" assembly="EAS.Data" type="EAS.Data.Access.OleDbConnection" LifestyleType="Singleton"><property name="ConnectionString" type="string" value="..." /> </object> <object name="OrmAccessor" assembly="EAS.Data" type="EAS.Data.ORM.OrmAccessor" LifestyleType="Singleton"><property name="DbConnection" type="object" value="MasterDbConnection" /> </object> <object name="CacheAccessor" assembly="EAS.Data" type="EAS.Data.ORM.CacheAccessor" LifestyleType="Singleton"> </object> 使用基于WebService實現的分布式訪問器: <object name="MasterDataAccessor" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.DataAccessor" LifestyleType="Singleton"><constructor-arg index="0" type="string" value="http://vm2003/Distributed/DataAccessService.asmx" /> </object> <object name="MasterRMIAccessor" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.RMIAccessor" LifestyleType="Singleton"><constructor-arg index="0" type="string" value="http://vm2003/Distributed/RMIService.asmx" /> </object> <object name="OrmTranser" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.OrmAccessor" LifestyleType="Singleton"><property name="DataAccessor" type="object" value="MasterDataAccessor" /><property name="RMIAccessor" type="object" value="MasterRMIAccessor" /> </object>
下一篇文章我簡單說一下數據實現和UI的綁帶。 QQ群:120661978,125643764 鏈接:AgileEAS.NET應用開發平臺介紹 AgileEAS.NET之敏捷并行開發方法 敏捷軟件工程實驗室
IOrmAccessor和ICacheAccessor都基于一個共同的接口IOrmEnvironment,IOrmEnvironment寓意為ORM操縱環境,根據類圖可以看到IOrmAccessor和ICacheAccessor也堅決的繼續于接口ISessionResource(會話資源),關我在后面的文章中專門介紹。 關于IOrmAccessor和ICacheAccessor詳細方法和具體的實現思路我在本文暫時不做介紹,在AgileEAS.NET實現了基于本地數據訪問器IDataAccessor的ORM實現,也實現了基于分布式WebService和Remoting的ORM訪問器實現,在開發和使用過程中,同一實體對象可以在不同的ORM訪問器中進行切換,只需要修改配置文件: 使用本地數據訪問器: <object name="MasterDbConnection" assembly="EAS.Data" type="EAS.Data.Access.OleDbConnection" LifestyleType="Singleton"><property name="ConnectionString" type="string" value="..." /> </object> <object name="OrmAccessor" assembly="EAS.Data" type="EAS.Data.ORM.OrmAccessor" LifestyleType="Singleton"><property name="DbConnection" type="object" value="MasterDbConnection" /> </object> <object name="CacheAccessor" assembly="EAS.Data" type="EAS.Data.ORM.CacheAccessor" LifestyleType="Singleton"> </object> 使用基于WebService實現的分布式訪問器: <object name="MasterDataAccessor" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.DataAccessor" LifestyleType="Singleton"><constructor-arg index="0" type="string" value="http://vm2003/Distributed/DataAccessService.asmx" /> </object> <object name="MasterRMIAccessor" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.RMIAccessor" LifestyleType="Singleton"><constructor-arg index="0" type="string" value="http://vm2003/Distributed/RMIService.asmx" /> </object> <object name="OrmTranser" assembly="EAS.Distributed.WebServiceClient" type="EAS.Distributed.WebServiceClient.OrmAccessor" LifestyleType="Singleton"><property name="DataAccessor" type="object" value="MasterDataAccessor" /><property name="RMIAccessor" type="object" value="MasterRMIAccessor" /> </object>
下一篇文章我簡單說一下數據實現和UI的綁帶。 QQ群:120661978,125643764 鏈接:AgileEAS.NET應用開發平臺介紹 AgileEAS.NET之敏捷并行開發方法 敏捷軟件工程實驗室
轉載于:https://blog.51cto.com/agilelab/561910
總結
以上是生活随笔為你收集整理的AgileEAS.NET之ORM访问器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu 1568 Fibonacci 对
- 下一篇: BackTrack 5 发布了 ---直