ehcache 程序

介绍

本文介绍如何在Openxava应用程序上快速启用Ehcache,从而提高性能。

查看实体及其图形时,将加载关系。 添加第二级缓存可加快关联元素的检索速度,因为已加载的元素是从缓存而不是数据库中检索的。

最终,该页面解释了分钟项目如何遵守诺言:不写任何内容。
例如,我们将以Lazuly分钟项目展示柜为例。

Openxava-Ehcache集成

在Openxava中,您可以使用Java注释的POJO来描述模型。注释来自标准的JPA2 ORM和特定于Openxava的注释。
但是没有什么可以阻止您添加其他人。 完成添加缓存的操作。 还有一些配置可以启用缓存。

行动清单

  1. 在源的根目录添加ehcache.xml配置文件
  2. 修改persistence.xml以包括二级缓存
  3. 添加缓存注释(与JPA2一起)

备注:

Openxava带有ehcache.jar,因此无需添加依赖项。

详细动作

添加ehcache.xml

在/ persistence处的ehcache.xml文件中

<ehcache><defaultCachemaxElementsInMemory="1000"eternal="false"timeToIdleSeconds="300"timeToLiveSeconds="300"overflowToDisk="false"diskPersistent="false"diskExpiryThreadIntervalSeconds="300"memoryStoreEvictionPolicy="LRU"/><cachename="your.domain.object"maxElementsInMemory="5000"eternal="false"timeToIdleSeconds="300"timeToLiveSeconds="600"overflowToDisk="false"/>
</ehcache>

修改persistence.xml

Persistence.xml文件包含与永久单元有关的信息,例如连接池信息,
类或配置加载。 'persistence.xml'位于/ persistence / META-INF中

我们将附加L2缓存的属性。

<properties><property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/><property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" /><property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml" /><property name="hibernate.cache.use_query_cache" value="true" /><property name="hibernate.cache.use_second_level_cache" value="true" /><property name="hibernate.generate_statistics" value="true" />   </properties>

添加缓存注释

此处使用的是Hibernate注释,而不是标准注释(实际上,可缓存似乎不起作用)
将缓存注释放置在域对象的类级别。

@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)

懒惰的应用

Lazuly是一个示例数据库,其中包含用于MinuteProject展示目的的会议信息。
Minuteproject生成了一套完整的人工制品,以加快OX应用程序的发布。
可以在Minuteproject 4 Openxava Lazuly展示柜中找到更多信息。 在这一部分,我们重点介绍针对特定缓存生成的伪像。 用于生成的Minuteproject本身基于配置文件,我们在其中定义数据模型以进行反向工程。 在此配置中,有一个扩充部分,您可以在其中添加信息。 处理实体类型中包含的内容类型的信息之一。 有4种可能性(参考数据,主数据,伪静态数据,实时业务数据) 如果使用content-type =“ master-data”或“ reference-data”丰富您的实体,MinuteProject 4 Openxava将生成关联的缓存。

这是针对国家实体在这里完成的。

<entity name="COUNTRY" content-type="reference-data">

这是与缓存有关的伪像

ehcache.xml

<ehcache><!--Sets the path to the directory where cache files are created.If the path is a Java System Property it is replaced by its value in therunning VM.The following properties are translated:* user.home - User's home directory* user.dir - User's current working directory* java.io.tmpdir - Default temp file pathSubdirectories can be specified below the property e.g. java.io.tmpdir/one-->
<!--MP-MANAGED-UPDATABLE-BEGINNING-DISABLE @ehcache-main-config-conference@--><diskStore path="java.io.tmpdir"/><!--Mandatory Default Cache configuration. These settings will be applied to cachescreated programmtically using CacheManager.add(String cacheName)--><defaultCachemaxElementsInMemory="1000"eternal="false"timeToIdleSeconds="300"timeToLiveSeconds="300"overflowToDisk="false"diskPersistent="false"diskExpiryThreadIntervalSeconds="300"memoryStoreEvictionPolicy="LRU"/>
<!-- The unnamed query cache --><cachename="org.hibernate.cache.StandardQueryCache"maxElementsInMemory="1000"eternal="false"timeToLiveSeconds="300"overflowToDisk="false"/>
<!--MP-MANAGED-UPDATABLE-ENDING--><!--MP-MANAGED-UPDATABLE-BEGINNING-DISABLE @cache-entity-country-conference@--><cachename="net.sf.mp.demo.conference.domain.admin.Country"maxElementsInMemory="5000"eternal="false"timeToIdleSeconds="300"timeToLiveSeconds="600"overflowToDisk="false"/>
<!--MP-MANAGED-UPDATABLE-ENDING--><!--MP-MANAGED-ADDED-AREA-BEGINNING @custom-cache-definition@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @custom-cache-definition@--></ehcache>

Persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"version="1.0"><!-- Tomcat + Hypersonic --><persistence-unit name="default"><non-jta-data-source>java:comp/env/jdbc/conferenceDS</non-jta-data-source><class>org.openxava.session.GalleryImage</class><properties><property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/><property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.SingletonEhCacheProvider" /><property name="net.sf.ehcache.configurationResourceName" value="/ehcache.xml" /><property name="hibernate.cache.use_query_cache" value="true" /><property name="hibernate.cache.use_second_level_cache" value="true" /><property name="hibernate.generate_statistics" value="true" />
<!--MP-MANAGED-ADDED-AREA-BEGINNING @properties@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @properties@--></properties>
<!--MP-MANAGED-ADDED-AREA-BEGINNING @persistence-unit@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @persistence-unit@--></persistence-unit>       <!--MP-MANAGED-ADDED-AREA-BEGINNING @persistence@-->
<!--MP-MANAGED-ADDED-AREA-ENDING @persistence@--></persistence>

类注解

@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
//MP-MANAGED-ADDED-AREA-BEGINNING @class-annotation@
//MP-MANAGED-ADDED-AREA-ENDING @class-annotation@
public class Country {@Hidden @Id @Column(name="id" )@GeneratedValue(strategy = GenerationType.AUTO)private Integer id;
...

生成的代码备注

生成的代码在文件扩展名注释中包含标记。

在MP-MANAGED-ADDED-AREA-BEGINNING和MP-MANAGED-ADDED-AREA-ENDING中,您可以放置​​自定义代码
在MP-MANAGED-UPDATABLE-BEGINNING-DISABLE和MP-MANAGED-UPDATABLE-ENDING中,您可以更改代码。 为了保留您的修改,请将MP-MANAGED-UPDATABLE-BEGINNING-DISABLE更改为MP-MANAGED-UPDATABLE-BEGINNING-ENABLE。
可更新的代码可防止您连续几代丢失定制。

有关可更新代码的更多信息,请参见Minuteproject可更新代码 。

  • 将以下文件mp-config-LAZULY-OPENXAVA.xml放在/ mywork / config中
  • 在提示符下执行mp-model-generation(.sh / cmd)mp-config-LAZULY-OPENXAVA.xml
  • / DEV / output / openxava / conference中产生的人工制品

要生成,请使用mp-config-LAZULY-OPENXAVA.xml的更新版本

<!DOCTYPE root>
<generator-config><configuration><conventions><target-convention type="enable-updatable-code-feature" /></conventions>  <model name="conference" version="1.0" package-root="net.sf.mp.demo"><data-model><driver name="mysql" version="5.1.16" groupId="mysql" artifactId="mysql-connector-java"></driver><dataSource><driverClassName>org.gjt.mm.mysql.Driver</driverClassName><url>jdbc:mysql://127.0.0.1:3306/conference</url><username>root</username><password>mysql</password></dataSource><!--for Oracle and DB2 please set the schema <schema> </schema>--><primaryKeyPolicy oneGlobal="true"><primaryKeyPolicyPattern name="autoincrementPattern"></primaryKeyPolicyPattern></primaryKeyPolicy></data-model><business-model><!--<generation-condition> <condition type="exclude"startsWith="DUAL"></condition> </generation-condition>--><business-package default="conference"><condition type="package" startsWith="STAT" result="statistics"></condition><condition type="package" startsWith="COUNTRY" result="admin"></condition><condition type="package" startsWith="ROLE" result="admin"></condition>    </business-package><enrichment><conventions><column-naming-convention type="apply-strip-column-name-suffix"pattern-to-strip="_ID" /><reference-naming-conventiontype="apply-referenced-alias-when-no-ambiguity" is-to-plurialize="true" /></conventions><entity name="COUNTRY" content-type="reference-data"><semantic-reference><sql-path path="NAME" /></semantic-reference></entity><entity name="CONFERENCE_MEMBER"><semantic-reference><sql-path path="FIRST_NAME" /><sql-path path="LAST_NAME" /></semantic-reference><field name="STATUS"><property tag="checkconstraint" alias="conference_member_status"><property name="PENDING" value="PENDING" /><property name="ACTIVE" value="ACTIVE" /></property></field><field name="EMAIL"><stereotype stereotype="EMAIL" /></field></entity><entity name="SPEAKER"><field name="BIO"><stereotype stereotype="HTML_TEXT" /></field><field name="PHOTO"><stereotype stereotype="PHOTO" /></field><field name="WEB_SITE_URL"><stereotype stereotype="WEBURL" /></field></entity><entity name="PRESENTATION"><field name="STATUS"><property tag="checkconstraint" alias="presentation_status"><property name="PROPOSAL" value="PROPOSAL" /><property name="ACTIVE" value="ACTIVE" /></property></field></entity><entity name="SPONSOR"><field name="STATUS"><property tag="checkconstraint" alias="sponsor_status"><property name="PENDING" value="PENDING" /><property name="ACTIVE" value="ACTIVE" /></property></field><field name="PRIVILEGE_TYPE"><property tag="checkconstraint" alias="sponsor_privilege"><property name="GOLDEN" value="Golden" /><property name="SILVER" value="Silver" /><property name="BRONZE" value="Bronze" /></property></field></entity><!-- views --><entity name="stat_mb_per_ctry_conf" alias="MEMBER_PER_COUNTRY_AND_CONFERENCE"><virtual-primary-key isRealPrimaryKey="true"><property name="virtualPrimaryKey" value="ID" /></virtual-primary-key></entity><entity name="stat_mb_by_role" alias="MEMBER_PER_ROLE_COUNTRY_AND_CONFERENCE"><virtual-primary-key isRealPrimaryKey="true"><property name="virtualPrimaryKey" value="id" /></virtual-primary-key><field name="stat_mb_per_ctry_conf_ID" linkToTargetEntity="stat_mb_per_ctry_conf"linkToTargetField="id"></field></entity></enrichment></business-model></model><targets><!-- openxava --><target refname="OpenXava" name="OpenXava"fileName="mp-template-config-openxava-last-features.xml"outputdir-root="../../DEV/output/openxava/conference"templatedir-root="../../template/framework/openxava"></target><target refname="JPA2-LIB" fileName="mp-template-config-JPA2-LIB.xml"templatedir-root="../../template/framework/jpa"></target><target refname="BSLA-LIB" fileName="mp-template-config-bsla-LIB-features.xml"templatedir-root="../../template/framework/bsla"></target><target refname="CACHE-LIB" fileName="mp-template-config-CACHE-LIB.xml" templatedir-root="../../template/framework/cache"></target></targets></configuration>
</generator-config>

测试
为确保缓存正常工作:

  • 启用Hibernate日志记录。 将以下代码段添加为persistence.xml中的其他属性。
<property name="hibernate.show_sql" value="true" /><property name="hibernate.format_sql" value="true" />
  • 导航到引用国家/地区的实体(例如地址)
  • 当您查看此实体的详细信息时,您会注意到相关实体“国家”的负载很大
  • 但是,第二次访问该实体(或引用同一国家/地区实例的另一个实体)的详细信息时,该国家/地区不会从数据库中加载两次。

参考:我们的JCG合作伙伴 将Ehcache添加到Openxava应用程序中   分钟项目博客上的 Florian Adler。

翻译自: https://www.javacodegeeks.com/2012/03/adding-ehcache-to-openxava-application.html

ehcache 程序

ehcache 程序_将Ehcache添加到Openxava应用程序相关推荐

  1. 将Ehcache添加到Openxava应用程序

    介绍 本文介绍如何在Openxava应用程序上快速启用Ehcache,从而提高性能. 查看实体及其图时,将加载关系. 添加第二级缓存可加快关联元素的检索速度,因为已加载的元素是从缓存而不是数据库中检索 ...

  2. ehcache 冲突_解决Ehcache缓存警告问题

    警告: Creating a new instance of CacheManager using the diskStorePath "D:\Apache Tomcat 6.0.18\te ...

  3. 谷歌地图api 微信小程序_使用Google的融合位置提供程序API进行实时位置跟踪

    谷歌地图api 微信小程序 Location tracking and monitoring have seen a surge in modern application development w ...

  4. php开发桌面应用程序_使用PHP开发跨平台桌面应用程序的3种方法

    php开发桌面应用程序 PHP as a cross-platform desktop app development language? Blasphemy! Nonetheless, it's p ...

  5. mpvue 微信小程序_使用Vue.js开发微信小程序:开源框架mpvue解析

    戳蓝字"CSDN云计算"关注我们哦! 作者 | 成全 责编 | 阿秃 转自 | 美团技术团队企业博客 前言 mpvue是一款使用Vue.js开发微信小程序的前端框架.使用此框架,开 ...

  6. hp designiet 500绘图仪程序_邹军:通过数控宏程序实现刀具寿命管理

    点击上方,关注我哈 (文章底部可以评论,欢迎对文章进行点评和知识补充) 数控编程教学 订单 | 技术 | 干货 | 编程 关注可加入机械行业群 [邹军,十多年数控工作经验,现自创一套有理论,有干货,还 ...

  7. 贵州农信凭证打印小程序_我的医保凭证小程序入口

     阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都会有分享,都是免费订阅,请您放心关注.            ...

  8. 新版微信不停跳转到小程序_如何设置跳转微信小程序

    一.功能效果 手机网站常用模块:文本.图片.按钮支持设置点击跳转微信小程序. 可实现手机微信端下,打开手机网站可与微信小程序的实现相互跳转. 二.注意事项 [版本]展示中级版及以上版本支持开通. [条 ...

  9. java 加法程序_使用JAVAEE编写简单的加法程序

    软件152  罗俊 首先选择菜单file-new-maven project,勾选"Create a &simple project (skip archetype selectio ...

最新文章

  1. 离线部署 CDH 5.12.1 及使用 CDH 部署 Hadoop 大数据平台集群服务
  2. JAVA 中 string 和 int 互相转化
  3. 重塑HPE:6笔收购推动销售增长
  4. cnpm与npm指定有什么区别?
  5. OpenGL ES之GLSL实现索引绘制及渲染纹理和颜色混合
  6. JAVA班级年龄平均值代码_java用list集合存储学生信息并算出成绩平均值操作
  7. Kickfire Enters into MySQL Enterprise Agreement with Sun
  8. Remainders Game (中国剩余定理)
  9. 鸿蒙-HI3516-Docker环境搭建编译烧录
  10. Golang map 三板斧第二式:注意事项
  11. Python 中的注意点_s2
  12. Qt5学习笔记之QQ登录界面三:添加图片资源
  13. 请远离这些精神毒品!!
  14. 获取2个集合ListT的共同元素
  15. hough变换检测圆周_Hough变换检测圆(附:MATLAB程序)
  16. SlideLive:提供阶梯类型PPT模板下载
  17. javascript_this的理解
  18. 关于adsl上网的问题
  19. java-net-php-python-java校园约球网站计算机毕业设计程序
  20. 什么样的电子签名有法律效力

热门文章

  1. 使用相对长度单位em布局网页内容
  2. 端午前夕的班级小游戏
  3. java中判断 101-200 之间有多少个素数,并输出所有的素数
  4. python binascii array('c')_详解Python中的array数组模块相关使用
  5. java正则表达式验证密码_最新密码验证正则表达式
  6. Spring websocket 使用@Autowired 出现null
  7. run spark pi_Spark Run本地设计模式
  8. kite 使用 go_使用Apache Storm和Kite SDK Morphlines的可配置ETL处理
  9. 枚举对象注释_如何以及何时使用枚举和注释
  10. jboss fuse 教程_IDC关于使用JBoss Fuse的商业价值的报告(与Apache Camel一起使用)