#342 - Polishing.
Remove Kotlin extension for Criteria as it should live in Spring Data Relational. Add author tags. Reformat code.
This commit is contained in:
@@ -57,7 +57,6 @@ import org.springframework.data.r2dbc.convert.ColumnMapRowMapper;
|
||||
import org.springframework.data.r2dbc.dialect.BindTarget;
|
||||
import org.springframework.data.r2dbc.mapping.OutboundRow;
|
||||
import org.springframework.data.r2dbc.mapping.SettableValue;
|
||||
import org.springframework.data.r2dbc.query.Criteria;
|
||||
import org.springframework.data.r2dbc.query.Update;
|
||||
import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator;
|
||||
import org.springframework.data.relational.core.query.CriteriaDefinition;
|
||||
@@ -70,6 +69,7 @@ import org.springframework.util.StringUtils;
|
||||
* Default implementation of {@link DatabaseClient}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
|
||||
@@ -700,8 +700,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
|
||||
DefaultSelectSpecSupport(SqlIdentifier table, List<SqlIdentifier> projectedFields,
|
||||
@Nullable CriteriaDefinition criteria,
|
||||
Sort sort, Pageable page) {
|
||||
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page) {
|
||||
this.table = table;
|
||||
this.projectedFields = projectedFields;
|
||||
this.criteria = criteria;
|
||||
@@ -761,8 +760,7 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
private class DefaultGenericSelectSpec extends DefaultSelectSpecSupport implements GenericSelectSpec {
|
||||
|
||||
DefaultGenericSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields,
|
||||
@Nullable CriteriaDefinition criteria,
|
||||
Sort sort, Pageable page) {
|
||||
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page) {
|
||||
super(table, projectedFields, criteria, sort, page);
|
||||
}
|
||||
|
||||
@@ -868,8 +866,8 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
|
||||
DefaultTypedSelectSpec(SqlIdentifier table, List<SqlIdentifier> projectedFields,
|
||||
@Nullable CriteriaDefinition criteria,
|
||||
Sort sort, Pageable page, Class<T> typeToRead, BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
@Nullable CriteriaDefinition criteria, Sort sort, Pageable page, Class<T> typeToRead,
|
||||
BiFunction<Row, RowMetadata, T> mappingFunction) {
|
||||
|
||||
super(table, projectedFields, criteria, sort, page);
|
||||
|
||||
@@ -1358,8 +1356,8 @@ class DefaultDatabaseClient implements DatabaseClient, ConnectionAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
PreparedOperation<?> operation = mapper.getMappedObject(
|
||||
mapper.createUpdate(table, update).withCriteria(org.springframework.data.relational.core.query.Criteria.where(dataAccessStrategy.toSql(ids.get(0))).is(id)));
|
||||
PreparedOperation<?> operation = mapper.getMappedObject(mapper.createUpdate(table, update).withCriteria(
|
||||
org.springframework.data.relational.core.query.Criteria.where(dataAccessStrategy.toSql(ids.get(0))).is(id)));
|
||||
|
||||
return exchangeUpdate(operation);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,55 +18,32 @@ package org.springframework.data.r2dbc.core
|
||||
import org.springframework.data.r2dbc.query.Criteria
|
||||
|
||||
/**
|
||||
* Extension for [Criteria.CriteriaStep.is] providing a
|
||||
* Extension for [Criteria.CriteriaStep. is] providing a
|
||||
* `eq(value)` variant.
|
||||
*
|
||||
* @author Jonas Bark
|
||||
*/
|
||||
@Deprecated("Deprecated in favor of Spring Data Relational's Criteria")
|
||||
infix fun Criteria.CriteriaStep.isEquals(value: Any): Criteria =
|
||||
`is`(value)
|
||||
|
||||
/**
|
||||
* Extension for [Criteria.CriteriaStep.in] providing a
|
||||
* Extension for [Criteria.CriteriaStep. in] providing a
|
||||
* `isIn(value)` variant.
|
||||
*
|
||||
* @author Jonas Bark
|
||||
*/
|
||||
@Deprecated("Deprecated in favor of Spring Data Relational's Criteria")
|
||||
fun Criteria.CriteriaStep.isIn(vararg value: Any): Criteria =
|
||||
`in`(value)
|
||||
|
||||
/**
|
||||
* Extension for [Criteria.CriteriaStep.in] providing a
|
||||
* Extension for [Criteria.CriteriaStep. in] providing a
|
||||
* `isIn(value)` variant.
|
||||
*
|
||||
* @author Jonas Bark
|
||||
*/
|
||||
@Deprecated("Deprecated in favor of Spring Data Relational's 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)
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.springframework.data.domain.Sort.Order.*;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.convert.MappingR2dbcConverter;
|
||||
import org.springframework.data.r2dbc.convert.R2dbcConverter;
|
||||
@@ -31,10 +32,10 @@ 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.Criteria;
|
||||
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}.
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.data.r2dbc.query.Criteria
|
||||
* Unit tests for [Criteria.CriteriaStep] extensions.
|
||||
*
|
||||
* @author Jonas Bark
|
||||
* @author Mingyuan Wu
|
||||
*/
|
||||
class CriteriaStepExtensionsTests {
|
||||
|
||||
@@ -74,49 +73,4 @@ 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