当前位置: 首页 > news >正文

沈阳做网站哪家最便宜seo文章关键词怎么优化

沈阳做网站哪家最便宜,seo文章关键词怎么优化,徐州信息网查询中心,wordpress 4.8 中文版hibernate工厂模式显式乐观锁定 在上一篇文章中 #xff0c;我介绍了Java持久性锁定的基本概念。 隐式锁定机制可防止丢失更新 #xff0c;它适用于我们可以主动修改的实体。 尽管隐式乐观锁定是一种广泛使用的技术#xff0c;但很少有人了解显式乐观锁定模式的内部工作原理… hibernate工厂模式 显式乐观锁定 在上一篇文章中 我介绍了Java持久性锁定的基本概念。 隐式锁定机制可防止丢失更新 它适用于我们可以主动修改的实体。 尽管隐式乐观锁定是一种广泛使用的技术但很少有人了解显式乐观锁定模式的内部工作原理。 当锁定的实体始终由某些外部机制修改时显式乐观锁定可以防止数据完整性异常。 产品订购用例 假设我们有以下域模型 我们的用户爱丽丝想订购产品。 购买过程如下 爱丽丝加载产品实体 因为价格方便她决定订购产品 价格引擎批处理作业更改了产品价格考虑了货币更改税项更改和市场营销活动 爱丽丝发出订单而没有注意到价格变动 隐式锁定的缺点 首先我们将测试隐式锁定机制是否可以防止此类异常。 我们的测试用例如下所示 doInTransaction(new TransactionCallableVoid() {Overridepublic Void execute(Session session) {final Product product (Product) session.get(Product.class, 1L);try {executeAndWait(new CallableVoid() {Overridepublic Void call() throws Exception {return doInTransaction(new TransactionCallableVoid() {Overridepublic Void execute(Session _session) {Product _product (Product) _session.get(Product.class, 1L);assertNotSame(product, _product);_product.setPrice(BigDecimal.valueOf(14.49));return null;}});}});} catch (Exception e) {fail(e.getMessage());}OrderLine orderLine new OrderLine(product);session.persist(orderLine);return null;} }); 测试生成以下输出 #Alice selects a Product Query:{[select abstractlo0_.id as id1_1_0_, abstractlo0_.description as descript2_1_0_, abstractlo0_.price as price3_1_0_, abstractlo0_.version as version4_1_0_ from product abstractlo0_ where abstractlo0_.id?][1]} #The price engine selects the Product as well Query:{[select abstractlo0_.id as id1_1_0_, abstractlo0_.description as descript2_1_0_, abstractlo0_.price as price3_1_0_, abstractlo0_.version as version4_1_0_ from product abstractlo0_ where abstractlo0_.id?][1]} #The price engine changes the Product price Query:{[update product set description?, price?, version? where id? and version?][USB Flash Drive,14.49,1,1,0]} #The price engine transaction is committed DEBUG [pool-2-thread-1]: o.h.e.t.i.j.JdbcTransaction - committed JDBC Connection#Alice inserts an OrderLine without realizing the Product price change Query:{[insert into order_line (id, product_id, unitPrice, version) values (default, ?, ?, ?)][1,12.99,0]} #Alice transaction is committed unaware of the Product state change DEBUG [main]: o.h.e.t.i.j.JdbcTransaction - committed JDBC Connection 隐式的乐观锁定机制无法检测到外部更改除非实体也被当前的持久性上下文更改。 为了防止发出过时的Product状态订单我们需要在Product实体上应用显式锁。 明确锁定救援 Java Persistence LockModeType.OPTIMISTIC是此类情况的合适候选者因此我们将对其进行测试。 Hibernate带有LockModeConverter实用程序该实用程序能够将任何Java Persistence LockModeType映射到与其关联的Hibernate LockMode 。 为简单起见我们将使用特定于Hibernate的LockMode.OPTIMISTIC 该方法实际上与其Java持久性对应项相同。 根据Hibernate文档显式的OPTIMISTIC锁定模式将 假设交易不会对实体产生竞争。 实体版本将在交易结束时进行验证。 我将调整测试用例改为使用显式OPTIMISTIC锁定 try {doInTransaction(new TransactionCallableVoid() {Overridepublic Void execute(Session session) {final Product product (Product) session.get(Product.class, 1L, new LockOptions(LockMode.OPTIMISTIC));executeAndWait(new CallableVoid() {Overridepublic Void call() throws Exception {return doInTransaction(new TransactionCallableVoid() {Overridepublic Void execute(Session _session) {Product _product (Product) _session.get(Product.class, 1L);assertNotSame(product, _product);_product.setPrice(BigDecimal.valueOf(14.49));return null;}});}});OrderLine orderLine new OrderLine(product);session.persist(orderLine);return null;}});fail(It should have thrown OptimisticEntityLockException!); } catch (OptimisticEntityLockException expected) {LOGGER.info(Failure: , expected); } 新的测试版本生成以下输出 #Alice selects a Product Query:{[select abstractlo0_.id as id1_1_0_, abstractlo0_.description as descript2_1_0_, abstractlo0_.price as price3_1_0_, abstractlo0_.version as version4_1_0_ from product abstractlo0_ where abstractlo0_.id?][1]} #The price engine selects the Product as well Query:{[select abstractlo0_.id as id1_1_0_, abstractlo0_.description as descript2_1_0_, abstractlo0_.price as price3_1_0_, abstractlo0_.version as version4_1_0_ from product abstractlo0_ where abstractlo0_.id?][1]} #The price engine changes the Product price Query:{[update product set description?, price?, version? where id? and version?][USB Flash Drive,14.49,1,1,0]} #The price engine transaction is committed DEBUG [pool-1-thread-1]: o.h.e.t.i.j.JdbcTransaction - committed JDBC Connection#Alice inserts an OrderLine Query:{[insert into order_line (id, product_id, unitPrice, version) values (default, ?, ?, ?)][1,12.99,0]} #Alice transaction verifies the Product version Query:{[select version from product where id ?][1]} #Alice transaction is rolled back due to Product version mismatch INFO [main]: c.v.h.m.l.c.LockModeOptimisticTest - Failure: org.hibernate.OptimisticLockException: Newer version [1] of entity [[com.vladmihalcea.hibernate.masterclass.laboratory.concurrency. AbstractLockModeOptimisticTest$Product#1]] found in database 操作流程如下 在交易结束时检查产品版本。 任何版本不匹配都会触发异常和事务回滚。 比赛条件风险 不幸的是应用程序级别的版本检查和事务提交不是原子操作。 该检查发生在EntityVerifyVersionProcess中 在交易之前提交阶段 public class EntityVerifyVersionProcess implements BeforeTransactionCompletionProcess {private final Object object;private final EntityEntry entry;/*** Constructs an EntityVerifyVersionProcess** param object The entity instance* param entry The entitys referenced EntityEntry*/public EntityVerifyVersionProcess(Object object, EntityEntry entry) {this.object object;this.entry entry;}Overridepublic void doBeforeTransactionCompletion(SessionImplementor session) {final EntityPersister persister entry.getPersister();final Object latestVersion persister.getCurrentVersion( entry.getId(), session );if ( !entry.getVersion().equals( latestVersion ) ) {throw new OptimisticLockException(object,Newer version [ latestVersion ] of entity [ MessageHelper.infoString( entry.getEntityName(), entry.getId() ) ] found in database);}} } 调用AbstractTransactionImpl.commit方法将执行before-transaction-commit阶段然后提交实际事务 Override public void commit() throws HibernateException {if ( localStatus ! LocalStatus.ACTIVE ) {throw new TransactionException( Transaction not successfully started );}LOG.debug( committing );beforeTransactionCommit();try {doCommit();localStatus LocalStatus.COMMITTED;afterTransactionCompletion( Status.STATUS_COMMITTED );}catch (Exception e) {localStatus LocalStatus.FAILED_COMMIT;afterTransactionCompletion( Status.STATUS_UNKNOWN );throw new TransactionException( commit failed, e );}finally {invalidate();afterAfterCompletion();} } 在支票和实际交易提交之间其他交易在很短的时间内默默地提交产品价格变化。 结论 显式的OPTIMISTIC锁定策略为过时的状态异常提供了有限的保护。 此竞争条件是“检查时间”到“使用时间数据完整性异常”的典型情况。 在下一篇文章中我将解释如何使用explicit lock upgrade技术保存该示例。 代码可在GitHub上获得 。 翻译自: https://www.javacodegeeks.com/2015/01/hibernate-locking-patterns-how-does-optimistic-lock-mode-work.htmlhibernate工厂模式
http://www.zqtcl.cn/news/185183/

相关文章:

  • 网站建设好学么模版型网站是怎样的
  • 网站维护建设费应计入科目高端营销型网站制作
  • 推荐几个好的网站wordpress 加载数据库表格也卖弄
  • 承德网站开发找人做网站安全吗
  • 百度网站推广电话眼镜网站怎么做竞价
  • 邢台建设银行官方网站为什么建设网站很多公司没有
  • 闵行做网站费用湖南正规网络营销哪家便宜
  • 找个公司做网站需要注意什么wordpress用户名长度
  • 推荐几个没封的正能量网站营销技巧和营销方法视频
  • html mip 网站桂林市临桂区
  • 做网站如何月入10万建行app怎么注册登录
  • 建设一个旅游网站毕业设计建设网站的功能定位是什么原因
  • wordpress网站导航模板杭州建设网站的公司
  • 如何做视频解析网站wordpress 关闭评论
  • 安福网站建设微信开发者工具怎么下载
  • 网罗设计网站威海网页设计制作公司
  • 网站用cmswordpress插件怎么做
  • 如何办好公司网站元器件网站搭建
  • 建设领域行政处罚查询网站wordpress数据库发文章
  • 怎么做网页的多开器宿迁seo优化
  • 别人帮做的网站怎么修改病句店铺引流的30种方法
  • 网站备案幕布怎么申请绍兴cms建站模板
  • 做网站熊掌号软件设计公司排名
  • 深圳 做网站学做西点的网站
  • 静态网站安全性百度服务平台
  • 网站vi设计公司网站建设app
  • 书店网站建设策划书总结每天看七个广告赚40元的app
  • 做网站的属于什么专业成都广告制作安装公司
  • 天津市网站建设公司网站制作费用
  • 网站制作公司 郑州wordpress图片中文不显示解决