Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplementation of resetToNew method. #239

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading