Skip to content

Commit 01c7edc

Browse files
committed
DATAMONGO-2138 - alike() takes no property; restrict regex() to String
1 parent a0e5d8c commit 01c7edc

File tree

2 files changed

+61
-49
lines changed

2 files changed

+61
-49
lines changed

spring-data-mongodb/src/main/kotlin/org/springframework/data/mongodb/core/query/TypedCriteriaBuilder.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,33 @@ class TypedCriteriaBuilder {
198198
* See [MongoDB Query operator: $regex](https://docs.mongodb.com/manual/reference/operator/query/regex/)
199199
* @see Criteria.regex
200200
*/
201-
infix fun KProperty<*>.regex(re: String) = addOperation { regex(re, null) }
201+
infix fun KProperty<String?>.regex(re: String) = addOperation { regex(re, null) }
202202

203203
/**
204204
* Creates a criterion using a $regex and $options operator.
205205
*
206206
* See [MongoDB Query operator: $regex](https://docs.mongodb.com/manual/reference/operator/query/regex/)
207207
* @see Criteria.regex
208208
*/
209-
fun KProperty<*>.regex(re: String, options: String?) = addOperation { regex(re, options) }
209+
fun KProperty<String?>.regex(re: String, options: String?) = addOperation { regex(re, options) }
210210

211211
/**
212212
* Syntactical sugar for [isEqualTo] making obvious that we create a regex predicate.
213213
* @see Criteria.regex
214214
*/
215-
infix fun KProperty<*>.regex(re: Regex) = addOperation { regex(re.toPattern()) }
215+
infix fun KProperty<String?>.regex(re: Regex) = addOperation { regex(re.toPattern()) }
216216

217217
/**
218218
* Syntactical sugar for [isEqualTo] making obvious that we create a regex predicate.
219219
* @see Criteria.regex
220220
*/
221-
infix fun KProperty<*>.regex(re: Pattern) = addOperation { regex(re) }
221+
infix fun KProperty<String?>.regex(re: Pattern) = addOperation { regex(re) }
222222

223223
/**
224224
* Syntactical sugar for [isEqualTo] making obvious that we create a regex predicate.
225225
* @see Criteria.regex
226226
*/
227-
infix fun KProperty<*>.regex(re: BsonRegularExpression) = addOperation { regex(re) }
227+
infix fun KProperty<String?>.regex(re: BsonRegularExpression) = addOperation { regex(re) }
228228

229229
/**
230230
* Creates a geospatial criterion using a $geoWithin $centerSphere operation. This is only available for
@@ -311,7 +311,7 @@ class TypedCriteriaBuilder {
311311
* Creates a criterion using the given object as a pattern.
312312
* @see Criteria.alike
313313
*/
314-
infix fun KProperty<*>.alike(sample: Example<*>) = addOperation { alike(sample) }
314+
fun alike(sample: Example<*>) = addOperation { alike(sample) }
315315

316316
/**
317317
* Creates a criterion (`$jsonSchema`) matching documents against a given structure defined by the
@@ -343,6 +343,10 @@ class TypedCriteriaBuilder {
343343
criteria = criteria.and(nestedFieldName(this)).operation()
344344
}
345345

346+
private fun addOperation(operation: Criteria.() -> Criteria) {
347+
criteria = criteria.operation()
348+
}
349+
346350
/**
347351
* Creates an 'or' criteria using the $or operator for all of the provided criteria
348352
*

0 commit comments

Comments
 (0)