Search in sources :

Example 1 with Update

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

the class UpdateRendererUnitTests method shouldRenderUpdateWithLiteral.

// DATAJDBC-335
@Test
public void shouldRenderUpdateWithLiteral() {
    Table table = SQL.table("mytable");
    Column column = table.column("foo");
    Update update = StatementBuilder.update(table).set(column.set(SQL.literalOf(20))).build();
    assertThat(SqlRenderer.toString(update)).isEqualTo("UPDATE mytable SET foo = 20");
}
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 2 with Update

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

the class UpdateRendererUnitTests method shouldRenderSimpleUpdate.

// DATAJDBC-335
@Test
public void shouldRenderSimpleUpdate() {
    Table table = SQL.table("mytable");
    Column column = table.column("foo");
    Update update = StatementBuilder.update(table).set(column.set(SQL.bindMarker())).build();
    assertThat(SqlRenderer.toString(update)).isEqualTo("UPDATE mytable SET foo = ?");
}
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 3 with Update

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

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

Test (org.junit.jupiter.api.Test)4 Column (org.springframework.data.relational.core.sql.Column)4 Table (org.springframework.data.relational.core.sql.Table)4 Update (org.springframework.data.relational.core.sql.Update)4