Search in sources :

Example 11 with Column

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

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

the class NameRendererUnitTests method fullyQualifiedReference.

// GH-1003, GH-968
@Test
void fullyQualifiedReference() {
    Column column = Table.aliased("table", "tab_alias").column("col");
    CharSequence rendered = NameRenderer.fullyQualifiedReference(context, column);
    assertThat(rendered).isEqualTo("tab_alias.col");
}
Also used : Column(org.springframework.data.relational.core.sql.Column) Test(org.junit.jupiter.api.Test)

Example 13 with Column

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

the class NameRendererUnitTests method rendersColumnWithoutTableName.

// GH-1003
@Test
void rendersColumnWithoutTableName() {
    Column column = Column.create("column", Table.create("table"));
    CharSequence rendered = NameRenderer.render(context, column);
    assertThat(rendered).isEqualTo("column");
}
Also used : Column(org.springframework.data.relational.core.sql.Column) Test(org.junit.jupiter.api.Test)

Example 14 with Column

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

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

Column (org.springframework.data.relational.core.sql.Column)17 Test (org.junit.jupiter.api.Test)14 Table (org.springframework.data.relational.core.sql.Table)9 Select (org.springframework.data.relational.core.sql.Select)5 Update (org.springframework.data.relational.core.sql.Update)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 SelectBuilder (org.springframework.data.relational.core.sql.SelectBuilder)2 ArrayList (java.util.ArrayList)1 PersistentPropertyPathExtension (org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension)1 RelationalPersistentProperty (org.springframework.data.relational.core.mapping.RelationalPersistentProperty)1 Expression (org.springframework.data.relational.core.sql.Expression)1 InlineQuery (org.springframework.data.relational.core.sql.InlineQuery)1 TestJoin (org.springframework.data.relational.core.sql.TestJoin)1