Skip to content

Commit 1e4ab80

Browse files
committed
feat: review issues
1 parent da5a2fe commit 1e4ab80

7 files changed

Lines changed: 33 additions & 29 deletions

File tree

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dependencies {
3838
dokka(projects.exposed.exposedSpringBoot4Starter)
3939
dokka(projects.exposed.springTransaction)
4040
dokka(projects.exposed.spring7Transaction)
41+
dokka(projects.exposed.exposedDaoR2dbc)
4142

4243
// Kover aggregated coverage dependencies
4344
// Include all source modules for coverage aggregation
@@ -58,6 +59,7 @@ dependencies {
5859
kover(project(":exposed-migration-jdbc"))
5960
kover(project(":exposed-migration-r2dbc"))
6061
kover(project(":exposed-r2dbc"))
62+
kover(project(":exposed-dao-r2dbc"))
6163

6264
// Include test modules to ensure their tests are executed and coverage is collected
6365
kover(project(":exposed-tests"))
@@ -91,7 +93,7 @@ allprojects {
9193
}
9294

9395
apiValidation {
94-
ignoredProjects.addAll(listOf("exposed-tests", "exposed-bom", "exposed-r2dbc-tests", "exposed-jdbc-r2dbc-tests", "exposed-dao-r2dbc-tests"))
96+
ignoredProjects.addAll(listOf("exposed-tests", "exposed-bom", "exposed-r2dbc-tests", "exposed-jdbc-r2dbc-tests", "exposed-dao-r2dbc-tests", "exposed-dao-r2dbc"))
9597
}
9698

9799
subprojects {

exposed-dao-r2dbc-tests/src/test/kotlin/org/jetbrains/exposed/dao/r2dbc/tests/shared/R2dbcEntityTests.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package org.jetbrains.exposed.dao.r2dbc.tests.shared
22

3+
import org.jetbrains.exposed.r2dbc.dao.IntR2dbcEntity
4+
import org.jetbrains.exposed.r2dbc.dao.IntR2dbcEntityClass
5+
import org.jetbrains.exposed.r2dbc.dao.LongR2dbcEntity
6+
import org.jetbrains.exposed.r2dbc.dao.LongR2dbcEntityClass
37
import org.jetbrains.exposed.r2dbc.dao.R2dbcEntity
48
import org.jetbrains.exposed.r2dbc.dao.R2dbcEntityClass
5-
import org.jetbrains.exposed.r2dbc.dao.R2dbcIntEntity
6-
import org.jetbrains.exposed.r2dbc.dao.R2dbcIntEntityClass
7-
import org.jetbrains.exposed.r2dbc.dao.R2dbcLongEntity
8-
import org.jetbrains.exposed.r2dbc.dao.R2dbcLongEntityClass
99
import org.jetbrains.exposed.r2dbc.dao.flushCache
1010
import org.jetbrains.exposed.r2dbc.dao.relationships.backReferencedOnSuspend
1111
import org.jetbrains.exposed.r2dbc.dao.relationships.optionalBackReferencedOnSuspend
@@ -55,10 +55,10 @@ object EntityTestsData {
5555
A, B
5656
}
5757

58-
open class AEntity(id: EntityID<Int>) : R2dbcIntEntity(id) {
58+
open class AEntity(id: EntityID<Int>) : IntR2dbcEntity(id) {
5959
var b1 by XTable.b1
6060

61-
companion object : R2dbcIntEntityClass<AEntity>(XTable) {
61+
companion object : IntR2dbcEntityClass<AEntity>(XTable) {
6262
fun create(b1: Boolean, type: XType): AEntity {
6363
val init: AEntity.() -> Unit = {
6464
this.b1 = b1
@@ -76,7 +76,7 @@ object EntityTestsData {
7676
var b2 by XTable.b2
7777
val y by YEntity optionalReferencedOnSuspend XTable.y1
7878

79-
companion object : R2dbcIntEntityClass<BEntity>(XTable) {
79+
companion object : IntR2dbcEntityClass<BEntity>(XTable) {
8080
fun create(init: AEntity.() -> Unit): BEntity {
8181
val answer = new {
8282
init()
@@ -158,14 +158,14 @@ class R2dbcEntityTests : R2dbcDatabaseTestsBase() {
158158
}
159159

160160
internal object OneAutoFieldTable : IntIdTable("single")
161-
internal class SingleFieldEntity(id: EntityID<Int>) : R2dbcIntEntity(id) {
162-
companion object : R2dbcIntEntityClass<SingleFieldEntity>(OneAutoFieldTable)
161+
internal class SingleFieldR2dbcEntity(id: EntityID<Int>) : IntR2dbcEntity(id) {
162+
companion object : IntR2dbcEntityClass<SingleFieldR2dbcEntity>(OneAutoFieldTable)
163163
}
164164

165165
@Test
166166
fun testOneFieldEntity() {
167167
withTables(OneAutoFieldTable) {
168-
val new = SingleFieldEntity.new { }
168+
val new = SingleFieldR2dbcEntity.new { }
169169
commit()
170170
}
171171
}
@@ -208,24 +208,24 @@ class R2dbcEntityTests : R2dbcDatabaseTestsBase() {
208208
val title = varchar("title", 50)
209209
}
210210

211-
class Board(id: EntityID<Int>) : R2dbcIntEntity(id) {
212-
companion object : R2dbcIntEntityClass<Board>(Boards)
211+
class Board(id: EntityID<Int>) : IntR2dbcEntity(id) {
212+
companion object : IntR2dbcEntityClass<Board>(Boards)
213213

214214
var name by Boards.name
215215
val posts by Post optionalReferrersOnSuspend Posts.board
216216
}
217217

218-
class Post(id: EntityID<Long>) : R2dbcLongEntity(id) {
219-
companion object : R2dbcLongEntityClass<Post>(Posts)
218+
class Post(id: EntityID<Long>) : LongR2dbcEntity(id) {
219+
companion object : LongR2dbcEntityClass<Post>(Posts)
220220

221221
val board by Board optionalReferencedOnSuspend Posts.board
222222
val parent by Post optionalReferencedOnSuspend Posts.parent
223223
val category by Category optionalReferencedOnSuspend Posts.category
224224
val optCategory by Category optionalReferencedOnSuspend Posts.optCategory
225225
}
226226

227-
class Category(id: EntityID<Int>) : R2dbcIntEntity(id) {
228-
companion object : R2dbcIntEntityClass<Category>(Categories)
227+
class Category(id: EntityID<Int>) : IntR2dbcEntity(id) {
228+
companion object : IntR2dbcEntityClass<Category>(Categories)
229229

230230
val uniqueId by Categories.uniqueId
231231
var title by Categories.title
@@ -260,14 +260,14 @@ class R2dbcEntityTests : R2dbcDatabaseTestsBase() {
260260
val name = text("name")
261261
}
262262

263-
open class Human(id: EntityID<Int>) : R2dbcIntEntity(id) {
264-
companion object : R2dbcIntEntityClass<Human>(Humans)
263+
open class Human(id: EntityID<Int>) : IntR2dbcEntity(id) {
264+
companion object : IntR2dbcEntityClass<Human>(Humans)
265265

266266
var h by Humans.h
267267
}
268268

269-
class User(id: EntityID<Int>) : R2dbcIntEntity(id) {
270-
companion object : R2dbcIntEntityClass<User>(Users) {
269+
class User(id: EntityID<Int>) : IntR2dbcEntity(id) {
270+
companion object : IntR2dbcEntityClass<User>(Users) {
271271
fun create(name: String): User {
272272
val h = Human.new { h = name.take(2) }
273273
return User.new(h.id.value) {

exposed-dao-r2dbc/src/main/kotlin/org/jetbrains/exposed/r2dbc/dao/IntEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package org.jetbrains.exposed.r2dbc.dao
33
import org.jetbrains.exposed.v1.core.dao.id.EntityID
44
import org.jetbrains.exposed.v1.core.dao.id.IdTable
55

6-
abstract class R2dbcIntEntity(id: EntityID<Int>) : R2dbcEntity<Int>(id)
6+
abstract class IntR2dbcEntity(id: EntityID<Int>) : R2dbcEntity<Int>(id)
77

8-
abstract class R2dbcIntEntityClass<out E : R2dbcIntEntity>(
8+
abstract class IntR2dbcEntityClass<out E : IntR2dbcEntity>(
99
table: IdTable<Int>,
1010
entityType: Class<E>? = null,
1111
entityCtor: ((EntityID<Int>) -> E)? = null

exposed-dao-r2dbc/src/main/kotlin/org/jetbrains/exposed/r2dbc/dao/LongEntity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package org.jetbrains.exposed.r2dbc.dao
33
import org.jetbrains.exposed.v1.core.dao.id.EntityID
44
import org.jetbrains.exposed.v1.core.dao.id.IdTable
55

6-
abstract class R2dbcLongEntity(id: EntityID<Long>) : R2dbcEntity<Long>(id)
6+
abstract class LongR2dbcEntity(id: EntityID<Long>) : R2dbcEntity<Long>(id)
77

8-
abstract class R2dbcLongEntityClass<out E : R2dbcLongEntity>(
8+
abstract class LongR2dbcEntityClass<out E : LongR2dbcEntity>(
99
table: IdTable<Long>,
1010
entityType: Class<E>? = null,
1111
entityCtor: ((EntityID<Long>) -> E)? = null

exposed-dao-r2dbc/src/main/kotlin/org/jetbrains/exposed/r2dbc/dao/R2dbcEntity.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ open class R2dbcEntity<ID : Any>(val id: EntityID<ID>) {
5050
else -> defaultValueFun?.invoke() as T
5151
}
5252
}
53-
else -> _readValues?.get(this) as T
53+
else -> readValues[this]
5454
}
5555

5656
operator fun <T> Column<T>.setValue(entity: R2dbcEntity<ID>, desc: KProperty<*>, value: T) {
@@ -101,7 +101,7 @@ open class R2dbcEntity<ID : Any>(val id: EntityID<ID>) {
101101
return cache.inserts[klass.table]?.contains(this) ?: false
102102
}
103103

104-
private fun storeWrittenValues() {
104+
fun storeWrittenValues() {
105105
// Move write values to read values
106106
if (_readValues != null) {
107107
for ((c, v) in writeValues) {
@@ -119,7 +119,8 @@ open class R2dbcEntity<ID : Any>(val id: EntityID<ID>) {
119119
@Suppress("ForbiddenComment")
120120
open suspend fun flush(batch: R2dbcEntityBatchUpdate? = null): Boolean {
121121
if (isNewEntity()) {
122-
return false
122+
TransactionManager.current().entityCache.flushInserts(klass.table)
123+
return true
123124
}
124125
if (writeValues.isNotEmpty()) {
125126
if (batch == null) {

exposed-dao-r2dbc/src/main/kotlin/org/jetbrains/exposed/r2dbc/dao/R2dbcEntityClass.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ abstract class R2dbcEntityClass<ID : Any, out T : R2dbcEntity<ID>>(
117117

118118
suspend operator fun get(id: ID): T = get(R2dbcDaoEntityID(id, table))
119119

120+
@Suppress("ForbiddenComment")
120121
fun removeFromCache(entity: R2dbcEntity<ID>) {
121122
val cache = warmCache()
122123
cache.remove(table, entity)

exposed-dao-r2dbc/src/main/kotlin/org/jetbrains/exposed/r2dbc/dao/relationships/R2dbcReferrers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class R2dbcReferrers<ParentID : Any, in Parent : R2dbcEntity<ParentID>, ChildID
2424
}
2525
}
2626

27-
@Suppress("NestedBlockDepth")
27+
@Suppress("NestedBlockDepth", "ForbiddenComment")
2828
operator fun getValue(thisRef: Parent, property: KProperty<*>): suspend () -> List<Child> {
2929
// Return a suspend lambda that will load the referrers when invoked
3030
return {

0 commit comments

Comments
 (0)