From bd93a013977b95dc01ac8439e91cedc3cc7f5669 Mon Sep 17 00:00:00 2001 From: andrii0lomakin Date: Thu, 16 Jan 2025 15:43:09 +0100 Subject: [PATCH] Reimplementation of resetToNew method - second attempt. --- entity-store/build.gradle.kts | 2 +- .../jetbrains/exodus/entitystore/orientdb/OEntityStore.kt | 2 ++ .../exodus/entitystore/orientdb/OPersistentEntityStore.kt | 6 ++++++ .../jetbrains/exodus/entitystore/orientdb/OVertexEntity.kt | 6 ++---- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/entity-store/build.gradle.kts b/entity-store/build.gradle.kts index 01352426c..a55d90302 100644 --- a/entity-store/build.gradle.kts +++ b/entity-store/build.gradle.kts @@ -1,6 +1,6 @@ dependencies { api(project(":xodus-openAPI")) - api("io.youtrackdb:youtrackdb-core:1.0.0-20250110.154816-3") + api("io.youtrackdb:youtrackdb-core:1.0.0-20250116.142259-7") implementation(project(":xodus-utils")) implementation(project(":xodus-environment")) diff --git a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OEntityStore.kt b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OEntityStore.kt index ac4794c9a..80205d05a 100644 --- a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OEntityStore.kt +++ b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OEntityStore.kt @@ -15,10 +15,12 @@ */ package jetbrains.exodus.entitystore.orientdb +import com.jetbrains.youtrack.db.api.DatabaseSession import jetbrains.exodus.entitystore.EntityStore import jetbrains.exodus.entitystore.PersistentEntityId interface OEntityStore : EntityStore { + val databaseSession: DatabaseSession fun requireActiveTransaction(): OStoreTransaction diff --git a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentEntityStore.kt b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentEntityStore.kt index 6d749690f..07d22046d 100644 --- a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentEntityStore.kt +++ b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentEntityStore.kt @@ -29,6 +29,12 @@ class OPersistentEntityStore( private val currentTransaction = ThreadLocal() + override val databaseSession: DatabaseSession + get() { + val tx = currentTransaction.get() ?: throw IllegalStateException("There is no active database session") + return tx.databaseSession + } + override fun close() { //or it should be closed independently currentTransaction.get()?.abort() diff --git a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OVertexEntity.kt b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OVertexEntity.kt index ebd23b4ca..026ece4ef 100644 --- a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OVertexEntity.kt +++ b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OVertexEntity.kt @@ -130,10 +130,8 @@ open class OVertexEntity(vertex: Vertex, private val store: OEntityStore) : OEnt val clusterId = identity.clusterId identity.reset() - vertexRecord = store.requireActiveTransaction().databaseSession.newVertex(oEntityId.getTypeName()) - (vertexRecord as RecordAbstract).also { - (it.identity as RecordId).clusterId = clusterId - } + identity.clusterId = clusterId + vertexRecord = (store.databaseSession as DatabaseSessionInternal).newVertex(identity) } override fun generateId() {