Search in sources :

Example 31 with Select

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

the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLimitWithLockRead.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitWithLockRead() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_READ;
    Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).lock(lockMode).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 10 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 32 with Select

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

the class PostgresDialectRenderingUnitTests method shouldRenderSimpleSelect.

// DATAJDBC-278
@Test
public void shouldRenderSimpleSelect() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo");
}
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 33 with Select

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

the class PostgresDialectRenderingUnitTests method shouldRenderSelectWithLimit.

// DATAJDBC-278
@Test
public void shouldRenderSelectWithLimit() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 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 34 with Select

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

the class PostgresDialectRenderingUnitTests method shouldApplyNamingStrategy.

// DATAJDBC-278
@Test
public void shouldApplyNamingStrategy() {
    factory.setNamingStrategy(NamingStrategies.toUpper());
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).build();
    String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
    assertThat(sql).isEqualTo("SELECT FOO.* FROM FOO");
}
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 35 with Select

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

the class PostgresDialectRenderingUnitTests method shouldRenderSelectOrderByWithNoOptions.

// GH-821
@Test
void shouldRenderSelectOrderByWithNoOptions() {
    Table table = Table.create("foo");
    Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(OrderByField.from(Column.create("bar", table))).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

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