Search in sources :

Example 26 with Select

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

the class OrderByClauseVisitorUnitTests method shouldRenderOrderByAlias.

// DATAJDBC-309
@Test
void shouldRenderOrderByAlias() {
    Table employee = SQL.table("employee").as("emp");
    Column column = employee.column("name").as("emp_name");
    Select select = Select.builder().select(column).from(employee).orderBy(OrderByField.from(column).asc()).build();
    OrderByClauseVisitor visitor = new OrderByClauseVisitor(new SimpleRenderContext(NamingStrategies.asIs()));
    select.visit(visitor);
    assertThat(visitor.getRenderedPart().toString()).isEqualTo("emp_name ASC");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Column(org.springframework.data.relational.core.sql.Column) Select(org.springframework.data.relational.core.sql.Select) Test(org.junit.jupiter.api.Test)

Example 27 with Select

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

the class OrderByClauseVisitorUnitTests method shouldRenderOrderByFullyQualifiedName.

// GH-968
@Test
void shouldRenderOrderByFullyQualifiedName() {
    Table employee = SQL.table("employee");
    Column column = employee.column("name");
    Select select = Select.builder().select(column).from(employee).orderBy(OrderByField.from(column).asc()).build();
    OrderByClauseVisitor visitor = new OrderByClauseVisitor(new SimpleRenderContext(NamingStrategies.asIs()));
    select.visit(visitor);
    assertThat(visitor.getRenderedPart().toString()).isEqualTo("employee.name ASC");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Column(org.springframework.data.relational.core.sql.Column) Select(org.springframework.data.relational.core.sql.Select) Test(org.junit.jupiter.api.Test)

Example 28 with Select

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

the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLimitWithLockWrite.

// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitWithLockWrite() {
    Table table = Table.create("foo");
    LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
    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 FOR UPDATE");
}
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 Select

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

the class MySqlDialectRenderingUnitTests 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 30 with Select

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

the class MySqlDialectRenderingUnitTests 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.* FROM foo LIMIT 10, 18446744073709551615");
}
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