Skip to content

Commit

Permalink
Merge pull request #155 from JetBrains/graph-store-string-blob-fix
Browse files Browse the repository at this point in the history
#XD-1048 fixed
  • Loading branch information
laa committed May 13, 2024
2 parents 921101a + f4f4556 commit dfefa93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import jetbrains.exodus.entitystore.PersistentEntityStore
import jetbrains.exodus.entitystore.orientdb.OVertexEntity.Companion.CLASS_ID_CUSTOM_PROPERTY_NAME
import jetbrains.exodus.entitystore.orientdb.OVertexEntity.Companion.LOCAL_ENTITY_ID_PROPERTY_NAME
import jetbrains.exodus.entitystore.orientdb.iterate.link.OVertexEntityIterable
import jetbrains.exodus.util.UTFUtil
import mu.KLogging
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.InputStream

Expand Down Expand Up @@ -143,7 +145,9 @@ open class OVertexEntity(private var vertex: OVertex, private val store: Persist
val ref = vertex.getLinkProperty(blobName)
return ref?.let {
val record = activeSession.getRecord<OElement>(ref)
record.getProperty(DATA_PROPERTY_NAME)
record.getProperty<ByteArray>(DATA_PROPERTY_NAME)?.let {
UTFUtil.readUTF(ByteArrayInputStream(it))
}
}
}

Expand Down Expand Up @@ -195,7 +199,9 @@ open class OVertexEntity(private var vertex: OVertex, private val store: Persist
record = record ?: activeSession.getRecord(ref) as OElement
vertex.setProperty(blobHashProperty(blobName), blobString.hashCode())
vertex.setProperty(blobSizeProperty(blobName), blobString.length.toLong())
record.setProperty(DATA_PROPERTY_NAME, blobString)
val baos = ByteArrayOutputStream(blobString.length)
UTFUtil.writeUTF(baos, blobString)
record.setProperty(DATA_PROPERTY_NAME, baos.toByteArray())
vertex.save<OVertex>()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class MigrateDataTest {
eBlobs("type2", 4, "bob1" to "four"),
eBlobs("type2", 5, "bob1" to "five"),
eBlobs("type2", 6, "bob1" to "six"),
eStringBlobs("type2", 7, "alice" to "cooper"),
eStringBlobs("type2", 8, "alice" to "coopercooper"),
)

xodus.withTx { tx ->
Expand Down Expand Up @@ -226,6 +228,10 @@ internal fun ODocument.assertEquals(expected: Entity, entityStore: OPersistentEn
val actualValue = actual.getBlob(blobName)!!.readAllBytes()
Assert.assertEquals(blobValue, actualValue.decodeToString())
}
for ((blobName, blobValue) in expected.stringBlobs) {
val actualValue = actual.getBlobString(blobName)!!
Assert.assertEquals(blobValue, actualValue)
}

for (expectedLink in expected.links) {
val actualLinks = actual.getLinks(expectedLink.name).toList()
Expand Down Expand Up @@ -259,6 +265,9 @@ internal fun StoreTransaction.createEntity(entity: Entity) {
for ((name, value) in entity.blobs) {
e.setBlob(name, ByteArrayInputStream(value.encodeToByteArray()))
}
for ((name, value) in entity.stringBlobs) {
e.setBlobString(name, value)
}
}

internal fun StoreTransaction.createLinks(entity: Entity) {
Expand Down Expand Up @@ -288,6 +297,7 @@ data class Entity(
val id: Int,
val props: Map<String, Comparable<*>>,
val blobs: Map<String, String>,
val stringBlobs: Map<String, String>,
val links: List<Link>
)

Expand All @@ -306,14 +316,18 @@ fun pileOfEntities(vararg entities: Entity): PileOfEntities {
}

fun eProps(type: String, id: Int, vararg props: Pair<String, Comparable<*>>): Entity {
return Entity(type, id, props.toMap(), mapOf(), listOf())
return Entity(type, id, props.toMap(), mapOf(), mapOf(), listOf())
}

fun eBlobs(type: String, id: Int, vararg blobs: Pair<String, String>): Entity {
return Entity(type, id, mapOf(), blobs.toMap(), listOf())
return Entity(type, id, mapOf(), blobs.toMap(), mapOf(), listOf())
}

fun eStringBlobs(type: String, id: Int, vararg blobs: Pair<String, String>): Entity {
return Entity(type, id, mapOf(), mapOf(), blobs.toMap(), listOf())
}

fun eLinks(type: String, id: Int, vararg links: Link): Entity {
return Entity(type, id, mapOf(), mapOf(), links.toList())
return Entity(type, id, mapOf(), mapOf(), mapOf(), links.toList())
}

0 comments on commit dfefa93

Please sign in to comment.