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

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

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

Query.setLockMode介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

  1. protected void applyQuerySettingsAndHints(Query query) {
  2. if ( lockOptions.getLockMode() != LockMode.NONE ) {
  3. query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
  4. }
  5. Object queryTimeout;
  6. if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
  7. query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
  8. }
  9. Object lockTimeout;
  10. if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
  11. query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
  12. }
  13. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Override
  2. protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition namedQueryDefinition) {
  3. super.initQueryFromNamedDefinition( query, namedQueryDefinition );
  4. if ( namedQueryDefinition.getLockOptions() != null ) {
  5. if ( namedQueryDefinition.getLockOptions().getLockMode() != null ) {
  6. query.setLockMode(
  7. LockModeTypeHelper.getLockModeType( namedQueryDefinition.getLockOptions().getLockMode() )
  8. );
  9. }
  10. }
  11. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. @TestForIssue(jiraKey = "HHH-2735")
  3. public void testQueryLockModePessimisticWriteWithAlias() {
  4. doInHibernate( this::sessionFactory, session -> {
  5. // shouldn't throw an exception
  6. session.createQuery( "SELECT MAX(a.id)+1 FROM A a where a.value = :value" )
  7. .setLockMode( "a", LockMode.PESSIMISTIC_WRITE )
  8. .setParameter( "value", "it" )
  9. .list();
  10. } );
  11. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. @TestForIssue(jiraKey = "HHH-2735")
  3. public void testQueryLockModeNoneWithAlias() {
  4. doInHibernate( this::sessionFactory, session -> {
  5. // shouldn't throw an exception
  6. session.createQuery( "SELECT a.value FROM A a where a.id = :id" )
  7. .setLockMode( "a", LockMode.NONE )
  8. .setParameter( "id", id )
  9. .list();
  10. } );
  11. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. public void testQuery() {
  3. // open a session, begin a transaction and lock row
  4. doInHibernate( this::sessionFactory, session -> {
  5. A it = (A) session.createQuery( "from A a" )
  6. .setLockMode( "a", LockMode.PESSIMISTIC_WRITE )
  7. .uniqueResult();
  8. // make sure we got it
  9. assertNotNull( it );
  10. // that initial transaction is still active and so the lock should still be held.
  11. // Lets open another session/transaction and verify that we cannot update the row
  12. nowAttemptToUpdateRow();
  13. } );
  14. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. @BMRules(rules = {
  3. @BMRule(targetClass = "org.hibernate.dialect.Dialect",
  4. targetMethod = "useFollowOnLocking",
  5. action = "return true",
  6. name = "H2DialectUseFollowOnLocking")
  7. })
  8. public void testQuerySetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
  9. try (Session s = openSession();) {
  10. final Query query = s.createQuery( "from Item i join i.bids b where name = :name" );
  11. query.setParameter( "name", "ZZZZ" );
  12. query.setLockMode( "i", LockMode.NONE );
  13. query.setLockMode( "b", LockMode.NONE );
  14. query.list();
  15. assertFalse( "Log message was not triggered", triggerable.wasTriggered() );
  16. }
  17. }

代码示例来源:origin: hibernate/hibernate-orm

  1. protected void setQueryProperties(Query query) {
  2. if ( maxResults != null ) {
  3. query.setMaxResults( maxResults );
  4. }
  5. if ( firstResult != null ) {
  6. query.setFirstResult( firstResult );
  7. }
  8. if ( cacheable != null ) {
  9. query.setCacheable( cacheable );
  10. }
  11. if ( cacheRegion != null ) {
  12. query.setCacheRegion( cacheRegion );
  13. }
  14. if ( comment != null ) {
  15. query.setComment( comment );
  16. }
  17. if ( flushMode != null ) {
  18. query.setFlushMode( flushMode );
  19. }
  20. if ( cacheMode != null ) {
  21. query.setCacheMode( cacheMode );
  22. }
  23. if ( timeout != null ) {
  24. query.setTimeout( timeout );
  25. }
  26. if ( lockOptions != null && lockOptions.getLockMode() != LockMode.NONE ) {
  27. query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() );
  28. }
  29. }

代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter

  1. @Override
  2. public void setLockMode(final String alias, final LockMode lockMode) {
  3. if (queryV2ForCompare != null) {
  4. queryV2ForCompare.setLockMode(alias, lockMode);
  5. }
  6. query.setLockMode(alias, LockModeAdapter.adapt(lockMode));
  7. }

代码示例来源:origin: org.hibernate.orm/hibernate-core

  1. protected void applyQuerySettingsAndHints(Query query) {
  2. if ( lockOptions.getLockMode() != LockMode.NONE ) {
  3. query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
  4. }
  5. Object queryTimeout;
  6. if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
  7. query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
  8. }
  9. Object lockTimeout;
  10. if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
  11. query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
  12. }
  13. }

代码示例来源:origin: hibernate/hibernate-search

  1. .setLockMode( LockModeType.NONE )
  2. .setHibernateFlushMode( FlushMode.MANUAL )
  3. .setCacheMode( cacheMode )

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

  1. "where c.post.id = :id", PostComment.class)
  2. .setParameter("id", 1L)
  3. .setLockMode(LockModeType.PESSIMISTIC_WRITE)
  4. .getResultList();

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

  1. "where c.post.id = :id", PostComment.class)
  2. .setParameter("id", 1L)
  3. .setLockMode(LockModeType.PESSIMISTIC_WRITE)
  4. .getResultList();

代码示例来源:origin: org.hibernate.orm/hibernate-core

  1. query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() );

相关文章