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

Moved entity modification operations to different class #90

Merged
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
@@ -0,0 +1,82 @@
/**
* Copyright 2006 - 2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package jetbrains.exodus.database

import java.io.File
import java.io.InputStream

interface TransientEntitiesUpdater {

fun addChild(
parent: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String,
child: TransientEntity
)

fun setBlob(transientEntity: TransientEntity, blobName: String, stream: InputStream)

fun setBlob(transientEntity: TransientEntity, blobName: String, file: File)

fun deleteProperty(transientEntity: TransientEntity, propertyName: String): Boolean

fun setBlobString(transientEntity: TransientEntity, blobName: String, newValue: String): Boolean
fun deleteBlob(transientEntity: TransientEntity, blobName: String): Boolean
fun setLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean
fun addLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean
fun deleteLinks(source: TransientEntity, linkName: String)
fun deleteEntity(transientEntity: TransientEntity): Boolean
fun deleteLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean
fun setProperty(transientEntity: TransientEntity, propertyName: String, propertyNewValue: Comparable<*>): Boolean
fun setToOne(source: TransientEntity, linkName: String, target: TransientEntity?)
fun setManyToOne(many: TransientEntity, manyToOneLinkName: String, oneToManyLinkName: String, one: TransientEntity?)
fun clearOneToMany(one: TransientEntity, manyToOneLinkName: String, oneToManyLinkName: String)
fun createManyToMany(e1: TransientEntity, e1Toe2LinkName: String, e2Toe1LinkName: String, e2: TransientEntity)
fun clearManyToMany(e1: TransientEntity, e1Toe2LinkName: String, e2Toe1LinkName: String)
fun setOneToOne(
e1: TransientEntity,
e1Toe2LinkName: String,
e2Toe1LinkName: String,
e2: TransientEntity?
)

fun removeOneToMany(
one: TransientEntity,
manyToOneLinkName: String,
oneToManyLinkName: String,
many: TransientEntity
)

fun removeFromParent(child: TransientEntity, parentToChildLinkName: String, childToParentLinkName: String)
fun removeChild(
parent: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String
)

fun setChild(
parent: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String,
child: TransientEntity
)

fun clearChildren(parent: TransientEntity, parentToChildLinkName: String)
fun hasChanges(): Boolean
fun clear()
fun apply()
fun addChange(change: () -> Boolean): () -> Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ package jetbrains.exodus.database
import jetbrains.exodus.entitystore.Entity
import jetbrains.exodus.entitystore.EntityIterable
import jetbrains.exodus.entitystore.StoreTransaction
import jetbrains.exodus.entitystore.orientdb.OStoreTransaction

//TODO: rename to TransientStoreTransaction
interface TransientStoreSession : StoreTransaction {

val oStoreTransaction: OStoreTransaction
val transactionInternal: StoreTransaction

val transientChangesTracker: TransientChangesTracker

val entitiesUpdater: TransientEntitiesUpdater

/**
* True if the session is opened
*/
Expand Down Expand Up @@ -78,4 +79,6 @@ interface TransientStoreSession : StoreTransaction {
fun quietIntermediateCommit()

fun setUpgradeHook(hook: Runnable?)


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,29 @@
*/
package com.jetbrains.teamsys.dnq.database

import jetbrains.exodus.database.EntityCreator
import jetbrains.exodus.database.TransientChangesTracker
import jetbrains.exodus.database.TransientEntity
import jetbrains.exodus.database.TransientStoreSession
import jetbrains.exodus.database.*
import jetbrains.exodus.entitystore.*
import jetbrains.exodus.entitystore.orientdb.OStoreTransaction
import jetbrains.exodus.entitystore.orientdb.OVertexEntity
import jetbrains.exodus.env.Transaction

class ReadOnlyTransientSession(
private val store: TransientEntityStoreImpl,
override val oStoreTransaction: OStoreTransaction) : TransientStoreSession, SessionQueryMixin {

override val transactionInternal: StoreTransaction
get() = oStoreTransaction
override val transactionInternal: OStoreTransaction) : TransientStoreSession, SessionQueryMixin {

override val transientChangesTracker: TransientChangesTracker
get() = ReadOnlyTransientChangesTrackerImpl()

override val isOpened: Boolean
get() = !oStoreTransaction.isFinished
get() = !transactionInternal.isFinished

override val isCommitted: Boolean
get() = oStoreTransaction.isFinished
get() = transactionInternal.isFinished

override val isAborted: Boolean
get() = oStoreTransaction.isFinished
get() = transactionInternal.isFinished

override fun isFinished() = oStoreTransaction.isFinished
override fun isFinished() = transactionInternal.isFinished

override fun getStore() = store

Expand All @@ -62,7 +56,7 @@ class ReadOnlyTransientSession(
valueGetter: ComparableGetter,
comparator: Comparator<Comparable<Any>>
): EntityIterable {
return oStoreTransaction.mergeSorted(sorted, valueGetter, comparator)
return transactionInternal.mergeSorted(sorted, valueGetter, comparator)
}

override fun newEntity(entityType: String) = throw UnsupportedOperationException()
Expand All @@ -88,7 +82,7 @@ class ReadOnlyTransientSession(

override fun isReadonly() = true

override fun getSnapshot() = oStoreTransaction
override fun getSnapshot() = transactionInternal

override fun isRemoved(entity: Entity) = false

Expand All @@ -105,7 +99,7 @@ class ReadOnlyTransientSession(
}

override fun isCurrent(): Boolean {
return oStoreTransaction.isCurrent
return transactionInternal.isCurrent
}

override fun abort() {
Expand All @@ -117,7 +111,7 @@ class ReadOnlyTransientSession(
}

override fun findWithPropSortedByValue(entityType: String, propertyName: String): EntityIterable {
return oStoreTransaction.findWithPropSortedByValue(entityType, propertyName)
return transactionInternal.findWithPropSortedByValue(entityType, propertyName)
}

override fun toEntityId(representation: String): EntityId {
Expand All @@ -139,6 +133,11 @@ class ReadOnlyTransientSession(
override fun getQueryCancellingPolicy(): QueryCancellingPolicy? = transactionInternal.queryCancellingPolicy

override fun getEnvironmentTransaction(): Transaction {
return oStoreTransaction.environmentTransaction
return transactionInternal.environmentTransaction
}

override val entitiesUpdater = ReadonlyTransientEntitiesUpdater()

}


Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/**
* Copyright 2006 - 2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.teamsys.dnq.database

import jetbrains.exodus.database.TransientEntitiesUpdater
import jetbrains.exodus.database.TransientEntity
import java.io.File
import java.io.InputStream

class ReadonlyTransientEntitiesUpdater : TransientEntitiesUpdater {

fun invalidState() {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun addChild(
parent: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String,
child: TransientEntity
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setBlob(transientEntity: TransientEntity, blobName: String, stream: InputStream) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setBlob(transientEntity: TransientEntity, blobName: String, file: File) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setBlobString(transientEntity: TransientEntity, blobName: String, newValue: String): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun deleteBlob(transientEntity: TransientEntity, blobName: String): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun addLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun deleteLinks(source: TransientEntity, linkName: String) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun deleteEntity(transientEntity: TransientEntity): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun deleteLink(source: TransientEntity, linkName: String, target: TransientEntity): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setProperty(
transientEntity: TransientEntity,
propertyName: String,
propertyNewValue: Comparable<*>
): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setToOne(source: TransientEntity, linkName: String, target: TransientEntity?) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setManyToOne(
many: TransientEntity,
manyToOneLinkName: String,
oneToManyLinkName: String,
one: TransientEntity?
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun clearOneToMany(one: TransientEntity, manyToOneLinkName: String, oneToManyLinkName: String) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun createManyToMany(
e1: TransientEntity,
e1Toe2LinkName: String,
e2Toe1LinkName: String,
e2: TransientEntity
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun clearManyToMany(e1: TransientEntity, e1Toe2LinkName: String, e2Toe1LinkName: String) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setOneToOne(
e1: TransientEntity,
e1Toe2LinkName: String,
e2Toe1LinkName: String,
e2: TransientEntity?
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun removeOneToMany(
one: TransientEntity,
manyToOneLinkName: String,
oneToManyLinkName: String,
many: TransientEntity
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun removeFromParent(
child: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun removeChild(parent: TransientEntity, parentToChildLinkName: String, childToParentLinkName: String) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun setChild(
parent: TransientEntity,
parentToChildLinkName: String,
childToParentLinkName: String,
child: TransientEntity
) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun clearChildren(parent: TransientEntity, parentToChildLinkName: String) {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}

override fun deleteProperty(transientEntity: TransientEntity, propertyName: String): Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}


override fun hasChanges() = false

override fun clear() {

}

override fun apply() {

}

override fun addChange(change: () -> Boolean): () -> Boolean {
throw IllegalStateException("Readonly transaction cannot perform write operations")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import jetbrains.exodus.entitystore.EntityIterable
import jetbrains.exodus.entitystore.StoreTransaction

internal interface SessionQueryMixin : TransientStoreSession {
val transactionInternal: StoreTransaction

fun wrap(action: String, entityIterable: EntityIterable): EntityIterable

Expand Down
Loading
Loading