use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class JdbcQueryCreator method complete.
/**
* Creates {@link ParametrizedQuery} applying the given {@link Criteria} and {@link Sort} definition.
*
* @param criteria {@link Criteria} to be applied to query
* @param sort sort option to be applied to query, must not be {@literal null}.
* @return instance of {@link ParametrizedQuery}
*/
@Override
protected ParametrizedQuery complete(@Nullable Criteria criteria, Sort sort) {
RelationalPersistentEntity<?> entity = entityMetadata.getTableEntity();
Table table = Table.create(entityMetadata.getTableName());
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
SelectBuilder.SelectLimitOffset limitOffsetBuilder = createSelectClause(entity, table);
SelectBuilder.SelectWhere whereBuilder = applyLimitAndOffset(limitOffsetBuilder);
SelectBuilder.SelectOrdered selectOrderBuilder = applyCriteria(criteria, entity, table, parameterSource, whereBuilder);
selectOrderBuilder = applyOrderBy(sort, entity, table, selectOrderBuilder);
SelectBuilder.BuildSelect completedBuildSelect = selectOrderBuilder;
if (this.lockMode.isPresent()) {
completedBuildSelect = selectOrderBuilder.lock(this.lockMode.get().value());
}
Select select = completedBuildSelect.build();
String sql = SqlRenderer.create(renderContextFactory.createRenderContext()).render(select);
return new ParametrizedQuery(sql, parameterSource);
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class MySqlDialectRenderingUnitTests method shouldRenderSelectWithLockRead.
// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockRead() {
Table table = Table.create("foo");
LockMode lockMode = LockMode.PESSIMISTIC_READ;
Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo LOCK IN SHARE MODE");
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class MySqlDialectRenderingUnitTests 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.* FROM foo LIMIT 20, 10");
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class PostgresDialectRenderingUnitTests method shouldRenderSelectWithLockWrite.
// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockWrite() {
Table table = Table.create("foo");
LockMode lockMode = LockMode.PESSIMISTIC_WRITE;
Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo FOR UPDATE OF foo");
}
use of org.springframework.data.relational.core.sql.Table in project spring-data-jdbc by spring-projects.
the class PostgresDialectRenderingUnitTests method shouldRenderSelectWithLockRead.
// DATAJDBC-498
@Test
public void shouldRenderSelectWithLockRead() {
Table table = Table.create("foo");
LockMode lockMode = LockMode.PESSIMISTIC_READ;
Select select = StatementBuilder.select(table.asterisk()).from(table).lock(lockMode).build();
String sql = SqlRenderer.create(factory.createRenderContext()).render(select);
assertThat(sql).isEqualTo("SELECT foo.* FROM foo FOR SHARE OF foo");
}
Aggregations