本文整理了Java中org.hibernate.query.Query.setLockMode
方法的一些代码示例,展示了Query.setLockMode
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setLockMode
方法的具体详情如下:
包路径:org.hibernate.query.Query
类名称:Query
方法名:setLockMode
暂无
代码示例来源:origin: hibernate/hibernate-orm
protected void applyQuerySettingsAndHints(Query query) {
if ( lockOptions.getLockMode() != LockMode.NONE ) {
query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
}
Object queryTimeout;
if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
}
Object lockTimeout;
if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected void initQueryFromNamedDefinition(Query query, NamedQueryDefinition namedQueryDefinition) {
super.initQueryFromNamedDefinition( query, namedQueryDefinition );
if ( namedQueryDefinition.getLockOptions() != null ) {
if ( namedQueryDefinition.getLockOptions().getLockMode() != null ) {
query.setLockMode(
LockModeTypeHelper.getLockModeType( namedQueryDefinition.getLockOptions().getLockMode() )
);
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-2735")
public void testQueryLockModePessimisticWriteWithAlias() {
doInHibernate( this::sessionFactory, session -> {
// shouldn't throw an exception
session.createQuery( "SELECT MAX(a.id)+1 FROM A a where a.value = :value" )
.setLockMode( "a", LockMode.PESSIMISTIC_WRITE )
.setParameter( "value", "it" )
.list();
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue(jiraKey = "HHH-2735")
public void testQueryLockModeNoneWithAlias() {
doInHibernate( this::sessionFactory, session -> {
// shouldn't throw an exception
session.createQuery( "SELECT a.value FROM A a where a.id = :id" )
.setLockMode( "a", LockMode.NONE )
.setParameter( "id", id )
.list();
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testQuery() {
// open a session, begin a transaction and lock row
doInHibernate( this::sessionFactory, session -> {
A it = (A) session.createQuery( "from A a" )
.setLockMode( "a", LockMode.PESSIMISTIC_WRITE )
.uniqueResult();
// make sure we got it
assertNotNull( it );
// that initial transaction is still active and so the lock should still be held.
// Lets open another session/transaction and verify that we cannot update the row
nowAttemptToUpdateRow();
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@BMRules(rules = {
@BMRule(targetClass = "org.hibernate.dialect.Dialect",
targetMethod = "useFollowOnLocking",
action = "return true",
name = "H2DialectUseFollowOnLocking")
})
public void testQuerySetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
try (Session s = openSession();) {
final Query query = s.createQuery( "from Item i join i.bids b where name = :name" );
query.setParameter( "name", "ZZZZ" );
query.setLockMode( "i", LockMode.NONE );
query.setLockMode( "b", LockMode.NONE );
query.list();
assertFalse( "Log message was not triggered", triggerable.wasTriggered() );
}
}
代码示例来源:origin: hibernate/hibernate-orm
protected void setQueryProperties(Query query) {
if ( maxResults != null ) {
query.setMaxResults( maxResults );
}
if ( firstResult != null ) {
query.setFirstResult( firstResult );
}
if ( cacheable != null ) {
query.setCacheable( cacheable );
}
if ( cacheRegion != null ) {
query.setCacheRegion( cacheRegion );
}
if ( comment != null ) {
query.setComment( comment );
}
if ( flushMode != null ) {
query.setFlushMode( flushMode );
}
if ( cacheMode != null ) {
query.setCacheMode( cacheMode );
}
if ( timeout != null ) {
query.setTimeout( timeout );
}
if ( lockOptions != null && lockOptions.getLockMode() != LockMode.NONE ) {
query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() );
}
}
代码示例来源:origin: com.atlassian.hibernate/hibernate.adapter
@Override
public void setLockMode(final String alias, final LockMode lockMode) {
if (queryV2ForCompare != null) {
queryV2ForCompare.setLockMode(alias, lockMode);
}
query.setLockMode(alias, LockModeAdapter.adapt(lockMode));
}
代码示例来源:origin: org.hibernate.orm/hibernate-core
protected void applyQuerySettingsAndHints(Query query) {
if ( lockOptions.getLockMode() != LockMode.NONE ) {
query.setLockMode( getLockMode( lockOptions.getLockMode() ) );
}
Object queryTimeout;
if ( (queryTimeout = getProperties().get( QueryHints.SPEC_HINT_TIMEOUT ) ) != null ) {
query.setHint( QueryHints.SPEC_HINT_TIMEOUT, queryTimeout );
}
Object lockTimeout;
if( (lockTimeout = getProperties().get( JPA_LOCK_TIMEOUT ))!=null){
query.setHint( JPA_LOCK_TIMEOUT, lockTimeout );
}
}
代码示例来源:origin: hibernate/hibernate-search
.setLockMode( LockModeType.NONE )
.setHibernateFlushMode( FlushMode.MANUAL )
.setCacheMode( cacheMode )
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
"where c.post.id = :id", PostComment.class)
.setParameter("id", 1L)
.setLockMode(LockModeType.PESSIMISTIC_WRITE)
.getResultList();
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
"where c.post.id = :id", PostComment.class)
.setParameter("id", 1L)
.setLockMode(LockModeType.PESSIMISTIC_WRITE)
.getResultList();
代码示例来源:origin: org.hibernate.orm/hibernate-core
query.setLockMode( REFERENCED_ENTITY_ALIAS, lockOptions.getLockMode() );
内容来源于网络,如有侵权,请联系作者删除!