use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class PostgreSQLLockTimeoutTest method testLockTimeoutNoAliasSkipLocked.
@Test
public void testLockTimeoutNoAliasSkipLocked() {
assertEquals(" for share skip locked", dialect.getForUpdateString(new LockOptions(LockMode.PESSIMISTIC_READ).setTimeOut(LockOptions.SKIP_LOCKED)));
assertEquals(" for update skip locked", dialect.getForUpdateString(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.SKIP_LOCKED)));
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class PostgreSQLLockTimeoutTest method testLockTimeoutAliasNoTimeout.
@Test
public void testLockTimeoutAliasNoTimeout() {
String alias = "a";
assertEquals(" for share of a", dialect.getForUpdateString(alias, new LockOptions(LockMode.PESSIMISTIC_READ).setAliasSpecificLockMode(alias, LockMode.PESSIMISTIC_READ)));
assertEquals(" for update of a", dialect.getForUpdateString(alias, new LockOptions(LockMode.PESSIMISTIC_WRITE).setAliasSpecificLockMode(alias, LockMode.PESSIMISTIC_WRITE)));
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class LockModeTest method testQueryUsingLockOptions.
@Test
public void testQueryUsingLockOptions() {
// todo : need an association here to make sure the alias-specific lock modes are applied correctly
doInHibernate(this::sessionFactory, session -> {
session.createQuery("from A a").setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE)).uniqueResult();
session.createQuery("from A a").setLockOptions(new LockOptions().setAliasSpecificLockMode("a", LockMode.PESSIMISTIC_WRITE)).uniqueResult();
});
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class PessimisticWriteLockTimeoutTest method testNoWait.
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL81Dialect.class, SQLServer2005Dialect.class })
public void testNoWait() throws NoSuchFieldException, IllegalAccessException {
Session session = sessionFactory().openSession();
session.beginTransaction();
try {
session.createQuery("select a from A a", A.class).unwrap(org.hibernate.query.Query.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.NO_WAIT)).list();
String lockingQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue(lockingQuery.toLowerCase().contains("nowait"));
} finally {
session.getTransaction().commit();
session.close();
}
}
use of org.hibernate.LockOptions in project hibernate-orm by hibernate.
the class PessimisticWriteLockTimeoutTest method testSkipLocked.
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL95Dialect.class })
public void testSkipLocked() throws NoSuchFieldException, IllegalAccessException {
Session session = sessionFactory().openSession();
session.beginTransaction();
try {
session.createQuery("select a from A a", A.class).unwrap(org.hibernate.query.Query.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.SKIP_LOCKED)).list();
String lockingQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue(lockingQuery.toLowerCase().contains("skip locked"));
} finally {
session.getTransaction().commit();
session.close();
}
}
Aggregations