-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from JetBrains/adopt-orientdb-old-links
Adopt orientdb old links
- Loading branch information
Showing
11 changed files
with
199 additions
and
98 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...en-api/src/main/kotlin/jetbrains/exodus/database/TransientEntityOriginalValuesProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* 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 jetbrains.exodus.entitystore.Entity | ||
import java.io.InputStream | ||
|
||
interface TransientEntityOriginalValuesProvider { | ||
fun getOriginalPropertyValue(e: TransientEntity, propertyName: String): Comparable<*>? | ||
fun getOriginalBlobStringValue(e: TransientEntity, blobName: String): String? | ||
fun getOriginalBlobValue(e: TransientEntity, blobName: String): InputStream? | ||
fun getOriginalLinkValue(e: TransientEntity, linkName: String): Entity? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...in/kotlin/com/jetbrains/teamsys/dnq/database/TransientEntityOriginalValuesProviderImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/** | ||
* 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 com.orientechnologies.orient.core.db.ODatabaseSession | ||
import com.orientechnologies.orient.core.record.OVertex | ||
import com.orientechnologies.orient.core.record.impl.ORecordBytes | ||
import jetbrains.exodus.database.LinkChangeType | ||
import jetbrains.exodus.database.TransientEntity | ||
import jetbrains.exodus.database.TransientEntityOriginalValuesProvider | ||
import jetbrains.exodus.database.TransientStoreSession | ||
import jetbrains.exodus.entitystore.Entity | ||
import jetbrains.exodus.entitystore.orientdb.OComparableSet | ||
import jetbrains.exodus.util.UTFUtil | ||
import java.io.ByteArrayInputStream | ||
import java.io.InputStream | ||
|
||
class TransientEntityOriginalValuesProviderImpl(private val session: TransientStoreSession) : TransientEntityOriginalValuesProvider { | ||
private val transientChangesTracker get() = session.transientChangesTracker | ||
|
||
override fun getOriginalPropertyValue(e: TransientEntity, propertyName: String): Comparable<*>? { | ||
val session = ODatabaseSession.getActiveSession() | ||
val id = e.entity.id.asOId() | ||
val oVertex = session.load<OVertex>(id) | ||
val onLoadValue = oVertex.getPropertyOnLoadValue<Any>(propertyName) | ||
return if (onLoadValue is MutableSet<*>) { | ||
OComparableSet(onLoadValue) | ||
} else { | ||
onLoadValue as Comparable<*>? | ||
} | ||
} | ||
|
||
override fun getOriginalBlobStringValue(e: TransientEntity, blobName: String): String? { | ||
val session = ODatabaseSession.getActiveSession() | ||
val id = e.entity.id.asOId() | ||
val oVertex = session.load<OVertex>(id) | ||
val blobHolder = oVertex.getPropertyOnLoadValue<ORecordBytes?>(blobName) | ||
return blobHolder?.toStream()?.let { | ||
UTFUtil.readUTF((it).inputStream()) | ||
} | ||
} | ||
|
||
override fun getOriginalBlobValue(e: TransientEntity, blobName: String): InputStream? { | ||
val session = ODatabaseSession.getActiveSession() | ||
val id = e.entity.id.asOId() | ||
val oVertex = session.load<OVertex>(id) | ||
val blobHolder = oVertex.getPropertyOnLoadValue<ORecordBytes?>(blobName) | ||
return blobHolder?.let { | ||
ByteArrayInputStream(blobHolder.toStream()) | ||
} | ||
} | ||
|
||
override fun getOriginalLinkValue(e: TransientEntity, linkName: String): Entity? { | ||
// get from saved changes, if not - from db | ||
val change = transientChangesTracker.getChangedLinksDetailed(e)?.get(linkName) | ||
if (change != null) { | ||
when (change.changeType) { | ||
LinkChangeType.ADD_AND_REMOVE, | ||
LinkChangeType.REMOVE -> { | ||
return if (change.removedEntitiesSize != 1) { | ||
if (change.deletedEntitiesSize == 1) { | ||
change.deletedEntities!!.iterator().next() | ||
} else { | ||
throw IllegalStateException("Can't determine original link value: ${e.type}.$linkName") | ||
} | ||
} else { | ||
change.removedEntities!!.iterator().next() | ||
} | ||
} | ||
|
||
else -> | ||
throw IllegalStateException("Incorrect change type for link that is part of index: ${e.type}.$linkName: ${change.changeType.getName()}") | ||
} | ||
} | ||
return e.entity.getLink(linkName) | ||
} | ||
|
||
} |
Oops, something went wrong.