org.hibernate.Query.setLockOptions()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(256)

本文整理了Java中org.hibernate.Query.setLockOptions方法的一些代码示例,展示了Query.setLockOptions的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setLockOptions方法的具体详情如下:
包路径:org.hibernate.Query
类名称:Query
方法名:setLockOptions

Query.setLockOptions介绍

[英]Set the lock options for the query. Specifically only the following are taken into consideration:

  1. LockOptions#getLockMode()
  2. LockOptions#getScope()
  3. LockOptions#getTimeOut()
    For alias-specific locking, use #setLockMode(String,LockMode).
    [中]设置查询的锁定选项。具体而言,仅考虑以下因素:
    1.锁定选项#getLockMode()
    1.锁定选项#getScope()
    1.锁定选项#getTimeOut()
    对于特定于别名的锁定,请使用#setLockMode(字符串,LockMode)。

代码示例

代码示例来源:origin: com.github.cafdataprocessing/corepolicy-hibernate

@Override
public Query setLockOptions(LockOptions lockOptions) {
  return query.setLockOptions(lockOptions);
}

代码示例来源:origin: riotfamily/riot

public TypedQuery<T> setLockOptions(LockOptions lockOptions) {
  query.setLockOptions(lockOptions);
  return this;
}

代码示例来源:origin: ezbz/projectx

@Override
public Query setLockOptions(final LockOptions lockOptions) {
 return query.setLockOptions(lockOptions);
}

代码示例来源:origin: com.isotrol.impe3/impe3-pms-core

private <T extends PublishableEntity<T, ?, ?>> Iterable<T> getPFM(String queryName, Class<T> type) {
  final Query q = getNamedQuery(queryName).setLockOptions(LockOptions.UPGRADE);
  return list(type, q);
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Test
public void testPessimisticWrite() {
  LOGGER.info("Test lock contention");
  doInJPA(entityManager -> {
    List<Post> pendingPosts = entityManager.createQuery(
      "select p " +
      "from Post p " +
      "where p.status = :status",
      Post.class)
    .setParameter("status", PostStatus.PENDING)
    .setMaxResults(5)
    //.setLockMode(LockModeType.PESSIMISTIC_WRITE)
    .unwrap(org.hibernate.Query.class)
    .setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.SKIP_LOCKED))
    .list();
    assertEquals(5, pendingPosts.size());
  });
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Test
@Ignore
public void testUpgradeSkipLockedOrderByMaxResult() {
  LOGGER.info("Test lock contention");
  doInJPA(entityManager -> {
    List<Post> pendingPosts = entityManager.createQuery(
      "select p " +
      "from Post p " +
      "where p.status = :status " +
      "order by p.id ",
      Post.class)
    .setParameter("status", PostStatus.PENDING)
    .setMaxResults(5)
    .unwrap(org.hibernate.Query.class)
    .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
    .list();
    assertEquals(3, pendingPosts.size());
  });
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Test
public void testUpgradeSkipLocked() {
  LOGGER.info("Test lock contention");
  doInJPA(entityManager -> {
    List<Post> pendingPosts = entityManager.createQuery(
      "select p " +
      "from Post p " +
      "where p.status = :status",
      Post.class)
    .setParameter("status", PostStatus.PENDING)
    .setFirstResult(2)
    .unwrap(org.hibernate.Query.class)
    .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
    .list();
    assertEquals(3, pendingPosts.size());
  });
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Test
public void testUpgradeSkipLockedOrderBy() {
  LOGGER.info("Test lock contention");
  doInJPA(entityManager -> {
    List<Post> pendingPosts = entityManager.createQuery(
      "select p " +
      "from Post p " +
      "where p.status = :status " +
      "order by p.id ",
      Post.class)
    .setParameter("status", PostStatus.PENDING)
    .setFirstResult(2)
    .unwrap(org.hibernate.Query.class)
    .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
    .list();
    assertEquals(3, pendingPosts.size());
  });
}

相关文章