Skip to content

Commit 0c7cb89

Browse files
deprecate ktorm-global
1 parent 4a1bbac commit 0c7cb89

File tree

15 files changed

+74
-0
lines changed

15 files changed

+74
-0
lines changed

ktorm-global/src/main/kotlin/org/ktorm/global/Aggregations.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION")
18+
1719
package org.ktorm.global
1820

1921
import org.ktorm.database.Database
@@ -24,90 +26,103 @@ import org.ktorm.schema.ColumnDeclaring
2426
/**
2527
* Check if all the records in the table matches the given [predicate].
2628
*/
29+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
2730
public inline fun <E : Any, T : BaseTable<E>> T.all(predicate: (T) -> ColumnDeclaring<Boolean>): Boolean {
2831
return Database.global.sequenceOf(this).all(predicate)
2932
}
3033

3134
/**
3235
* Check if there is any record in the table.
3336
*/
37+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
3438
public fun <E : Any, T : BaseTable<E>> T.any(): Boolean {
3539
return Database.global.sequenceOf(this).any()
3640
}
3741

3842
/**
3943
* Check if there is any record in the table matches the given [predicate].
4044
*/
45+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4146
public inline fun <E : Any, T : BaseTable<E>> T.any(predicate: (T) -> ColumnDeclaring<Boolean>): Boolean {
4247
return Database.global.sequenceOf(this).any(predicate)
4348
}
4449

4550
/**
4651
* Return `true` if there is no records in the table.
4752
*/
53+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4854
public fun <E : Any, T : BaseTable<E>> T.none(): Boolean {
4955
return Database.global.sequenceOf(this).none()
5056
}
5157

5258
/**
5359
* Return `true` if there is no records in the table that matches the given [predicate].
5460
*/
61+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
5562
public inline fun <E : Any, T : BaseTable<E>> T.none(predicate: (T) -> ColumnDeclaring<Boolean>): Boolean {
5663
return Database.global.sequenceOf(this).none(predicate)
5764
}
5865

5966
/**
6067
* Return `true` if the table has no records.
6168
*/
69+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
6270
public fun <E : Any, T : BaseTable<E>> T.isEmpty(): Boolean {
6371
return Database.global.sequenceOf(this).isEmpty()
6472
}
6573

6674
/**
6775
* Return `true` if the table has at lease one record.
6876
*/
77+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
6978
public fun <E : Any, T : BaseTable<E>> T.isNotEmpty(): Boolean {
7079
return Database.global.sequenceOf(this).isNotEmpty()
7180
}
7281

7382
/**
7483
* Return the records count in the table.
7584
*/
85+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
7686
public fun <E : Any, T : BaseTable<E>> T.count(): Int {
7787
return Database.global.sequenceOf(this).count()
7888
}
7989

8090
/**
8191
* Return the records count in the table that matches the given [predicate].
8292
*/
93+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
8394
public inline fun <E : Any, T : BaseTable<E>> T.count(predicate: (T) -> ColumnDeclaring<Boolean>): Int {
8495
return Database.global.sequenceOf(this).count(predicate)
8596
}
8697

8798
/**
8899
* Return the sum of the given column or expression of all the records, null if there are no records in the table.
89100
*/
101+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
90102
public inline fun <E : Any, T : BaseTable<E>, C : Number> T.sumBy(selector: (T) -> ColumnDeclaring<C>): C? {
91103
return Database.global.sequenceOf(this).sumBy(selector)
92104
}
93105

94106
/**
95107
* Return the max value of the given column or expression of all the records, null if there are no records in the table.
96108
*/
109+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
97110
public inline fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T.maxBy(selector: (T) -> ColumnDeclaring<C>): C? {
98111
return Database.global.sequenceOf(this).maxBy(selector)
99112
}
100113

101114
/**
102115
* Return the min value of the given column or expression of all the records, null if there are no records in the table.
103116
*/
117+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
104118
public inline fun <E : Any, T : BaseTable<E>, C : Comparable<C>> T.minBy(selector: (T) -> ColumnDeclaring<C>): C? {
105119
return Database.global.sequenceOf(this).minBy(selector)
106120
}
107121

108122
/**
109123
* Return the average value of the given column or expression of all the records, null if there are no records.
110124
*/
125+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
111126
public inline fun <E : Any, T : BaseTable<E>> T.averageBy(selector: (T) -> ColumnDeclaring<out Number>): Double? {
112127
return Database.global.sequenceOf(this).averageBy(selector)
113128
}

ktorm-global/src/main/kotlin/org/ktorm/global/Dml.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION")
18+
1719
package org.ktorm.global
1820

1921
import org.ktorm.database.Database
@@ -41,6 +43,7 @@ import java.sql.Statement
4143
* @param block the DSL block, an extension function of [UpdateStatementBuilder], used to construct the expression.
4244
* @return the effected row count.
4345
*/
46+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4447
public fun <T : BaseTable<*>> T.update(block: UpdateStatementBuilder.(T) -> Unit): Int {
4548
return Database.global.update(this, block)
4649
}
@@ -70,6 +73,7 @@ public fun <T : BaseTable<*>> T.update(block: UpdateStatementBuilder.(T) -> Unit
7073
* @param block the DSL block, extension function of [BatchUpdateStatementBuilder], used to construct the expressions.
7174
* @return the effected row counts for each sub-operation.
7275
*/
76+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
7377
public fun <T : BaseTable<*>> T.batchUpdate(block: BatchUpdateStatementBuilder<T>.() -> Unit): IntArray {
7478
return Database.global.batchUpdate(this, block)
7579
}
@@ -93,6 +97,7 @@ public fun <T : BaseTable<*>> T.batchUpdate(block: BatchUpdateStatementBuilder<T
9397
* @param block the DSL block, an extension function of [AssignmentsBuilder], used to construct the expression.
9498
* @return the effected row count.
9599
*/
100+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
96101
public fun <T : BaseTable<*>> T.insert(block: AssignmentsBuilder.(T) -> Unit): Int {
97102
return Database.global.insert(this, block)
98103
}
@@ -130,6 +135,7 @@ public fun <T : BaseTable<*>> T.insert(block: AssignmentsBuilder.(T) -> Unit): I
130135
* @param block the DSL block, extension function of [BatchInsertStatementBuilder], used to construct the expressions.
131136
* @return the effected row counts for each sub-operation.
132137
*/
138+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
133139
public fun <T : BaseTable<*>> T.batchInsert(block: BatchInsertStatementBuilder<T>.() -> Unit): IntArray {
134140
return Database.global.batchInsert(this, block)
135141
}
@@ -156,20 +162,23 @@ public fun <T : BaseTable<*>> T.batchInsert(block: BatchInsertStatementBuilder<T
156162
* @param block the DSL block, an extension function of [AssignmentsBuilder], used to construct the expression.
157163
* @return the first auto-generated key.
158164
*/
165+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
159166
public fun <T : BaseTable<*>> T.insertAndGenerateKey(block: AssignmentsBuilder.(T) -> Unit): Any {
160167
return Database.global.insertAndGenerateKey(this, block)
161168
}
162169

163170
/**
164171
* Delete the records in the table that matches the given [predicate].
165172
*/
173+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
166174
public fun <T : BaseTable<*>> T.delete(predicate: (T) -> ColumnDeclaring<Boolean>): Int {
167175
return Database.global.delete(this, predicate)
168176
}
169177

170178
/**
171179
* Delete all the records in the table.
172180
*/
181+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
173182
public fun BaseTable<*>.deleteAll(): Int {
174183
return Database.global.deleteAll(this)
175184
}

ktorm-global/src/main/kotlin/org/ktorm/global/EntitySequence.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION")
18+
1719
package org.ktorm.global
1820

1921
import org.ktorm.database.Database
@@ -25,6 +27,7 @@ import org.ktorm.schema.Table
2527
/**
2628
* Create an [EntitySequence] from this table.
2729
*/
30+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
2831
public fun <E : Any, T : BaseTable<E>> T.asSequence(withReferences: Boolean = true): EntitySequence<E, T> {
2932
return Database.global.sequenceOf(this, withReferences)
3033
}
@@ -43,6 +46,7 @@ public fun <E : Any, T : BaseTable<E>> T.asSequence(withReferences: Boolean = tr
4346
* @see Entity.flushChanges
4447
* @see Entity.delete
4548
*/
49+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4650
public fun <E : Entity<E>> Table<E>.addEntity(entity: E): Int {
4751
return Database.global.sequenceOf(this).add(entity)
4852
}
@@ -56,27 +60,31 @@ public fun <E : Entity<E>> Table<E>.addEntity(entity: E): Int {
5660
* @see Entity.delete
5761
* @since 3.1.0
5862
*/
63+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
5964
public fun <E : Entity<E>> Table<E>.updateEntity(entity: E): Int {
6065
return Database.global.sequenceOf(this).update(entity)
6166
}
6267

6368
/**
6469
* Obtain a entity object matching the given [predicate], auto left joining all the reference tables.
6570
*/
71+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
6672
public inline fun <E : Any, T : BaseTable<E>> T.findOne(predicate: (T) -> ColumnDeclaring<Boolean>): E? {
6773
return Database.global.sequenceOf(this).find(predicate)
6874
}
6975

7076
/**
7177
* Obtain all the entity objects from this table, auto left joining all the reference tables.
7278
*/
79+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
7380
public fun <E : Any> BaseTable<E>.findAll(): List<E> {
7481
return Database.global.sequenceOf(this).toList()
7582
}
7683

7784
/**
7885
* Obtain a list of entity objects matching the given [predicate], auto left joining all the reference tables.
7986
*/
87+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
8088
public inline fun <E : Any, T : BaseTable<E>> T.findList(predicate: (T) -> ColumnDeclaring<Boolean>): List<E> {
8189
return Database.global.sequenceOf(this).filter(predicate).toList()
8290
}

ktorm-global/src/main/kotlin/org/ktorm/global/Global.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DEPRECATION")
18+
1719
package org.ktorm.global
1820

1921
import org.ktorm.database.*
@@ -48,6 +50,7 @@ internal val threadLocal: ThreadLocal<Database> = ThreadLocal()
4850
*
4951
* @see Database.invoke
5052
*/
53+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
5154
public val Database.Companion.global: Database get() {
5255
val database = threadLocal.get() ?: lastConnected.get()
5356
return database ?: error("Not connected to any database yet, please connect to one via Database.connectGlobally")
@@ -64,6 +67,7 @@ public val Database.Companion.global: Database get() {
6467
* @param connector the connector function used to obtain SQL connections.
6568
* @return the new-created database object.
6669
*/
70+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
6771
public fun Database.Companion.connectGlobally(
6872
dialect: SqlDialect = detectDialectImplementation(),
6973
logger: Logger = detectLoggerImplementation(),
@@ -93,6 +97,7 @@ public fun Database.Companion.connectGlobally(
9397
* @param generateSqlInUpperCase whether we need to output the generated SQLs in upper case.
9498
* @return the new-created database object.
9599
*/
100+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
96101
public fun Database.Companion.connectGlobally(
97102
dataSource: DataSource,
98103
dialect: SqlDialect = detectDialectImplementation(),
@@ -126,6 +131,7 @@ public fun Database.Companion.connectGlobally(
126131
* @param generateSqlInUpperCase whether we need to output the generated SQLs in upper case.
127132
* @return the new-created database object.
128133
*/
134+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
129135
public fun Database.Companion.connectGlobally(
130136
url: String,
131137
driver: String? = null,
@@ -170,6 +176,7 @@ public fun Database.Companion.connectGlobally(
170176
* @param generateSqlInUpperCase whether we need to output the generated SQLs in upper case.
171177
* @return the new-created database object.
172178
*/
179+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
173180
public fun Database.Companion.connectWithSpringSupportGlobally(
174181
dataSource: DataSource,
175182
dialect: SqlDialect = detectDialectImplementation(),
@@ -202,6 +209,7 @@ public fun Database.Companion.connectWithSpringSupportGlobally(
202209
*
203210
* @see Database.Companion.global
204211
*/
212+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
205213
public inline operator fun <T> Database.invoke(func: Database.() -> T): T {
206214
// Contracts are not allowed for operator functions?
207215
// contract {
@@ -230,6 +238,7 @@ public inline operator fun <T> Database.invoke(func: Database.() -> T): T {
230238
* @see Database.useConnection
231239
*/
232240
@OptIn(ExperimentalContracts::class)
241+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
233242
public inline fun <T> useConnection(func: (Connection) -> T): T {
234243
contract {
235244
callsInPlace(func, InvocationKind.EXACTLY_ONCE)
@@ -256,6 +265,7 @@ public inline fun <T> useConnection(func: (Connection) -> T): T {
256265
* @see Database.useTransaction
257266
*/
258267
@OptIn(ExperimentalContracts::class)
268+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
259269
public inline fun <T> useTransaction(isolation: TransactionIsolation? = null, func: (Transaction) -> T): T {
260270
contract {
261271
callsInPlace(func, InvocationKind.EXACTLY_ONCE)

ktorm-global/src/main/kotlin/org/ktorm/global/Query.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
18+
1719
package org.ktorm.global
1820

1921
import org.ktorm.database.Database
@@ -24,34 +26,39 @@ import org.ktorm.schema.ColumnDeclaring
2426
/**
2527
* Join the right table and return a new [QuerySource], translated to `cross join` in SQL.
2628
*/
29+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
2730
public fun BaseTable<*>.crossJoin(right: BaseTable<*>, on: ColumnDeclaring<Boolean>? = null): QuerySource {
2831
return Database.global.from(this).crossJoin(right, on)
2932
}
3033

3134
/**
3235
* Join the right table and return a new [QuerySource], translated to `inner join` in SQL.
3336
*/
37+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
3438
public fun BaseTable<*>.innerJoin(right: BaseTable<*>, on: ColumnDeclaring<Boolean>? = null): QuerySource {
3539
return Database.global.from(this).innerJoin(right, on)
3640
}
3741

3842
/**
3943
* Join the right table and return a new [QuerySource], translated to `left join` in SQL.
4044
*/
45+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4146
public fun BaseTable<*>.leftJoin(right: BaseTable<*>, on: ColumnDeclaring<Boolean>? = null): QuerySource {
4247
return Database.global.from(this).leftJoin(right, on)
4348
}
4449

4550
/**
4651
* Join the right table and return a new [QuerySource], translated to `right join` in SQL.
4752
*/
53+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
4854
public fun BaseTable<*>.rightJoin(right: BaseTable<*>, on: ColumnDeclaring<Boolean>? = null): QuerySource {
4955
return Database.global.from(this).rightJoin(right, on)
5056
}
5157

5258
/**
5359
* Return a new-created [Query] object, left joining all the reference tables, and selecting all columns of them.
5460
*/
61+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
5562
public fun BaseTable<*>.joinReferencesAndSelect(): Query {
5663
return Database.global.from(this).joinReferencesAndSelect()
5764
}
@@ -61,6 +68,7 @@ public fun BaseTable<*>.joinReferencesAndSelect(): Query {
6168
*
6269
* Note that the specific columns can be empty, that means `select *` in SQL.
6370
*/
71+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
6472
public fun BaseTable<*>.select(columns: Collection<ColumnDeclaring<*>>): Query {
6573
return Database.global.from(this).select(columns)
6674
}
@@ -70,6 +78,7 @@ public fun BaseTable<*>.select(columns: Collection<ColumnDeclaring<*>>): Query {
7078
*
7179
* Note that the specific columns can be empty, that means `select *` in SQL.
7280
*/
81+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
7382
public fun BaseTable<*>.select(vararg columns: ColumnDeclaring<*>): Query {
7483
return Database.global.from(this).select(*columns)
7584
}
@@ -79,6 +88,7 @@ public fun BaseTable<*>.select(vararg columns: ColumnDeclaring<*>): Query {
7988
*
8089
* Note that the specific columns can be empty, that means `select distinct *` in SQL.
8190
*/
91+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
8292
public fun BaseTable<*>.selectDistinct(columns: Collection<ColumnDeclaring<*>>): Query {
8393
return Database.global.from(this).selectDistinct(columns)
8494
}
@@ -88,6 +98,7 @@ public fun BaseTable<*>.selectDistinct(columns: Collection<ColumnDeclaring<*>>):
8898
*
8999
* Note that the specific columns can be empty, that means `select distinct *` in SQL.
90100
*/
101+
@Deprecated("ktorm-global will be removed in the future, please migrate to the standard API.")
91102
public fun BaseTable<*>.selectDistinct(vararg columns: ColumnDeclaring<*>): Query {
92103
return Database.global.from(this).selectDistinct(*columns)
93104
}

ktorm-global/src/test/kotlin/org/ktorm/global/BaseGlobalTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.ktorm.database.Database
66
/**
77
* Created by vince at Apr 05, 2020.
88
*/
9+
@Suppress("DEPRECATION")
910
open class BaseGlobalTest : BaseTest() {
1011

1112
override fun init() {

0 commit comments

Comments
 (0)