hibernate shards源自google的一個工程師小團隊的20%項目。它提供一個對資料庫水準分割的解決方案。
hibernate shards是對hibernate core進行了擴充,降低了複雜度。從概念上可以分成2部分。
1、基礎邏輯
該部分對
• org.hibernate.Session
• org.hibernate.SessionFactory
• org.hibernate.Criteria
• org.hibernate.Query
進行了擴充。
• org.hibernate.shards.session.ShardedSession
• org.hibernate.shards.ShardedSessionFactory
• org.hibernate.shards.criteria.ShardedCriteria
• org.hibernate.shards.query.ShardedQuery
你可以很友善的使用就像普通的hibernate應用。
2、應用邏輯部分
提供三個接口,用來處理具體的實作政策
• org.hibernate.shards.strategy.selection.ShardSelectionStrategy
• org.hibernate.shards.strategy.resolution.ShardResolutionStrategy
• org.hibernate.shards.strategy.access.ShardAccessStrategy
ShardAccessStrategy:
擷取資料的政策,目前已經包含的實作有:
SequentialShardAccessStrategy:順序政策
ParallelShardAccessStrategy:并發政策
如果你想隻取某一個庫,目前你隻能通過取具體的資料庫的 SessionFactory。目前在政策裡還不支援取其中的某個或某幾個庫,暫時是所有
資料庫都參與。
ShardSelectionStrategy:
當一個新資料儲存時,決定存儲到那個資料庫。
ShardResolutionStrategy:
當資料修改後,判斷同步到哪一個資料庫。 http://pppppp.iteye.com/blog/125315