Search in sources :

Example 26 with Table

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

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithOffset.

// DATAJDBC-278
@Test
public void shouldRenderSelectWithOffset() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).offset(10).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.*, ROW_NUMBER() over (ORDER BY (SELECT 1)) AS __relational_row_number__ FROM foo ORDER BY __relational_row_number__ OFFSET 10 ROWS");
}
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 27 with Table

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

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLimitOffsetWithLockWrite.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitOffsetWithLockWrite() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
    Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).offset(20).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.*, ROW_NUMBER() over (ORDER BY (SELECT 1)) AS __relational_row_number__ FROM foo WITH (UPDLOCK, ROWLOCK) ORDER BY __relational_row_number__ 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 28 with Table

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

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLimitOffsetAndOrderByWithLockWrite.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitOffsetAndOrderByWithLockWrite() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
    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 (UPDLOCK, 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 29 with Table

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

the class SqlServerDialectRenderingUnitTests 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.*, ROW_NUMBER() over (ORDER BY (SELECT 1)) AS __relational_row_number__ FROM foo ORDER BY __relational_row_number__ 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) Test(org.junit.jupiter.api.Test)

Example 30 with Table

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

the class SqlServerDialectRenderingUnitTests method shouldRenderSelectOrderByIgnoringNullHandling.

// GH-821
@Test
void shouldRenderSelectOrderByIgnoringNullHandling() {
    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");
}
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

Table (org.springframework.data.relational.core.sql.Table)59 Test (org.junit.jupiter.api.Test)53 Select (org.springframework.data.relational.core.sql.Select)40 LockMode (org.springframework.data.relational.core.sql.LockMode)14 Column (org.springframework.data.relational.core.sql.Column)9 Expression (org.springframework.data.relational.core.sql.Expression)4 Insert (org.springframework.data.relational.core.sql.Insert)4 Update (org.springframework.data.relational.core.sql.Update)4 Delete (org.springframework.data.relational.core.sql.Delete)3 SqlIdentifier (org.springframework.data.relational.core.sql.SqlIdentifier)2 PersistentPropertyPathExtension (org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension)1 Aliased (org.springframework.data.relational.core.sql.Aliased)1 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 Nullable (org.springframework.lang.Nullable)1