Skip to content

Commit

Permalink
Merge pull request #239 from JetBrains/ytdb-226-entity-renew
Browse files Browse the repository at this point in the history
Reimplementation of resetToNew method.
  • Loading branch information
andrii0lomakin authored Jan 16, 2025
2 parents 5877618 + f87704b commit d94f142
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package jetbrains.exodus.entitystore.orientdb

import com.jetbrains.youtrack.db.api.DatabaseSession
import com.jetbrains.youtrack.db.api.query.ResultSet
import com.jetbrains.youtrack.db.api.record.DBRecord
import com.jetbrains.youtrack.db.api.record.Vertex
Expand All @@ -24,12 +25,12 @@ import jetbrains.exodus.entitystore.PersistentEntityId
import jetbrains.exodus.entitystore.StoreTransaction

interface OStoreTransaction : StoreTransaction {
val databaseSession: DatabaseSession

fun getOEntityStore(): OEntityStore

fun getTransactionId(): Long


fun requireActiveTransaction()

fun requireActiveWritableTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import jetbrains.exodus.env.ReadonlyTransactionException
internal typealias TransactionEventHandler = (DatabaseSession, OStoreTransaction) -> Unit

class OStoreTransactionImpl(
val session: DatabaseSession,
private val session: DatabaseSession,
private val store: OPersistentEntityStore,
private val schemaBuddy: OSchemaBuddy,
private val onFinished: TransactionEventHandler,
Expand Down Expand Up @@ -101,6 +101,9 @@ class OStoreTransactionImpl(
return !isFinished && session.isActiveOnCurrentThread
}

override val databaseSession: DatabaseSession
get() = session

override fun getOEntityStore(): OEntityStore {
return store
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ open class OVertexEntity(vertex: Vertex, private val store: OEntityStore) : OEnt
}

override fun resetToNew() {
val clusterId = vertexRecord.identity.clusterId
val identity = vertexRecord.identity as RecordId
val clusterId = identity.clusterId
identity.reset()

(vertexRecord.identity as RecordId).reset()
vertexRecord = store.requireActiveTransaction().databaseSession.newVertex(oEntityId.getTypeName())
(vertexRecord as RecordAbstract).also {
it.resetToNew()
(it.identity as RecordId).clusterId = clusterId
}
}

override fun generateId() {
val type = oEntityId.getTypeName()
vertexRecord = store.currentTransaction!!.asOStoreTransaction().bindToSession(vertexRecord)
store.requireActiveTransaction().generateEntityId(type, vertexRecord)
oEntityId = ORIDEntityId.fromVertex(vertexRecord)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ class OStoreTransactionLifecycleTest : OTestMixin {
val tx = beginTransaction()


val trista1 = tx.session.newVertex("trista")
val trista1 = tx.databaseSession.newVertex("trista")
trista1.setProperty("name", "dvesti")
trista1.save()
val trista2 = tx.session.newVertex("trista")
val trista2 = tx.databaseSession.newVertex("trista")
trista2.setProperty("name", "dvesti")
trista2.save()

Expand Down

0 comments on commit d94f142

Please sign in to comment.