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

x33g5p2x  于2022-01-18 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(139)

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

Criteria.setLockMode介绍

[英]Set the lock mode of the aliased entity.
[中]设置别名实体的锁定模式。

代码示例

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

/**
 * Set the lock mode to use.
 *
 * @param lockMode The lock mode to use
 *
 * @return {@code this}, for method chaining
 */
public DetachedCriteria setLockMode(LockMode lockMode) {
  criteria.setLockMode( lockMode );
  return this;
}

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

/**
 * Set an alias-specific lock mode.  The specified lock mode applies only to that alias.
 *
 * @param alias The alias to apply the lock to
 * @param lockMode The lock mode to use.
 *
 * @return {@code this}, for method chaining
 */
public DetachedCriteria setLockMode(String alias, LockMode lockMode) {
  criteria.setLockMode( alias, lockMode );
  return this;
}

代码示例来源:origin: kaaproject/kaa

protected T findOneByCriterionWithLock(Criterion criterion, LockMode lockMode) {
 String className = getSimpleClassName();
 LOG.trace("Searching {} entity by criterion [{}] ", className, criterion);
 Criteria criteria = getCriteria();
 criteria.setLockMode(lockMode);
 criteria.add(criterion);
 return (T) criteria.uniqueResult();
}

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

@Test
public void testCriteria() {
  Session session = openSession();
  session.beginTransaction();
  Criteria criteria = session.createCriteria( Door.class );
  criteria.setLockMode( LockMode.PESSIMISTIC_WRITE );
  criteria.setFirstResult( 2 );
  criteria.setMaxResults( 2 );
  @SuppressWarnings("unchecked") List<Door> results = criteria.list();
  assertEquals( 2, results.size() );
  for ( Door door : results ) {
    assertEquals( LockMode.PESSIMISTIC_WRITE, session.getCurrentLockMode( door ) );
  }
  session.getTransaction().commit();
  session.close();
}

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

@Test
public void testLegacyCriteriaAliasSpecific() {
  // open a session, begin a transaction and lock row
  doInHibernate( this::sessionFactory, session -> {
    A it = (A) session.createCriteria( A.class )
        .setLockMode( "this", 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
public void testLegacyCriteria() {
  // open a session, begin a transaction and lock row
  doInHibernate( this::sessionFactory, session -> {
    A it = (A) session.createCriteria( A.class )
        .setLockMode( 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: org.hibernate/com.springsource.org.hibernate

public DetachedCriteria setLockMode(String alias, LockMode lockMode) {
    criteria.setLockMode(alias, lockMode);
    return this;
  }
}

代码示例来源:origin: TGAC/miso-lims

@Override
public Criteria setLockMode(LockMode lockMode) {
 backingCriteria.setLockMode(lockMode);
 return this;
}

代码示例来源:origin: TGAC/miso-lims

@Override
public Criteria setLockMode(String alias, LockMode lockMode) {
 backingCriteria.setLockMode(alias, lockMode);
 return this;
}

代码示例来源:origin: theonedev/onedev

public EntityCriteria<T> setLockMode(String alias, LockMode lockMode) {
    criteria.setLockMode(alias, lockMode);
    return this;
  }
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

public DetachedCriteria setLockMode(String alias, LockMode lockMode) {
    criteria.setLockMode(alias, lockMode);
    return this;
  }
}

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

@Override
public Criteria setLockMode(final LockMode lockMode) {
 return criteria.setLockMode(lockMode);
}

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

@Override
public Criteria setLockMode(final String alias, final LockMode lockMode) {
 return criteria.setLockMode(alias, lockMode);
}

代码示例来源:origin: theonedev/onedev

public EntityCriteria<T> setLockMode(LockMode lockMode) {
  criteria.setLockMode(lockMode);
  return this;
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate

public DetachedCriteria setLockMode(LockMode lockMode) {
  criteria.setLockMode(lockMode);
  return this;
}

代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.core

public DetachedCriteria setLockMode(LockMode lockMode) {
  criteria.setLockMode(lockMode);
  return this;
}

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

@Override
public Criteria setLockMode(final LockMode lockMode) {
  criteria.setLockMode(LockModeAdapter.adapt(lockMode));
  return this;
}

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

@Override
public Criteria setLockMode(final String alias, final LockMode lockMode) {
  criteria.setLockMode(alias, LockModeAdapter.adapt(lockMode));
  return this;
}

代码示例来源:origin: stackoverflow.com

// Load from DB

Criteria crit = session.createCriteria( Dummy.class ).add( Restrictions.eq("id", 5) );

crit.setLockMode( LockMode.UPGRADE  ); // issues a SELECT ... for UPDATE... 

Dummy val = crit.uniqueResult();

 etc.etc

代码示例来源:origin: org.grails/grails-datastore-gorm-hibernate-core

@Override
public Query lock(boolean lock) {
  criteria.setCacheable(false);
  criteria.setLockMode(LockMode.PESSIMISTIC_WRITE);
  return super.lock(lock);
}

相关文章