use of org.springframework.data.relational.core.sql.Select 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");
}
use of org.springframework.data.relational.core.sql.Select 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");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLimitWithLockWrite.
// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitWithLockWrite() {
Table table = Table.create("foo");
LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).lock(lockMode).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 10 FOR UPDATE");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLimit.
// DATAJDBC-278
@Test
public void shouldRenderSelectWithLimit() {
Table table = Table.create("foo");
Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 10");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithOffset.
// DATAJDBC-278
@Test
public void shouldRenderSelectWithOffset() {
Table table = Table.create("foo");
Select select = StatementBuilder.select(table.asterisk()).from(table).offset(10).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo LIMIT 10, 18446744073709551615");
}
Aggregations