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

手机网站怎么做单页面电影的网络营销方式

手机网站怎么做单页面,电影的网络营销方式,嵊州市网站建设,个人网站建设推广策划书介绍 在我以前的文章中 #xff0c;我解释了批处理INSERT和UPDATE语句所需的Hibernate配置。 这篇文章将继续本主题的DELETE语句批处理。 领域模型实体 我们将从以下实体模型开始#xff1a; Post实体与Comment具有一对多关联#xff0c;并且与PostDetails实体具有一对一… 介绍 在我以前的文章中 我解释了批处理INSERT和UPDATE语句所需的Hibernate配置。 这篇文章将继续本主题的DELETE语句批处理。 领域模型实体 我们将从以下实体模型开始 Post实体与Comment具有一对多关联并且与PostDetails实体具有一对一关系 OneToMany(cascade CascadeType.ALL, mappedBy post,orphanRemoval true) private ListComment comments new ArrayList();OneToOne(cascade CascadeType.ALL, mappedBy post,orphanRemoval true, fetch FetchType.LAZY) private PostDetails details; 即将进行的测试将针对以下数据进行 doInTransaction(session - {int batchSize batchSize();for(int i 0; i itemsCount(); i) {int j 0;Post post new Post(String.format(Post no. %d, i)); post.addComment(new Comment( String.format(Post comment %d:%d, i, j)));post.addComment(new Comment(String.format(Post comment %d:%d, i, j)));post.addDetails(new PostDetails());session.persist(post);if(i % batchSize 0 i 0) {session.flush();session.clear();}} });休眠配置 正如已经说明 以下属性所需的配料INSERT和UPDATE语句 properties.put(hibernate.jdbc.batch_size, String.valueOf(batchSize())); properties.put(hibernate.order_inserts, true); properties.put(hibernate.order_updates, true); properties.put(hibernate.jdbc.batch_versioned_data, true); 接下来我们将检查DELETE语句是否也被批处理。 JPA级联删除 因为级联实体状态转换很方便所以我将证明CascadeType.DELETE和JDBC批处理不能很好地混合使用。 以下测试将要进行 选择一些帖子以及评论和帖子 详细信息 删除帖子 同时将delete事件传播到Comments和PostDetails Test public void testCascadeDelete() {LOGGER.info(Test batch delete with cascade);final AtomicReferenceLong startNanos new AtomicReference();addDeleteBatchingRows();doInTransaction(session - {ListPost posts session.createQuery(select distinct p from Post p join fetch p.details d join fetch p.comments c).list();startNanos.set(System.nanoTime());for (Post post : posts) {session.delete(post);}});LOGGER.info({}.testCascadeDelete took {} millis,getClass().getSimpleName(),TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos.get())); } 运行此测试将给出以下输出 Query:{[delete from Comment where id? and version?][55,0]} {[delete from Comment where id? and version?][56,0]} Query:{[delete from PostDetails where id?][3]} Query:{[delete from Post where id? and version?][3,0]} Query:{[delete from Comment where id? and version?][54,0]} {[delete from Comment where id? and version?][53,0]} Query:{[delete from PostDetails where id?][2]} Query:{[delete from Post where id? and version?][2,0]} Query:{[delete from Comment where id? and version?][52,0]} {[delete from Comment where id? and version?][51,0]} Query:{[delete from PostDetails where id?][1]} Query:{[delete from Post where id? and version?][1,0]} 仅批注Comment DELETE语句其他实体在单独的数据库往返中删除。 此行为的原因由ActionQueue排序实现给出 if ( session.getFactory().getSettings().isOrderUpdatesEnabled() ) {// sort the updates by pkupdates.sort(); } if ( session.getFactory().getSettings().isOrderInsertsEnabled() ) {insertions.sort(); } 虽然介绍了INSERTS和UPDATES 但根本不对DELETE语句进行排序。 仅当所有语句都属于同一数据库表时才能重新使用JDBC批处理。 当传入语句针对另一个数据库表时必须释放当前批处理以便新批处理与当前语句数据库表匹配 public Batch getBatch(BatchKey key) {if ( currentBatch ! null ) {if ( currentBatch.getKey().equals( key ) ) {return currentBatch;}else {currentBatch.execute();currentBatch.release();}}currentBatch batchBuilder().buildBatch(key, this);return currentBatch; }移除孤儿和手动冲洗 一种变通方法是在前进到新的Child关联之前先手动刷新Hibernate Session然后解除所有Child实体的关联 Test public void testOrphanRemoval() {LOGGER.info(Test batch delete with orphan removal);final AtomicReferenceLong startNanos new AtomicReference();addDeleteBatchingRows();doInTransaction(session - {ListPost posts session.createQuery(select distinct p from Post p join fetch p.details d join fetch p.comments c).list();startNanos.set(System.nanoTime());posts.forEach(Post::removeDetails);session.flush();posts.forEach(post - {for (IteratorComment commentIterator post.getComments().iterator(); commentIterator.hasNext(); ) {Comment comment commentIterator.next();comment.post null;commentIterator.remove();}});session.flush();posts.forEach(session::delete);});LOGGER.info({}.testOrphanRemoval took {} millis,getClass().getSimpleName(),TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos.get())); } 这次所有DELETE语句均已正确批处理 Query:{[delete from PostDetails where id?][2]} {[delete from PostDetails where id?][3]} {[delete from PostDetails where id?][1]} Query:{[delete from Comment where id? and version?][53,0]} {[delete from Comment where id? and version?][54,0]} {[delete from Comment where id? and version?][56,0]} {[delete from Comment where id? and version?][55,0]} {[delete from Comment where id? and version?][52,0]} {[delete from Comment where id? and version?][51, Query:{[delete from Post where id? and version?][2,0]} {[delete from Post where id? and version?][3,0]} {[delete from Post where id? and version?][1,0]}SQL级联删除 更好的解决方案是使用SQL级联删除而不是JPA实体状态传播机制。 这样我们还可以减少DML语句的数量。 由于Hibernate Session充当事务后写式缓存 因此在将实体状态转换与数据库端自动操作混合使用时我们必须格外谨慎因为持久性上下文可能无法反映最新的数据库更改。 Post实体一对多 注释关联使用Hibernate特定的OnDelete批注进行标记以便自动生成的数据库模式包括ON DELETE CASCADE指令 OneToMany(cascade {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy post) OnDelete(action OnDeleteAction.CASCADE) private ListComment comments new ArrayList(); 生成以下DDL alter table Comment add constraint FK_apirq8ka64iidc18f3k6x5tc5 foreign key (post_id) references Post on delete cascade 使用PostDetails实体一对一的Post关联也可以做到这一点 OneToOne(fetch FetchType.LAZY) JoinColumn(name id) MapsId OnDelete(action OnDeleteAction.CASCADE) private Post post; 以及相关的DDL alter table PostDetails add constraint FK_h14un5v94coafqonc6medfpv8 foreign key (id) references Post on delete cascade CascadeType.ALL和orphanRemoval替换为CascadeType.PERSIST和CascadeType.MERGE 因为我们不再希望Hibernate传播实体删除事件。 测试仅删除Post实体。 doInTransaction(session - {ListPost posts session.createQuery(select p from Post p).list();startNanos.set(System.nanoTime());for (Post post : posts) {session.delete(post);} }); 由于只有一个目标表因此DELETE语句已正确批处理。 Query:{[delete from Post where id? and version?][1,0]} {[delete from Post where id? and version?][2,0]} {[delete from Post where id? and version?][3,0]}结论 如果INSERT和UPDATE语句的批处理只是配置问题则DELETE语句需要一些其他步骤这可能会增加数据访问层的复杂性。 代码可在GitHub上获得 。 翻译自: https://www.javacodegeeks.com/2015/03/how-to-batch-delete-statements-with-hibernate.html
http://www.pierceye.com/news/773728/

相关文章:

  • 4s店网站建设贺贵江seo教程
  • 做网站的公司一般怎么培训销售wordpress引用php
  • 自己怎样做网站平台网页设计做网站首页
  • 费县做网站点石家装
  • 科技网站制作案例图片制作在线网页
  • 怀柔成都网站建设网络推广图片
  • 网站建设微信运营公司中国室内设计公司
  • app推广平台网站建设银行东营分行网站
  • 校园二手交易网站设计的原则群辉搭wordpress
  • 无锡网站建设网页制作seo网站优化培训要多少钱
  • 一个人可以做几个网站seo页面检测
  • 在哪里可以找到做网站的公司wordpress下拉
  • 企业网站更新什么内容网站设计怎么保持风格一致
  • 网页设计作业网站素材和效果图网站开发和网络安全
  • 开发一个彩票网站多少钱怎么为一个网站做外链
  • 一家专门做动漫的网站怎么查企业注册信息
  • 中太建设集团官方网站微信网页链接怎么制作
  • 做家政网上推广网站长沙网站建设有哪些
  • 西安网站建设 招聘西安是哪个省属于哪个市
  • 灯饰网站开发中国十大门窗品牌
  • 移动网站开发认证基层建设被哪些网站全文收录
  • 中国电子商务网站小吃网站建设
  • 用什么语言能写网站吗装修公司招聘网站
  • 触摸网站手机软件开发公司赚钱吗
  • 刘家窑网站建设公司网店装修模板
  • 旅游网站国内外研究现状微信模板素材
  • 查一下红之易道学做的什么网站全国大型网站建设
  • 网站页面可以用什么框架做wordpress 自动 图片大小
  • 百度小程序可以根据网站的要求做吗网站建设评分细则
  • 团购模板网站廉洁长沙网站