use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLimitOffsetAndOrderByWithLockWrite.
// DATAJDBC-498
@Test
public void shouldRenderSelectWithLimitOffsetAndOrderByWithLockWrite() {
Table table = Table.create("foo");
LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(table.column("column_1")).limit(10).offset(20).lock(lockMode).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo WITH (UPDLOCK, ROWLOCK) ORDER BY foo.column_1 OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class SqlServerDialectRenderingUnitTests method shouldRenderSelectWithLimitOffset.
// DATAJDBC-278
@Test
public void shouldRenderSelectWithLimitOffset() {
Table table = Table.create("foo");
Select select = StatementBuilder.select(table.asterisk()).from(table).limit(10).offset(20).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.*, ROW_NUMBER() over (ORDER BY (SELECT 1)) AS __relational_row_number__ FROM foo ORDER BY __relational_row_number__ OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class SqlServerDialectRenderingUnitTests method shouldRenderSelectOrderByIgnoringNullHandling.
// GH-821
@Test
void shouldRenderSelectOrderByIgnoringNullHandling() {
Table table = Table.create("foo");
Select select = StatementBuilder.select(table.asterisk()).from(table).orderBy(OrderByField.from(Column.create("bar", table)).withNullHandling(Sort.NullHandling.NULLS_FIRST)).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo ORDER BY foo.bar");
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class SelectStatementVisitor method doLeave.
/*
* (non-Javadoc)
* @see org.springframework.data.relational.core.sql.render.DelegatingVisitor#doLeave(org.springframework.data.relational.core.sql.Visitable)
*/
@Override
public Delegation doLeave(Visitable segment) {
if (segment instanceof Select) {
Select select = (Select) segment;
builder.append("SELECT ");
if (select.isDistinct()) {
builder.append("DISTINCT ");
}
builder.append(selectList);
builder.append(selectRenderContext.afterSelectList().apply(select));
if (from.length() != 0) {
builder.append(" FROM ").append(from);
}
builder.append(selectRenderContext.afterFromTable().apply(select));
if (join.length() != 0) {
builder.append(' ').append(join);
}
if (where.length() != 0) {
builder.append(" WHERE ").append(where);
}
CharSequence orderBy = orderByClauseVisitor.getRenderedPart();
if (orderBy.length() != 0) {
builder.append(" ORDER BY ").append(orderBy);
}
builder.append(selectRenderContext.afterOrderBy(orderBy.length() != 0).apply(select));
return Delegation.leave();
}
return Delegation.retain();
}
use of org.springframework.data.relational.core.sql.Select in project spring-data-jdbc by spring-projects.
the class JoinVisitorTestsUnitTest method renderJoins.
static List<Fixture> renderJoins() {
Column colOne = Column.create("colOne", Table.create("tabOne"));
Table tabTwo = Table.create("tabTwo");
Column colTwo = Column.create("colTwo", tabTwo);
Column renamed = colOne.as("renamed");
Select select = Select.builder().select(renamed).from(colOne.getTable()).build();
InlineQuery inlineQuery = InlineQuery.create(select, "inline");
return Arrays.asList(fixture("simple join", new TestJoin(Join.JoinType.JOIN, tabTwo, colOne.isEqualTo(colTwo)), "JOIN tabTwo ON tabOne.colOne = tabTwo.colTwo"), fixture("inlineQuery", new TestJoin(Join.JoinType.JOIN, inlineQuery, colTwo.isEqualTo(inlineQuery.column("renamed"))), "JOIN (SELECT tabOne.colOne AS renamed FROM tabOne) inline ON tabTwo.colTwo = inline.renamed"));
}
Aggregations