Search in sources :

Example 41 with Table

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

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

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

the class InsertRendererUnitTests method shouldRenderInsert.

// DATAJDBC-335
@Test
public void shouldRenderInsert() {
    Table bar = SQL.table("bar");
    Insert insert = Insert.builder().into(bar).values(SQL.bindMarker()).build();
    assertThat(SqlRenderer.toString(insert)).isEqualTo("INSERT INTO bar VALUES (?)");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Insert(org.springframework.data.relational.core.sql.Insert) Test(org.junit.jupiter.api.Test)

Example 44 with Table

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

the class UpdateRendererUnitTests method shouldRenderMultipleColumnUpdate.

// DATAJDBC-335
@Test
public void shouldRenderMultipleColumnUpdate() {
    Table table = SQL.table("mytable");
    Column foo = table.column("foo");
    Column bar = table.column("bar");
    Update update = // 
    StatementBuilder.update(table).set(foo.set(SQL.bindMarker()), // 
    bar.set(SQL.bindMarker())).build();
    assertThat(SqlRenderer.toString(update)).isEqualTo("UPDATE mytable SET foo = ?, bar = ?");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Column(org.springframework.data.relational.core.sql.Column) Update(org.springframework.data.relational.core.sql.Update) Test(org.junit.jupiter.api.Test)

Example 45 with Table

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

the class UpdateRendererUnitTests method shouldCreateUpdateWIthCondition.

// DATAJDBC-335
@Test
public void shouldCreateUpdateWIthCondition() {
    Table table = SQL.table("mytable");
    Column column = table.column("foo");
    Update update = StatementBuilder.update(table).set(column.set(SQL.bindMarker())).where(column.isNull()).build();
    assertThat(SqlRenderer.toString(update)).isEqualTo("UPDATE mytable SET foo = ? WHERE mytable.foo IS NULL");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Column(org.springframework.data.relational.core.sql.Column) Update(org.springframework.data.relational.core.sql.Update) 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