Search in sources :

Example 1 with Column

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

the class OrderByClauseVisitorUnitTests method shouldApplyNamingStrategy.

// DATAJDBC-309
@Test
void shouldApplyNamingStrategy() {
    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.toUpper()));
    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 2 with Column

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

the class OrderByClauseVisitorUnitTests method shouldRenderOrderByFullyQualifiedNameWithTableAlias.

// GH-968
@Test
void shouldRenderOrderByFullyQualifiedNameWithTableAlias() {
    Table employee = SQL.table("employee").as("emp");
    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("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 3 with Column

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

the class NameRendererUnitTests method fullyQualifiedReferenceWithAlias.

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

Example 4 with Column

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

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

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