Skip to content

Commit 5188673

Browse files
Kotlin: deprecate extension function for old query API
1 parent 29dad9c commit 5188673

File tree

2 files changed

+26
-5
lines changed
  • objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin
  • tests/objectbox-java-test/src/test/java/io/objectbox/query

2 files changed

+26
-5
lines changed

objectbox-kotlin/src/main/kotlin/io/objectbox/kotlin/Box.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 ObjectBox Ltd. All rights reserved.
2+
* Copyright 2021-2025 ObjectBox Ltd. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,13 +22,17 @@ import io.objectbox.query.QueryBuilder
2222

2323

2424
/**
25+
* Note: new code should use the [Box.query] functions directly, including the new query API.
26+
*
2527
* Allows building a query for this Box instance with a call to [build][QueryBuilder.build] to return a [Query] instance.
28+
*
2629
* ```
2730
* val query = box.query {
2831
* equal(Entity_.property, value)
2932
* }
3033
* ```
3134
*/
35+
@Deprecated("New code should use query(queryCondition).build() instead.")
3236
inline fun <T> Box<T>.query(block: QueryBuilder<T>.() -> Unit): Query<T> {
3337
val builder = query()
3438
block(builder)

tests/objectbox-java-test/src/test/java/io/objectbox/query/QueryTestK.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2020-2025 ObjectBox Ltd. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package io.objectbox.query
218

319
import io.objectbox.TestEntity_
@@ -19,7 +35,8 @@ class QueryTestK : AbstractQueryTest() {
1935
val resultJava = box.query().`in`(TestEntity_.simpleLong, valuesLong).build().use {
2036
it.findFirst()
2137
}
22-
val result = box.query {
38+
// Keep testing the old query API on purpose
39+
@Suppress("DEPRECATION") val result = box.query {
2340
inValues(TestEntity_.simpleLong, valuesLong)
2441
}.use {
2542
it.findFirst()
@@ -33,8 +50,8 @@ class QueryTestK : AbstractQueryTest() {
3350
putTestEntity("Fry", 12)
3451
putTestEntity("Fry", 10)
3552

36-
// current query API
37-
val query = box.query {
53+
// Old query API
54+
@Suppress("DEPRECATION") val query = box.query {
3855
less(TestEntity_.simpleInt, 12)
3956
or()
4057
inValues(TestEntity_.simpleLong, longArrayOf(1012))
@@ -46,7 +63,7 @@ class QueryTestK : AbstractQueryTest() {
4663
assertEquals(10, results[0].simpleInt)
4764
assertEquals(12, results[1].simpleInt)
4865

49-
// suggested query API
66+
// New query API
5067
val newQuery = box.query(
5168
(TestEntity_.simpleInt less 12 or (TestEntity_.simpleLong oneOf longArrayOf(1012)))
5269
and (TestEntity_.simpleString equal "Fry")

0 commit comments

Comments
 (0)