From d66c963bc977513262c031d750fbd0bb5b5a2b23 Mon Sep 17 00:00:00 2001 From: Leonid Stryuk <=> Date: Mon, 9 Dec 2024 14:41:10 +0100 Subject: [PATCH] #XD-1169 fixed --- .../orientdb/OStoreTransactionImpl.kt | 8 ++++- .../orientdb/OPersistentStoreTest.kt | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OStoreTransactionImpl.kt b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OStoreTransactionImpl.kt index a7ee1b0f5..1b96e4a62 100644 --- a/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OStoreTransactionImpl.kt +++ b/entity-store/src/main/kotlin/jetbrains/exodus/entitystore/orientdb/OStoreTransactionImpl.kt @@ -19,6 +19,7 @@ import com.orientechnologies.common.concur.lock.OModificationOperationProhibited import com.orientechnologies.orient.core.db.ODatabaseSession import com.orientechnologies.orient.core.db.ODatabaseSessionInternal import com.orientechnologies.orient.core.exception.ORecordNotFoundException +import com.orientechnologies.orient.core.id.OEmptyRecordId import com.orientechnologies.orient.core.metadata.schema.OClass import com.orientechnologies.orient.core.metadata.sequence.OSequence import com.orientechnologies.orient.core.record.ORecord @@ -444,7 +445,12 @@ class OStoreTransactionImpl( override fun toEntityId(representation: String): EntityId { requireActiveTransaction() val legacyId = PersistentEntityId.toEntityId(representation) - return store.requireOEntityId(legacyId) + val oEntityId = store.requireOEntityId(legacyId) + return if (oEntityId == ORIDEntityId.EMPTY_ID) { + ORIDEntityId(legacyId.typeId, legacyId.localId, OEmptyRecordId(), null) + } else { + oEntityId + } } override fun getSequence(sequenceName: String): Sequence { diff --git a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentStoreTest.kt b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentStoreTest.kt index 08b7c69cf..8e776355f 100644 --- a/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentStoreTest.kt +++ b/entity-store/src/test/kotlin/jetbrains/exodus/entitystore/orientdb/OPersistentStoreTest.kt @@ -15,6 +15,7 @@ */ package jetbrains.exodus.entitystore.orientdb +import com.orientechnologies.orient.core.id.OEmptyRecordId import com.orientechnologies.orient.core.metadata.schema.OClass import com.orientechnologies.orient.core.metadata.schema.OType import com.orientechnologies.orient.core.storage.ORecordDuplicatedException @@ -193,6 +194,41 @@ class OPersistentStoreTest: OTestMixin { } } + @Test + fun `toEntityId(presentation) from not existent idString will return OEntityId with correct xodus part and empty orient`() { + val issueId = orientDb.createIssue("trista").id + val notExistingEntityId = PersistentEntityId(300, 301) + val partiallyExistingEntityId1 = PersistentEntityId(issueId.typeId, 301) + val partiallyExistingEntityId2 = PersistentEntityId(300, issueId.localId) + val totallyExistingEntityId = PersistentEntityId(issueId.typeId, issueId.localId) + val empty = OEmptyRecordId() + orientDb.store.executeInTransaction { txn-> + with(txn.toEntityId(notExistingEntityId.toString()) as OEntityId){ + assertEquals(notExistingEntityId.localId, localId) + assertEquals(notExistingEntityId.typeId, typeId) + assertEquals(empty.clusterId, asOId().clusterId) + assertEquals(empty.clusterPosition, asOId().clusterPosition) + } + with(txn.toEntityId(partiallyExistingEntityId1.toString()) as OEntityId){ + assertEquals(partiallyExistingEntityId1.localId, localId) + assertEquals(partiallyExistingEntityId1.typeId, typeId) + assertEquals(empty.clusterId, asOId().clusterId) + assertEquals(empty.clusterPosition, asOId().clusterPosition) + } + with(txn.toEntityId(partiallyExistingEntityId2.toString()) as OEntityId){ + assertEquals(partiallyExistingEntityId2.localId, localId) + assertEquals(partiallyExistingEntityId2.typeId, typeId) + assertEquals(empty.clusterId, asOId().clusterId) + assertEquals(empty.clusterPosition, asOId().clusterPosition) + } + with(txn.toEntityId(totallyExistingEntityId.toString()) as OEntityId){ + assertEquals(totallyExistingEntityId.localId, localId) + assertEquals(totallyExistingEntityId.typeId, typeId) + assertEquals(issueId.asOId(), asOId()) + } + } + } + @Test fun `propertyNames does not count internal properties`() { val issue = orientDb.store.computeInTransaction { txn ->