程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> hibernate 3.3采用新的緩存方法

hibernate 3.3采用新的緩存方法

編輯:關於JAVA

今天查看hibernate cache接口時 svn了hibernate3.3的源碼

打開CacheProvider類一看 居然給 @deprecated

真是大塊人心

早就對hibernate的二級緩存和查詢緩存不爽

只能按照實體配置 不能針對某條查詢語句設置

3.3的提供了兩個接口 Region  RegionFactory 來代替 3.2中的Cache CacheProvider

看看RegionFactory 的實現吧

看看這幾個方法名字是多麼的讓人激動

Java代碼

buildCollectionRegion 對集合的緩存 猜測是對一對多的集合進行配置的吧
buildQueryResultsRegion 查詢緩存 自定義的查詢 也可以有自己的region了
buildTimestampsRegion  給緩存設置過期時間吧

英文不好 猜測的 英文好的可以翻譯一下

在gg上搜索了一下hibernate RegionFactory 關鍵字 居然沒搜索到

難道大家對個功能都不感冒

Java代碼

public interface RegionFactory {

  public void start(Settings settings, Properties properties) throws CacheException;

  public void stop();

  public boolean isMinimalPutsEnabledByDefault();

  public long nextTimestamp();

  public EntityRegion buildEntityRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException;

  public CollectionRegion buildCollectionRegion(String regionName, Properties properties, CacheDataDescription metadata) throws CacheException;

  public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties) throws CacheException;

  public TimestampsRegion buildTimestampsRegion(String regionName, Properties properties) throws CacheException;
}

附上hibernate3.3 cache包裡的說明

引用

This package defines APIs/SPIs and implementations for the Hibernate second-level cache.

The legacy (and now deprecated) approach to caching is defined by the {@link org.hibernate.cache.CacheProvider} and {@link org.hibernate.cache.Cache} interfaces as well as the {@link org.hibernate.cache.CacheConcurrencyStrategy} interface along with the various implementations of all these interfaces. In that scheme, a {@link org.hibernate.cache.CacheProvider} defined how to configure and perform lifecycle operations in regards to a particular underlying caching library; it also defined how to build {@link org.hibernate.cache.Cache} instances which in turn defined how to access the "regions" of the underlying cache instance. For entity and collection data cache regions, {@link org.hibernate.cache.CacheConcurrencyStrategy} wrapped access to those cache regions to apply transactional/concurrent access semantics.

The improved approach is based on {@link org.hibernate.cache.RegionFactory}, the various {@link org.hibernate.cache.Region} specializations and the two access strategies contracts ({@link org.hibernate.cache.access.EntityRegionAccessStrategy} and {@link org.hibernate.cache.access.CollectionRegionAccessStrategy}). The general approach here is that {@link org.hibernate.cache.RegionFactory} defined how to configure and perform lifecycle operations in regards to a particular underlying caching library (or libraries). {@link org.hibernate.cache.RegionFactory} also defines how to build specialized {@link org.hibernate.cache.Region} instances based on the type of data we will be storing in that given region. The fact that {@link org.hibernate.cache.RegionFactory} is asked to build specialized regions (as opposed to just general access) is the first improvement over the legacy scheme. The second improvement is the fact that the regions (well the ones like entity and collection regions that are responsible for storing {@link org.hibernate.cache.TransactionalDataRegion transactional} data) are asked to build their own access strategies (see {@link org.hibernate.cache.EntityRegion#buildAccessStrategy} and {@link org.hibernate.cache.CollectionRegion#buildAccessStrategy}).

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved