提交 c867b9f4 编写于 作者: C Calvin

#57 将ehcache的hibernate 2nd Cache搬回Showcase

上级 8ec78d2d
......@@ -488,15 +488,11 @@
<!-- 避免引入过期的jar包 -->
<excludes>
<exclude>commons-logging</exclude>
<exclude>javassist:javassist</exclude>
<exclude>aspectj:aspectj*</exclude>
<exclude>org.springframework:2.*</exclude>
<exclude>org.springframework:3.0.*</exclude>
</excludes>
</bannedDependencies>
<requireJavaVersion>
<version>${jdk.version}</version>
</requireJavaVersion>
</rules>
<fail>true</fail>
</configuration>
......
......@@ -70,6 +70,10 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
<!-- mybatis -->
<dependency>
......
......@@ -5,6 +5,8 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
/**
* 角色.
......@@ -13,6 +15,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
*/
@Entity
@Table(name = "SS_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Role extends IdEntity {
private String name;
......
......@@ -8,6 +8,9 @@ import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.google.common.collect.Lists;
/**
......@@ -17,6 +20,7 @@ import com.google.common.collect.Lists;
*/
@Entity
@Table(name = "SS_TEAM")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Team extends IdEntity {
private String name;
......
......@@ -12,6 +12,8 @@ import javax.persistence.Table;
import javax.persistence.Transient;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.Email;
......@@ -28,6 +30,8 @@ import com.google.common.collect.Lists;
*/
@Entity
@Table(name = "SS_USER")
//默认的缓存策略.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends IdEntity {
private String loginName;
private String plainPassword;
......@@ -108,6 +112,7 @@ public class User extends IdEntity {
@Fetch(FetchMode.SUBSELECT)
//集合按id排序
@OrderBy("id ASC")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public List<Role> getRoleList() {
return roleList;
}
......
......@@ -26,6 +26,8 @@
<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="net.sf.ehcache.configurationResourceName">cache/ehcache-hibernate-local.xml</prop>
<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
</props>
</property>
......@@ -39,18 +41,18 @@
</property>
</bean>
<!-- Spring Data Jpa配置, 扫描base-package下所有继承于Repository<T,ID>的接口, 动态生成实现类 -->
<!-- Spring Data Jpa配置, 扫描base-package下所有继承于Repository<T,ID>的接口 -->
<jpa:repositories base-package="org.springside.examples.showcase" transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
<!-- MyBatis配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描目录, 省掉Configuration.xml里的手工配置Class名及其缩写 -->
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="typeAliasesPackage" value="org.springside.examples.showcase.entity" />
<!-- 没有把mapper文件放到与dao相同的深层目录,显式指定Mapper文件位置 -->
<!-- 显式指定Mapper文件位置 -->
<property name="mapperLocations" value="classpath:/mybatis/*Mapper.xml" />
</bean>
<!-- 扫描basePackage下所有接口, 动态生成MyBatis Dao接口实现 -->
<!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="org.springside.examples.showcase" />
<property name="annotationClass" value="org.springside.examples.showcase.repository.mybatis.MyBatisRepository"/>
......
<?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="false">
<diskStore path="java.io.tmpdir/hibernate/mini-web" />
<!-- DefaultCache setting. -->
<defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600"
overflowToDisk="true" maxEntriesLocalDisk="100000" />
<!-- Special objects setting. -->
<cache name="org.springside.examples.showcase.entity.User" maxEntriesLocalHeap="1000" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="10000" />
<cache name="org.springside.examples.showcase.entity.User.roleList" maxEntriesLocalHeap="1000" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="10000" />
<cache name="org.springside.examples.showcase.entity.Team" maxEntriesLocalHeap="100" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="1000" />
<cache name="org.springside.examples.showcase.entity.Role" maxEntriesLocalHeap="100"
eternal="true" overflowToDisk="true" maxEntriesLocalDisk="1000" />
</ehcache>
<?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="false">
<cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
properties="peerDiscovery=automatic,multicastGroupAddress=230.0.0.1,multicastGroupPort=4446" />
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" />
<diskStore path="java.io.tmpdir/hibernate/mini-web" />
<!-- DefaultCache setting. -->
<defaultCache maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600"
overflowToDisk="true" maxEntriesLocalDisk="100000" />
<!-- Special objects setting. -->
<cache name="org.springside.examples.showcase.entity.User" maxEntriesLocalHeap="1000" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="10000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicatePuts=false,replicateUpdatesViaCopy=false" />
</cache>
<cache name="org.springside.examples.showcase.entity.User.roleList" maxEntriesLocalHeap="1000" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="10000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicatePuts=false,replicateUpdatesViaCopy=false" />
</cache>
<cache name="org.springside.examples.showcase.entity.Team" maxEntriesLocalHeap="100" eternal="true"
overflowToDisk="true" maxEntriesLocalDisk="1000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicatePuts=false,replicateUpdatesViaCopy=false" />
</cache>
<cache name="org.springside.examples.showcase.entity.Role" maxEntriesLocalHeap="100"
eternal="true" overflowToDisk="true" maxEntriesLocalDisk="1000">
<cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
properties="replicatePuts=false,replicateUpdatesViaCopy=false" />
</cache>
</ehcache>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册