Search in sources :

Example 6 with Select

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

the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLimitOffset.

// DATAJDBC-278
@Test
public void shouldRenderSelectWithLimitOffset() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).offset(20).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 20, 10");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) Test(org.junit.jupiter.api.Test)

Example 7 with Select

use of org.springframework.data.relational.core.sql.Select 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 8 with Select

use of org.springframework.data.relational.core.sql.Select 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 9 with Select

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

the class PostgresDialectRenderingUnitTests method shouldRenderSelectOrderByWithDirection.

// GH-821
@Test
void shouldRenderSelectOrderByWithDirection() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(OrderByField.from(Column.create("bar", table), Sort.Direction.ASC)).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo ORDER BY foo.bar ASC");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) Test(org.junit.jupiter.api.Test)

Example 10 with Select

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

the class PostgresDialectRenderingUnitTests method shouldRenderSelectOrderByWithNullPrecedence.

// GH-821
@Test
void shouldRenderSelectOrderByWithNullPrecedence() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(OrderByField.from(Column.create("bar", table)).withNullHandling(Sort.NullHandling.NULLS_FIRST)).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo ORDER BY foo.bar NULLS FIRST");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Select(org.springframework.data.relational.core.sql.Select) Test(org.junit.jupiter.api.Test)

Aggregations

Select (org.springframework.data.relational.core.sql.Select)41 Table (org.springframework.data.relational.core.sql.Table)40 Test (org.junit.jupiter.api.Test)37 LockMode (org.springframework.data.relational.core.sql.LockMode)14 Column (org.springframework.data.relational.core.sql.Column)5 InlineQuery (org.springframework.data.relational.core.sql.InlineQuery)1 SelectBuilder (org.springframework.data.relational.core.sql.SelectBuilder)1 TestFrom (org.springframework.data.relational.core.sql.TestFrom)1 TestJoin (org.springframework.data.relational.core.sql.TestJoin)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1