Skip to content

Commit

Permalink
Merge pull request #266 from JetBrains/graph-store-XD-1201
Browse files Browse the repository at this point in the history
Graph store xd 1201
  • Loading branch information
leostryuk authored Mar 7, 2025
2 parents 5a557e2 + 8f26ff3 commit 5a1a7a4
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class YTDBPersistentEntityStore(
currentTx.renameOClass(oldEntityTypeName, newEntityTypeName)
}

override fun deleteEntityType(entityTypeName: String) {
val currentTx = requireActiveTransaction()
currentTx.deleteOClass(entityTypeName)
}

override fun getAndCheckCurrentTransaction(): StoreTransaction {
return requireActiveTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ interface YTDBSchemaBuddy {

fun renameOClass(session: DatabaseSession, oldName: String, newName: String)

fun deleteOClass(session: DatabaseSession, name: String)

fun getOrCreateEdgeClass(
session: DatabaseSession,
linkName: String,
Expand Down Expand Up @@ -119,6 +121,15 @@ class YTDBSchemaBuddyImpl(
}
}

override fun deleteOClass(session: DatabaseSession, name: String) {
session.executeInASeparateSessionIfCurrentHasTransaction(dbProvider) { sessionToWork ->
val targetClass = sessionToWork.schema.getClass(name)
if (targetClass != null){
sessionToWork.schema.dropClass(name)
}
}
}

override fun getOrCreateEdgeClass(
session: DatabaseSession,
linkName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ interface YTDBStoreTransaction : StoreTransaction {
): SchemaClass

fun bindResultSet(resultSet: ResultSet)
fun deleteOClass(entityTypeName: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ class YTDBStoreTransactionImpl(
schemaBuddy.renameOClass(session, oldName, newName)
}

override fun deleteOClass(entityTypeName: String) {
requireActiveTransaction()
schemaBuddy.deleteOClass(session, entityTypeName)
}

override fun getOrCreateEdgeClass(
linkName: String,
outClassName: String,
Expand Down Expand Up @@ -524,6 +529,8 @@ class YTDBStoreTransactionImpl(
return schemaBuddy.getType(session, entityTypeId)
}



override fun bindResultSet(resultSet: ResultSet) {
resultSets.add(resultSet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ class OPersistentStoreTest : OTestMixin {
}
}

@Test
fun `can delete entityType`(){
youTrackDb.withSession { session->
Assert.assertNotNull(session.getClass(Issues.CLASS))
}
youTrackDb.createIssue("trista")
youTrackDb.withStoreTx {
youTrackDb.store.deleteEntityType(Issues.CLASS)
}
youTrackDb.withSession { session->
Assert.assertNull(session.getClass(Issues.CLASS))
}
}

@Test
fun `requireOEntityId works correctly with different types of EntityId`() {
val issueId = youTrackDb.createIssue("trista").id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

import jetbrains.exodus.backup.Backupable;
import jetbrains.exodus.bindings.ComparableBinding;
import jetbrains.exodus.core.execution.JobProcessor;
import jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor;
import jetbrains.exodus.env.Environment;
import jetbrains.exodus.management.Statistics;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -155,6 +152,8 @@ void registerCustomPropertyType(@NotNull final StoreTransaction txn,
*/
void renameEntityType(@NotNull String oldEntityTypeName, @NotNull String newEntityTypeName);

void deleteEntityType(@NotNull String entityTypeName);

@NotNull
StoreTransaction getAndCheckCurrentTransaction();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@ public void remove() { // don't give a damn
);
}

@Override
public void deleteEntityType(@NotNull final String entityTypeName) {
final PersistentStoreTransaction txn = getAndCheckCurrentTransaction();
final int entityTypeId = entityTypes.delete(txn, entityTypeName);
Expand Down
17 changes: 7 additions & 10 deletions query/src/main/kotlin/jetbrains/exodus/query/QueryEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,13 @@ open class QueryEngine(val modelMetaData: ModelMetaData?, val persistentStore: P
open fun query(entityType: String, tree: NodeBase): EntityIterable = query(null, entityType, tree)

open fun query(instance: Iterable<Entity>?, entityType: String, tree: NodeBase): EntityIterable {
return when (instance) {
null -> tree.instantiate(entityType, this, modelMetaData, NodeBase.InstantiateContext()) as EntityIterable
is EntityIterable -> {
if (tree is Sort){
return when {
modelMetaData != null && modelMetaData.getEntityMetaData(entityType) == null -> YTDBEntityIterableBase.EMPTY
instance == null -> tree.instantiate(entityType, this, modelMetaData, NodeBase.InstantiateContext()) as EntityIterable
instance is EntityIterable -> {
if (tree is Sort) {
val sorted = tree.applySort(entityType, instance, sortEngine!!)
if (sorted !is EntityIterable){
InMemoryEntityIterable(sorted, txn = persistentStore.andCheckCurrentTransaction, this)
} else {
sorted
}
sorted as? EntityIterable ?: InMemoryEntityIterable(sorted, txn = persistentStore.andCheckCurrentTransaction, this)
} else {
instance.intersect(
tree.instantiate(
Expand Down Expand Up @@ -202,7 +199,7 @@ open class QueryEngine(val modelMetaData: ModelMetaData?, val persistentStore: P
*/
internal open fun inMemoryIntersect(left: Iterable<Entity>, right: Iterable<Entity>): Iterable<Entity> {
val ids: EntityIdSet
val sequence: kotlin.sequences.Sequence<Entity>
val sequence: Sequence<Entity>

val txn = persistentStore.andCheckCurrentTransaction
if (left is YTDBEntityIterable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import jetbrains.exodus.entitystore.youtrackdb.iterate.YTDBEntityOfTypeIterable
import jetbrains.exodus.entitystore.youtrackdb.testutil.*
import jetbrains.exodus.query.metadata.entity
import jetbrains.exodus.query.metadata.oModel
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -52,6 +53,17 @@ class OperationsWithEmptyIterableTest : OTestMixin {
}
}

@Test
fun `query for non existent class should return empty YTDBEmpty`(){
val model = givenModel()
val engine = QueryEngine(model, youTrackDb.store)
withStoreTx {
val iterable = engine.queryGetAll("HAHAHA_NOSUCH_CLASS")
Assert.assertEquals(iterable.size(), 0)
}
}


private fun givenModel() = oModel(youTrackDb.provider) {
entity(BaseUser.CLASS)
entity(User.CLASS, BaseUser.CLASS)
Expand Down

0 comments on commit 5a1a7a4

Please sign in to comment.