#342 - Move off deprecated Criteria and Update.
This commit is contained in:
@@ -1359,7 +1359,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
|
||||
PreparedOperation<?> operation = mapper.getMappedObject(
|
||||
mapper.createUpdate(table, update).withCriteria(Criteria.where(dataAccessStrategy.toSql(ids.get(0))).is(id)));
|
||||
mapper.createUpdate(table, update).withCriteria(org.springframework.data.relational.core.query.Criteria.where(dataAccessStrategy.toSql(ids.get(0))).is(id)));
|
||||
|
||||
return exchangeUpdate(operation);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.dialect.BindMarkers;
|
||||
import org.springframework.data.r2dbc.mapping.SettableValue;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.CriteriaDefinition;
|
||||
import org.springframework.data.relational.core.sql.Expression;
|
||||
import org.springframework.data.relational.core.sql.SqlIdentifier;
|
||||
@@ -44,6 +44,7 @@ import org.springframework.lang.Nullable;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Roman Chigvintsev
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public interface StatementMapper {
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.data.r2dbc.core.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityOperations;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.r2dbc.core.ReactiveDataAccessStrategy;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.data.relational.repository.query.RelationalEntityInformation;
|
||||
@@ -39,6 +39,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Jens Schauder
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
@Transactional(readOnly = true)
|
||||
public class SimpleR2dbcRepository<T, ID> implements ReactiveCrudRepository<T, ID> {
|
||||
|
||||
@@ -43,3 +43,30 @@ fun Criteria.CriteriaStep.isIn(vararg value: Any): Criteria =
|
||||
*/
|
||||
fun Criteria.CriteriaStep.isIn(values: Collection<Any>): Criteria =
|
||||
`in`(values)
|
||||
|
||||
/**
|
||||
* Extension for [org.springframework.data.relational.core.query.Criteria.CriteriaStep.is] providing a
|
||||
* `eq(value)` variant.
|
||||
*
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
infix fun org.springframework.data.relational.core.query.Criteria.CriteriaStep.isEquals(value: Any): org.springframework.data.relational.core.query.Criteria =
|
||||
`is`(value)
|
||||
|
||||
/**
|
||||
* Extension for [org.springframework.data.relational.core.query.Criteria.CriteriaStep.in] providing a
|
||||
* `isIn(value)` variant.
|
||||
*
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
fun org.springframework.data.relational.core.query.Criteria.CriteriaStep.isIn(vararg value: Any): org.springframework.data.relational.core.query.Criteria =
|
||||
`in`(value)
|
||||
|
||||
/**
|
||||
* Extension for [org.springframework.data.relational.core.query.Criteria.CriteriaStep.in] providing a
|
||||
* `isIn(value)` variant.
|
||||
*
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
fun org.springframework.data.relational.core.query.Criteria.CriteriaStep.isIn(values: Collection<Any>): org.springframework.data.relational.core.query.Criteria =
|
||||
`in`(values)
|
||||
|
||||
@@ -34,8 +34,8 @@ import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.r2dbc.query.Update;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Update;
|
||||
import org.springframework.data.r2dbc.testing.R2dbcIntegrationTestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -44,6 +44,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
* Integration tests for {@link DatabaseClient}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public abstract class AbstractDatabaseClientIntegrationTests extends R2dbcIntegrationTestSupport {
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.data.r2dbc.dialect.MySqlDialect;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.MariaDbTestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
@@ -46,6 +46,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
* Integration tests for {@link DatabaseClient} against MariaDB.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public class MariaDbDatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests {
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.data.r2dbc.dialect.MySqlDialect;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.r2dbc.testing.ExternalDatabase;
|
||||
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
@@ -46,6 +46,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
* Integration tests for {@link DatabaseClient} against MySQL.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public class MySqlDatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests {
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.data.r2dbc.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.r2dbc.query.Criteria.*;
|
||||
import static org.springframework.data.relational.core.query.Criteria.*;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -29,6 +30,7 @@ import org.springframework.data.relational.core.sql.SqlIdentifier;
|
||||
* Unit tests for {@link Criteria}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public class CriteriaUnitTests {
|
||||
|
||||
|
||||
@@ -34,11 +34,13 @@ import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.sql.Expression;
|
||||
import org.springframework.data.relational.core.sql.Functions;
|
||||
import org.springframework.data.relational.core.sql.Table;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QueryMapper}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public class QueryMapperUnitTests {
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.data.r2dbc.dialect.PostgresDialect;
|
||||
import org.springframework.data.r2dbc.mapping.R2dbcMappingContext;
|
||||
import org.springframework.data.r2dbc.mapping.SettableValue;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
import org.springframework.data.relational.core.query.Update;
|
||||
import org.springframework.data.relational.core.sql.AssignValue;
|
||||
import org.springframework.data.relational.core.sql.Expression;
|
||||
import org.springframework.data.relational.core.sql.SQL;
|
||||
@@ -41,6 +42,7 @@ import org.springframework.data.relational.core.sql.Table;
|
||||
* Unit tests for {@link UpdateMapper}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
public class UpdateMapperUnitTests {
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.r2dbc.query.Criteria
|
||||
* Unit tests for [Criteria.CriteriaStep] extensions.
|
||||
*
|
||||
* @author Jonas Bark
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
class CriteriaStepExtensionsTests {
|
||||
|
||||
@@ -73,4 +74,49 @@ class CriteriaStepExtensionsTests {
|
||||
spec.`in`(listOf("test"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-122
|
||||
fun eqIsCriteriaStepForSpringData2() {
|
||||
|
||||
val spec = mockk<org.springframework.data.relational.core.query.Criteria.CriteriaStep>()
|
||||
val criteria = mockk<org.springframework.data.relational.core.query.Criteria>()
|
||||
|
||||
every { spec.`is`("test") } returns criteria
|
||||
|
||||
assertThat(spec isEquals "test").isEqualTo(criteria)
|
||||
|
||||
verify {
|
||||
spec.`is`("test")
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-122
|
||||
fun inVarargCriteriaStepForSpringData2() {
|
||||
|
||||
val spec = mockk<org.springframework.data.relational.core.query.Criteria.CriteriaStep>()
|
||||
val criteria = mockk<org.springframework.data.relational.core.query.Criteria>()
|
||||
|
||||
every { spec.`in`(any() as Array<Any>) } returns criteria
|
||||
|
||||
assertThat(spec.isIn("test")).isEqualTo(criteria)
|
||||
|
||||
verify {
|
||||
spec.`in`(arrayOf("test"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-122
|
||||
fun inListCriteriaStepForSpringData2() {
|
||||
|
||||
val spec = mockk<org.springframework.data.relational.core.query.Criteria.CriteriaStep>()
|
||||
val criteria = mockk<org.springframework.data.relational.core.query.Criteria>()
|
||||
|
||||
every { spec.`in`(listOf("test")) } returns criteria
|
||||
|
||||
assertThat(spec.isIn(listOf("test"))).isEqualTo(criteria)
|
||||
|
||||
verify {
|
||||
spec.`in`(listOf("test"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user