Search in sources :

Example 31 with Table

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

the class QueryMapperUnitTests method shouldMapCountFunction.

// DATAJDBC-318
@Test
public void shouldMapCountFunction() {
    Table table = Table.create("my_table").as("my_aliased_table");
    Expression mappedObject = mapper.getMappedObject(Functions.count(table.column("alternative")), context.getRequiredPersistentEntity(Person.class));
    assertThat(mappedObject).hasToString("COUNT(my_aliased_table.\"another_name\")");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Expression(org.springframework.data.relational.core.sql.Expression) Test(org.junit.jupiter.api.Test)

Example 32 with Table

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

the class QueryMapperUnitTests method shouldMapExpression.

// DATAJDBC-318
@Test
public void shouldMapExpression() {
    Table table = Table.create("my_table").as("my_aliased_table");
    Expression mappedObject = mapper.getMappedObject(table.column("alternative").as("my_aliased_col"), context.getRequiredPersistentEntity(Person.class));
    assertThat(mappedObject).hasToString("my_aliased_table.\"another_name\" AS my_aliased_col");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Expression(org.springframework.data.relational.core.sql.Expression) Test(org.junit.jupiter.api.Test)

Example 33 with Table

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

the class QueryMapperUnitTests method shouldMapExpressionWithoutEntity.

// DATAJDBC-318
@Test
public void shouldMapExpressionWithoutEntity() {
    Table table = Table.create("my_table").as("my_aliased_table");
    Expression mappedObject = mapper.getMappedObject(table.column("my_col").as("my_aliased_col"), null);
    assertThat(mappedObject).hasToString("my_aliased_table.my_col AS my_aliased_col");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Expression(org.springframework.data.relational.core.sql.Expression) Test(org.junit.jupiter.api.Test)

Example 34 with Table

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

the class QueryMapperUnitTests method shouldMapExpressionToUnknownColumn.

// DATAJDBC-318
@Test
public void shouldMapExpressionToUnknownColumn() {
    Table table = Table.create("my_table").as("my_aliased_table");
    Expression mappedObject = mapper.getMappedObject(table.column("unknown").as("my_aliased_col"), context.getRequiredPersistentEntity(Person.class));
    assertThat(mappedObject).hasToString("my_aliased_table.unknown AS my_aliased_col");
}
Also used : Table(org.springframework.data.relational.core.sql.Table) Expression(org.springframework.data.relational.core.sql.Expression) Test(org.junit.jupiter.api.Test)

Example 35 with Table

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

the class SqlContext method getTable.

Table getTable(PersistentPropertyPathExtension path) {
    SqlIdentifier tableAlias = path.getTableAlias();
    Table table = Table.create(path.getTableName());
    return tableAlias == null ? table : table.as(tableAlias);
}
Also used : Table(org.springframework.data.relational.core.sql.Table) SqlIdentifier(org.springframework.data.relational.core.sql.SqlIdentifier)

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