From 56756f8a4c473619125d554ee126a40e46295fc9 Mon Sep 17 00:00:00 2001 From: kuna Date: Wed, 26 Nov 2025 15:56:29 +0900 Subject: [PATCH] Fix maven classpath resolve failure when multiple entry is given When maven classpath is resolved, it is being saved to internal DB cache for reuse. However when multiple entity is given, multiple DB records will be created at one transaction, and it is impossible as it contains auto-incremental ID column. Solution is inserting the records in a batch transaction. --- .../kt/classpath/CachedClassPathResolver.kt | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/shared/src/main/kotlin/org/javacs/kt/classpath/CachedClassPathResolver.kt b/shared/src/main/kotlin/org/javacs/kt/classpath/CachedClassPathResolver.kt index d81667deb..4122d4338 100644 --- a/shared/src/main/kotlin/org/javacs/kt/classpath/CachedClassPathResolver.kt +++ b/shared/src/main/kotlin/org/javacs/kt/classpath/CachedClassPathResolver.kt @@ -7,7 +7,9 @@ import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.SchemaUtils +import org.jetbrains.exposed.sql.batchInsert import org.jetbrains.exposed.sql.deleteAll +import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.transactions.transaction import java.nio.file.Path import java.nio.file.Paths @@ -64,23 +66,28 @@ internal class CachedClassPathResolver( ) }.toSet() } - set(newEntries) = transaction(db) { - ClassPathCacheEntry.deleteAll() - newEntries.map { - ClassPathCacheEntryEntity.new { - compiledJar = it.compiledJar.toString() - sourceJar = it.sourceJar?.toString() + set(newEntries) { + transaction(db) { + ClassPathCacheEntry.deleteAll() + ClassPathCacheEntry.batchInsert(newEntries) { + this[ClassPathCacheEntry.compiledJar] = it.compiledJar.toString() + this[ClassPathCacheEntry.sourceJar] = it.sourceJar?.toString() } } } private var cachedBuildScriptClassPathEntries: Set get() = transaction(db) { BuildScriptClassPathCacheEntryEntity.all().map { Paths.get(it.jar) }.toSet() } - set(newEntries) = transaction(db) { - BuildScriptClassPathCacheEntry.deleteAll() - newEntries.map { BuildScriptClassPathCacheEntryEntity.new { jar = it.toString() } } + set(newEntries) { + transaction(db) { + BuildScriptClassPathCacheEntry.deleteAll() + BuildScriptClassPathCacheEntry.batchInsert(newEntries) { + this[BuildScriptClassPathCacheEntry.jar] = it.toString() + } + } } + private var cachedClassPathMetadata get() = transaction(db) { ClassPathMetadataCacheEntity.all().map { @@ -90,12 +97,14 @@ internal class CachedClassPathResolver( ) }.firstOrNull() } - set(newClassPathMetadata) = transaction(db) { - ClassPathMetadataCache.deleteAll() - val newClassPathMetadataRow = newClassPathMetadata ?: ClasspathMetadata() - ClassPathMetadataCacheEntity.new { - includesSources = newClassPathMetadataRow.includesSources - buildFileVersion = newClassPathMetadataRow.buildFileVersion + set(newClassPathMetadata) { + transaction(db) { + ClassPathMetadataCache.deleteAll() + val newClassPathMetadataRow = newClassPathMetadata ?: ClasspathMetadata() + ClassPathMetadataCache.insert { + it[includesSources] = newClassPathMetadataRow.includesSources + it[buildFileVersion] = newClassPathMetadataRow.buildFileVersion + } } }