Skip to content

Commit 8f098ff

Browse files
authored
build/qg-xxx: обновлены зависимости проекта (#294)
1. Spring Boot 3.5.6 -> 4.0.3 2. Kotlin 2.2.10 -> 2.3.10 3. Gradle 9.1.0 - 9.3.1
2 parents d074d5b + 1455473 commit 8f098ff

File tree

77 files changed

+409
-312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+409
-312
lines changed

app/build.gradle.kts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ plugins {
1919
group = "pro.qyoga"
2020
version = "0.0.1-SNAPSHOT"
2121

22+
configurations.matching { it.name == "compileClasspath" }.all {
23+
exclude(group = "com.fasterxml.jackson.core", module = "jackson-core")
24+
exclude(group = "com.fasterxml.jackson.core", module = "jackson-databind")
25+
}
26+
27+
configurations.matching { it.name in setOf("testCompileClasspath", "testFixturesCompileClasspath") }.all {
28+
exclude(group = "com.fasterxml.jackson")
29+
exclude(group = "com.fasterxml.jackson.core")
30+
}
31+
2232
dependencies {
2333
implementation(kotlin("reflect"))
2434
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
@@ -29,11 +39,12 @@ dependencies {
2939
implementation("org.springframework.boot:spring-boot-starter-actuator")
3040
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
3141
implementation("org.springframework.boot:spring-boot-starter-cache")
42+
implementation("org.springframework.boot:spring-boot-starter-flyway")
3243
implementation(libs.caffeine)
3344

34-
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
45+
implementation("tools.jackson.module:jackson-module-kotlin")
3546
implementation("org.flywaydb:flyway-database-postgresql")
36-
implementation(libs.jackarta.validation)
47+
implementation("org.springframework.boot:spring-boot-starter-validation")
3748
implementation(libs.thymeleaf.extras.java8time)
3849
implementation(libs.postgres)
3950
implementation(libs.minio)
@@ -49,6 +60,9 @@ dependencies {
4960
implementation(libs.bouncycastle)
5061

5162
developmentOnly("org.springframework.boot:spring-boot-docker-compose")
63+
runtimeOnly(platform("com.fasterxml.jackson:jackson-bom:2.20.2"))
64+
runtimeOnly("com.fasterxml.jackson.core:jackson-core")
65+
runtimeOnly("com.fasterxml.jackson.core:jackson-databind")
5266

5367
testFixturesApi("org.springframework.boot:spring-boot-testcontainers")
5468
testFixturesApi(testLibs.kotest.assertions)
@@ -71,18 +85,22 @@ dependencies {
7185
testFixturesImplementation("org.springframework.boot:spring-boot-starter-web")
7286
testFixturesImplementation("org.springframework.boot:spring-boot-starter-security")
7387
testFixturesImplementation("org.springframework.boot:spring-boot-starter-oauth2-client")
74-
testFixturesImplementation("com.fasterxml.jackson.core:jackson-databind")
88+
testFixturesImplementation(enforcedPlatform(testLibs.jetty))
89+
testFixturesImplementation(enforcedPlatform(testLibs.jetty.ee10))
90+
testFixturesImplementation("tools.jackson.core:jackson-databind")
7591
testFixturesImplementation(libs.minio)
7692
testFixturesImplementation(libs.ical4j)
7793

7894
testFixturesImplementation("org.springframework.boot:spring-boot-starter-test")
7995
testFixturesImplementation("org.springframework.security:spring-security-test")
8096
testFixturesImplementation("org.springframework.boot:spring-boot-starter-webflux")
81-
testFixturesImplementation("org.testcontainers:junit-jupiter")
82-
testFixturesImplementation("org.testcontainers:postgresql")
97+
testFixturesImplementation("org.testcontainers:testcontainers-junit-jupiter")
98+
testFixturesImplementation("org.testcontainers:testcontainers-postgresql")
8399
testFixturesImplementation(testLibs.testcontainers.minio)
84100

85101
testImplementation(testFixtures(project(":app")))
102+
testImplementation(enforcedPlatform(testLibs.jetty))
103+
testImplementation(enforcedPlatform(testLibs.jetty.ee10))
86104
testImplementation(testLibs.bundles.restassured)
87105
testImplementation(testLibs.archunit)
88106
testImplementation(testLibs.mockito.kotlin)
@@ -220,7 +238,7 @@ configurations.matching { it.name == "detekt" }.all {
220238
resolutionStrategy.eachDependency {
221239
if (requested.group == "org.jetbrains.kotlin") {
222240
@Suppress("UnstableApiUsage")
223-
useVersion(io.gitlab.arturbosch.detekt.getSupportedKotlinVersion())
241+
useVersion(dev.detekt.gradle.plugin.getSupportedKotlinVersion())
224242
}
225243
}
226244
}

app/src/main/kotlin/pro/azhidkov/platform/file_storage/internal/FilesMetaDataRepo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package pro.azhidkov.platform.file_storage.internal
22

3+
import org.springframework.data.core.TypeInformation
34
import org.springframework.data.jdbc.core.JdbcAggregateOperations
45
import org.springframework.data.jdbc.core.convert.JdbcConverter
56
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository
67
import org.springframework.data.mapping.model.BasicPersistentEntity
7-
import org.springframework.data.util.TypeInformation
88
import org.springframework.stereotype.Repository
99
import pro.azhidkov.platform.file_storage.api.FileMetaData
1010

app/src/main/kotlin/pro/azhidkov/platform/spring/jdbc/RowMapperExt.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package pro.azhidkov.platform.spring.jdbc
22

3-
import com.fasterxml.jackson.databind.ObjectMapper
43
import org.springframework.core.convert.support.DefaultConversionService
54
import org.springframework.jdbc.core.DataClassRowMapper
65
import org.springframework.jdbc.core.RowMapper
76
import pro.azhidkov.platform.spring.sdj.converters.PGIntervalToDurationConverter
87
import pro.azhidkov.platform.spring.sdj.converters.StringToSecretChars
98
import pro.azhidkov.platform.spring.sdj.converters.UuidToAggregateReferenceConverter
9+
import tools.jackson.databind.ObjectMapper
1010

1111

12-
inline fun <reified T> rowMapperFor(objectMapper: ObjectMapper, columnName: String? = null) = RowMapper<T> { rs, _ ->
12+
inline fun <reified T> rowMapperFor(objectMapper: ObjectMapper, columnName: String? = null) = RowMapper<T?> { rs, _ ->
1313
val json: String? = if (columnName != null) {
1414
rs.getString(columnName)
1515
} else {
@@ -18,10 +18,11 @@ inline fun <reified T> rowMapperFor(objectMapper: ObjectMapper, columnName: Stri
1818
json?.let { objectMapper.readValue(it, T::class.java) }
1919
}
2020

21-
inline fun <reified T> taDataClassRowMapper() = DataClassRowMapper.newInstance(T::class.java).apply {
22-
conversionService = DefaultConversionService().apply {
21+
inline fun <reified T : Any> taDataClassRowMapper(): DataClassRowMapper<T> =
22+
DataClassRowMapper.newInstance(T::class.java).apply {
23+
conversionService = DefaultConversionService().apply {
2324
addConverter(PGIntervalToDurationConverter())
2425
addConverter(UuidToAggregateReferenceConverter)
2526
addConverter(StringToSecretChars())
27+
}
2628
}
27-
}

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/AggregateReferenceDeserializer.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package pro.azhidkov.platform.spring.sdj
22

3-
import com.fasterxml.jackson.core.JsonParser
4-
import com.fasterxml.jackson.databind.*
5-
import com.fasterxml.jackson.databind.deser.ContextualDeserializer
6-
import com.fasterxml.jackson.databind.type.TypeFactory
73
import org.springframework.data.jdbc.core.mapping.AggregateReference
84
import pro.azhidkov.platform.spring.sdj.ergo.hydration.AggregateReferenceTarget
95
import pro.azhidkov.platform.spring.sdj.ergo.hydration.Identifiable
6+
import tools.jackson.core.JsonParser
7+
import tools.jackson.databind.*
8+
import tools.jackson.databind.type.TypeFactory
109
import kotlin.reflect.full.memberProperties
1110
import kotlin.reflect.jvm.jvmErasure
1211

1312

1413
class AggregateReferenceDeserializer(
1514
private var type: JavaType = TypeFactory.unknownType()
16-
) : JsonDeserializer<AggregateReference<*, *>>(), ContextualDeserializer {
15+
) : ValueDeserializer<AggregateReference<*, *>>() {
1716

1817
override fun deserialize(parser: JsonParser, context: DeserializationContext): AggregateReference<*, *>? {
19-
val node = parser.codec.readTree<JsonNode>(parser)
18+
val node = parser.readValueAsTree<JsonNode>()
2019
val propertyNames = node.properties().map { it.key }.toSet()
2120
return if (propertyNames == setOf(ID_FIELD_NAME)) {
2221
val idType = getIdType(type)
@@ -28,7 +27,7 @@ class AggregateReferenceDeserializer(
2827
}
2928
}
3029

31-
override fun createContextual(ctx: DeserializationContext, property: BeanProperty): JsonDeserializer<*> {
30+
override fun createContextual(ctx: DeserializationContext, property: BeanProperty): ValueDeserializer<*> {
3231
return AggregateReferenceDeserializer(property.type.containedType(0))
3332
}
3433

@@ -44,4 +43,4 @@ private fun getIdType(type: JavaType): Class<out Any> =
4443
.first { it.name == AggregateReferenceDeserializer.ID_FIELD_NAME }
4544
.returnType
4645
.jvmErasure
47-
.java
46+
.java
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package pro.azhidkov.platform.spring.sdj
22

3-
import com.fasterxml.jackson.databind.module.SimpleModule
43
import org.springframework.context.annotation.Bean
54
import org.springframework.context.annotation.Configuration
65
import org.springframework.data.jdbc.core.mapping.AggregateReference
7-
import pro.azhidkov.platform.spring.sdj.ergo.ErgoPersistenceExceptionTranslator
8-
import com.fasterxml.jackson.databind.Module as JacksonModule
6+
import tools.jackson.databind.JacksonModule
7+
import tools.jackson.databind.module.SimpleModule
98

109

1110
@Configuration
@@ -21,8 +20,4 @@ class ErgoSdjConfig {
2120
fun aggregateReferenceBindingAdvice() =
2221
AggregateReferenceBindingAdvice()
2322

24-
@Bean
25-
fun persistenceExceptionTranslator() =
26-
ErgoPersistenceExceptionTranslator()
27-
28-
}
23+
}

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/PageExt.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import org.springframework.data.domain.Page
44
import org.springframework.data.domain.PageImpl
55
import org.springframework.data.domain.PageRequest
66

7-
fun <T, R> Page<T>.mapContent(f: (MutableList<T>) -> List<R>): Page<R> {
7+
fun <T : Any, R : Any> Page<T>.mapContent(f: (List<T>) -> List<R>): Page<R> {
88
return PageImpl(f(this.content), PageRequest.of(this.number, this.size), this.totalElements)
99
}

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/converters/ObjectToJsonbConverters.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package pro.azhidkov.platform.spring.sdj.converters
22

3-
import com.fasterxml.jackson.databind.ObjectMapper
43
import org.postgresql.util.PGobject
54
import org.springframework.core.convert.converter.Converter
65
import org.springframework.data.convert.ReadingConverter
76
import org.springframework.data.convert.WritingConverter
7+
import tools.jackson.databind.ObjectMapper
88
import kotlin.reflect.KClass
99

1010

1111
@WritingConverter
1212
fun interface ObjectToJsonbWriter<T : Any> : Converter<T, PGobject>
1313

1414
@ReadingConverter
15-
fun interface JsonbToObjectReader<T : Any> : Converter<PGobject, T>
15+
fun interface JsonbToObjectReader<T> : Converter<PGobject, T?>
1616

1717
abstract class JacksonObjectToJsonbWriter<T : Any>(
1818
private val objectMapper: ObjectMapper

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/ergo/ErgoPersistenceExceptionTranslator.kt

Lines changed: 0 additions & 15 deletions
This file was deleted.

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/ergo/ErgoRepository.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import org.springframework.data.jdbc.core.JdbcAggregateOperations
66
import org.springframework.data.jdbc.core.convert.EntityRowMapper
77
import org.springframework.data.jdbc.core.convert.JdbcConverter
88
import org.springframework.data.jdbc.repository.support.SimpleJdbcRepository
9-
import org.springframework.data.relational.core.conversion.DbActionExecutionException
109
import org.springframework.data.relational.core.mapping.RelationalMappingContext
1110
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity
1211
import org.springframework.data.relational.core.query.Query
@@ -48,7 +47,7 @@ class ErgoRepository<T : Any, ID : Any>(
4847

4948
protected fun <S : T> saveAndMapDuplicatedKeyException(aggregate: T, map: (DuplicateKeyException) -> Throwable): S {
5049
val res = runCatching { super.save(aggregate) }
51-
when (val ex = (res.exceptionOrNull() as? DbActionExecutionException)?.cause as? DuplicateKeyException) {
50+
when (val ex = res.exceptionOrNull() as? DuplicateKeyException) {
5251
is DuplicateKeyException -> throw map(ex)
5352
}
5453

@@ -162,13 +161,19 @@ class ErgoRepository<T : Any, ID : Any>(
162161
queryBuilder: QueryBuilder.() -> Unit = {}
163162
): Page<T> {
164163
val query = query(queryBuilder)
165-
val res = jdbcAggregateTemplate.findAll(query, relationalPersistentEntity.type, pageRequest)
166-
return res.mapContent {
167-
jdbcAggregateTemplate.hydrate(
168-
res,
169-
FetchSpec(fetch)
170-
)
171-
}
164+
165+
val content = jdbcAggregateTemplate.findAll(query.with(pageRequest), relationalPersistentEntity.type)
166+
.let { jdbcAggregateTemplate.hydrate(it, FetchSpec(fetch)) }
167+
168+
val total = jdbcAggregateTemplate.count(query, relationalPersistentEntity.type)
169+
170+
val page = PageImpl(
171+
content,
172+
pageRequest,
173+
total
174+
)
175+
176+
return page
172177
}
173178

174179
fun findSlice(
@@ -263,4 +268,4 @@ class ErgoRepository<T : Any, ID : Any>(
263268
@Suppress("UNCHECKED_CAST")
264269
private fun <T : Any> RelationalMappingContext.getRelationPersistentEntity(
265270
type: KClass<T>
266-
): RelationalPersistentEntity<T> = getRequiredPersistentEntity(type.java) as RelationalPersistentEntity<T>
271+
): RelationalPersistentEntity<T> = getRequiredPersistentEntity(type.java) as RelationalPersistentEntity<T>

app/src/main/kotlin/pro/azhidkov/platform/spring/sdj/ergo/hydration/Hydration.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.reflect.jvm.jvmErasure
1111

1212
data class PropertyFetchSpec<T : Any?, V>(
1313
val property: KProperty1<T, V?>,
14-
val fetchSpec: FetchSpec<*> = FetchSpec(
14+
val fetchSpec: FetchSpec<out Any> = FetchSpec(
1515
emptyList<PropertyFetchSpec<Any, Any>>()
1616
)
1717
)
@@ -42,15 +42,14 @@ fun <T : Any> JdbcAggregateOperations.hydrate(
4242
return (entities as? List<T>) ?: entities.toList()
4343
}
4444

45-
val refs: Map<KProperty1<*, AggregateReference<*, *>?>, Map<Any, Any>> =
45+
val refs: Map<KProperty1<*, *>, Map<Any, Any>> =
4646
fetchSpec.propertyFetchSpecs.filter {
4747
detectRefType(
4848
it.property
4949
) != null
5050
}
5151
.associate { it: PropertyFetchSpec<T, *> ->
52-
val property = it.property as KProperty1<*, AggregateReference<*, *>?>
53-
property to fetchPropertyRefs(entities, it)
52+
it.property to fetchPropertyRefs(entities, it)
5453
}
5554

5655
if (refs.isEmpty()) {
@@ -69,11 +68,19 @@ private fun <T : Any> JdbcAggregateOperations.fetchPropertyRefs(
6968
val property = propertyFetchSpec.property
7069
val ids = fetchIds(entities, property)
7170
val targetType = (property.returnType.arguments[0].type!!.classifier!! as KClass<*>).java
72-
val refs = hydrate(this.findAllById(ids, targetType), propertyFetchSpec.fetchSpec as FetchSpec<Any>)
71+
val refs = hydrateAny(this.findAllById(ids, targetType), propertyFetchSpec.fetchSpec)
7372
.associateBy { (it as Identifiable<*>).id }
7473
return refs
7574
}
7675

76+
@Suppress("UNCHECKED_CAST")
77+
private fun JdbcAggregateOperations.hydrateAny(
78+
entities: Iterable<*>,
79+
fetchSpec: FetchSpec<out Any>
80+
): List<Any> {
81+
return hydrate(entities as Iterable<Any>, fetchSpec as FetchSpec<Any>)
82+
}
83+
7784
private fun <T : Any> fetchIds(
7885
entities: Iterable<T>,
7986
property: KProperty1<T, Any?>
@@ -87,12 +94,12 @@ private fun <T : Any> fetchIds(
8794
else -> error("Unsupported property type: $property")
8895
}
8996

90-
private fun <T : Any> hydrateEntity(entity: T, refs: Map<KProperty1<*, AggregateReference<*, *>?>, Map<Any, Any>>): T {
97+
private fun <T : Any> hydrateEntity(entity: T, refs: Map<KProperty1<*, *>, Map<Any, Any>>): T {
9198
val constructorParams = entity::class.primaryConstructor!!.parameters
9299
val paramValues = constructorParams.associateWith { param ->
93100
val prop =
94-
entity::class.memberProperties.find { prop -> param.name == prop.name }!! as KProperty1<T, AggregateReference<*, *>?>
95-
val currentValue: Any? = prop.invoke(entity)
101+
entity::class.memberProperties.find { prop -> param.name == prop.name }!!
102+
val currentValue = prop.getter.call(entity)
96103
val newValue = if (prop in refs) {
97104
val id = (currentValue as AggregateReference<*, *>?)?.id
98105
if (id != null) {

0 commit comments

Comments
 (0)