Search in sources :

Example 36 with LockOptions

use of org.hibernate.LockOptions in project hibernate-orm by hibernate.

the class PostgreSQL81DialectTestCase method testGetForUpdateStringWithAliasesAndLockOptions.

/**
	 * Tests that getForUpdateString(String aliases, LockOptions lockOptions) will return a String
	 * that will effect the SELECT ... FOR UPDATE OF tableAlias1, ..., tableAliasN
	 */
@TestForIssue(jiraKey = "HHH-5654")
public void testGetForUpdateStringWithAliasesAndLockOptions() {
    PostgreSQL81Dialect dialect = new PostgreSQL81Dialect();
    LockOptions lockOptions = new LockOptions();
    lockOptions.setAliasSpecificLockMode("tableAlias1", LockMode.PESSIMISTIC_WRITE);
    String forUpdateClause = dialect.getForUpdateString("tableAlias1", lockOptions);
    assertTrue("for update of tableAlias1".equals(forUpdateClause));
    lockOptions.setAliasSpecificLockMode("tableAlias2", LockMode.PESSIMISTIC_WRITE);
    forUpdateClause = dialect.getForUpdateString("tableAlias1,tableAlias2", lockOptions);
    assertTrue("for update of tableAlias1,tableAlias2".equals(forUpdateClause));
}
Also used : LockOptions(org.hibernate.LockOptions) TestForIssue(org.hibernate.testing.TestForIssue)

Example 37 with LockOptions

use of org.hibernate.LockOptions in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method testAppendLockHintUpgradeNoWait.

@Test
@TestForIssue(jiraKey = "HHH-9635")
public void testAppendLockHintUpgradeNoWait() {
    final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)";
    LockOptions lockOptions = new LockOptions(LockMode.UPGRADE_NOWAIT);
    String lockHint = dialect.appendLockHint(lockOptions, "tab1");
    assertEquals(expectedLockHint, lockHint);
}
Also used : LockOptions(org.hibernate.LockOptions) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 38 with LockOptions

use of org.hibernate.LockOptions in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method testAppendLockHintWriteWithNoTimeOut.

@Test
@TestForIssue(jiraKey = "HHH-9635")
public void testAppendLockHintWriteWithNoTimeOut() {
    final String expectedLockHint = "tab1 with (updlock, rowlock, nowait)";
    LockOptions lockOptions = new LockOptions(LockMode.WRITE);
    lockOptions.setTimeOut(LockOptions.NO_WAIT);
    String lockHint = dialect.appendLockHint(lockOptions, "tab1");
    assertEquals(expectedLockHint, lockHint);
}
Also used : LockOptions(org.hibernate.LockOptions) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 39 with LockOptions

use of org.hibernate.LockOptions in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method testAppendLockHintPessimisticRead.

@Test
@TestForIssue(jiraKey = "HHH-9635")
public void testAppendLockHintPessimisticRead() {
    final String expectedLockHint = "tab1 with (holdlock, rowlock)";
    LockOptions lockOptions = new LockOptions(LockMode.PESSIMISTIC_READ);
    String lockHint = dialect.appendLockHint(lockOptions, "tab1");
    assertEquals(expectedLockHint, lockHint);
}
Also used : LockOptions(org.hibernate.LockOptions) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 40 with LockOptions

use of org.hibernate.LockOptions in project hibernate-orm by hibernate.

the class SQLServer2005DialectTestCase method testAppendLockHintReadPastLocking.

@Test
@TestForIssue(jiraKey = "HHH-9635")
public void testAppendLockHintReadPastLocking() {
    final String expectedLockHint = "tab1 with (updlock, rowlock, readpast)";
    LockOptions lockOptions = new LockOptions(LockMode.UPGRADE_SKIPLOCKED);
    String lockHint = dialect.appendLockHint(lockOptions, "tab1");
    assertEquals(expectedLockHint, lockHint);
}
Also used : LockOptions(org.hibernate.LockOptions) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

LockOptions (org.hibernate.LockOptions)64 Test (org.junit.Test)43 Session (org.hibernate.Session)23 TestForIssue (org.hibernate.testing.TestForIssue)14 PersistenceException (javax.persistence.PersistenceException)5 SQLGrammarException (org.hibernate.exception.SQLGrammarException)5 LockMode (org.hibernate.LockMode)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 RowSelection (org.hibernate.engine.spi.RowSelection)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)3 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)3 AfterLoadAction (org.hibernate.loader.spi.AfterLoadAction)3 Loadable (org.hibernate.persister.entity.Loadable)3 RequiresDialect (org.hibernate.testing.RequiresDialect)3 Serializable (java.io.Serializable)2 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2