Search in sources :

Example 1 with LockMode

use of org.springframework.data.relational.core.sql.LockMode in project spring-data-jdbc by spring-projects.

the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLockRead.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockRead() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_READ;
    Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo LOCK IN SHARE MODE");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) LockMode(org.springframework.data.relational.core.sql.LockMode) Test(org.junit.jupiter.api.Test)

Example 2 with LockMode

use of org.springframework.data.relational.core.sql.LockMode in project spring-data-jdbc by spring-projects.

the class PostgresDialectRenderingUnitTests method shouldRenderSelectWithLockWrite.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockWrite() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
    Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo FOR UPDATE OF foo");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) LockMode(org.springframework.data.relational.core.sql.LockMode) Test(org.junit.jupiter.api.Test)

Example 3 with LockMode

use of org.springframework.data.relational.core.sql.LockMode in project spring-data-jdbc by spring-projects.

the class PostgresDialectRenderingUnitTests method shouldRenderSelectWithLockRead.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockRead() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_READ;
    Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo FOR SHARE OF foo");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) LockMode(org.springframework.data.relational.core.sql.LockMode) Test(org.junit.jupiter.api.Test)

Example 4 with LockMode

use of org.springframework.data.relational.core.sql.LockMode in project spring-data-jdbc by spring-projects.

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLimitOffsetAndOrderByWithLockRead.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitOffsetAndOrderByWithLockRead() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_READ;
    Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(table.column("column_1")).limit(10).offset(20).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo WITH (HOLDLOCK, ROWLOCK) ORDER BY foo.column_1 OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) LockMode(org.springframework.data.relational.core.sql.LockMode) Test(org.junit.jupiter.api.Test)

Example 5 with LockMode

use of org.springframework.data.relational.core.sql.LockMode in project spring-data-jdbc by spring-projects.

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLockRead.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockRead() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_READ;
    Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo WITH (HOLDLOCK, ROWLOCK)");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) LockMode(org.springframework.data.relational.core.sql.LockMode) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)14 LockMode (org.springframework.data.relational.core.sql.LockMode)14 Select (org.springframework.data.relational.core.sql.Select)14 Table (org.springframework.data.relational.core.sql.Table)14