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

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

本文整理了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

  1. @Override
  2. public Query setLockOptions(LockOptions lockOptions) {
  3. return query.setLockOptions(lockOptions);
  4. }

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

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

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

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

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

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

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

  1. @Test
  2. public void testPessimisticWrite() {
  3. LOGGER.info("Test lock contention");
  4. doInJPA(entityManager -> {
  5. List<Post> pendingPosts = entityManager.createQuery(
  6. "select p " +
  7. "from Post p " +
  8. "where p.status = :status",
  9. Post.class)
  10. .setParameter("status", PostStatus.PENDING)
  11. .setMaxResults(5)
  12. //.setLockMode(LockModeType.PESSIMISTIC_WRITE)
  13. .unwrap(org.hibernate.Query.class)
  14. .setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.SKIP_LOCKED))
  15. .list();
  16. assertEquals(5, pendingPosts.size());
  17. });
  18. }

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

  1. @Test
  2. @Ignore
  3. public void testUpgradeSkipLockedOrderByMaxResult() {
  4. LOGGER.info("Test lock contention");
  5. doInJPA(entityManager -> {
  6. List<Post> pendingPosts = entityManager.createQuery(
  7. "select p " +
  8. "from Post p " +
  9. "where p.status = :status " +
  10. "order by p.id ",
  11. Post.class)
  12. .setParameter("status", PostStatus.PENDING)
  13. .setMaxResults(5)
  14. .unwrap(org.hibernate.Query.class)
  15. .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
  16. .list();
  17. assertEquals(3, pendingPosts.size());
  18. });
  19. }

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

  1. @Test
  2. public void testUpgradeSkipLocked() {
  3. LOGGER.info("Test lock contention");
  4. doInJPA(entityManager -> {
  5. List<Post> pendingPosts = entityManager.createQuery(
  6. "select p " +
  7. "from Post p " +
  8. "where p.status = :status",
  9. Post.class)
  10. .setParameter("status", PostStatus.PENDING)
  11. .setFirstResult(2)
  12. .unwrap(org.hibernate.Query.class)
  13. .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
  14. .list();
  15. assertEquals(3, pendingPosts.size());
  16. });
  17. }

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

  1. @Test
  2. public void testUpgradeSkipLockedOrderBy() {
  3. LOGGER.info("Test lock contention");
  4. doInJPA(entityManager -> {
  5. List<Post> pendingPosts = entityManager.createQuery(
  6. "select p " +
  7. "from Post p " +
  8. "where p.status = :status " +
  9. "order by p.id ",
  10. Post.class)
  11. .setParameter("status", PostStatus.PENDING)
  12. .setFirstResult(2)
  13. .unwrap(org.hibernate.Query.class)
  14. .setLockOptions(new LockOptions(LockMode.UPGRADE_SKIPLOCKED))
  15. .list();
  16. assertEquals(3, pendingPosts.size());
  17. });
  18. }

相关文章