@@ -29,13 +29,12 @@ import com.jetbrains.youtrack.db.internal.core.metadata.sequence.DBSequence
2929import com.jetbrains.youtrack.db.internal.core.tx.FrontendTransaction
3030import jetbrains.exodus.entitystore.*
3131import jetbrains.exodus.entitystore.youtrackdb.YTDBVertexEntity.Companion.LOCAL_ENTITY_ID_PROPERTY_NAME
32- import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinEntityIterable
3332import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinBlock
3433import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinBlock.SortDirection
34+ import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinEntityIterable
3535import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinEntityIterableImpl
3636import jetbrains.exodus.entitystore.youtrackdb.gremlin.GremlinQuery
37- import jetbrains.exodus.entitystore.youtrackdb.iterate.link.*
38- import jetbrains.exodus.entitystore.youtrackdb.iterate.property.*
37+ import jetbrains.exodus.entitystore.youtrackdb.iterate.property.YTDBSequenceImpl
3938import jetbrains.exodus.entitystore.youtrackdb.query.YTDBQueryCancellingPolicy
4039import jetbrains.exodus.env.ReadonlyTransactionException
4140import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
@@ -275,10 +274,12 @@ class YTDBGremlinStoreTransactionImpl(
275274 return GremlinEntityIterable .where(entityType, this , GremlinBlock .All )
276275 }
277276
278- // todo: remove YTDBMultipleEntitiesIterable
279277 override fun getSingletonIterable (entity : Entity ): EntityIterable {
280278 requireActiveTransaction()
281- return YTDBMultipleEntitiesIterable (this , listOf (entity))
279+ return GremlinEntityIterable .query(
280+ this , GremlinQuery .all
281+ .then(GremlinBlock .IdEqual ((entity.id as YTDBEntityId ).asOId()))
282+ )
282283 }
283284
284285 override fun find (
@@ -346,11 +347,13 @@ class YTDBGremlinStoreTransactionImpl(
346347 propertyName : String
347348 ): EntityIterable {
348349 requireActiveTransaction()
349- return GremlinEntityIterable .where(
350- entityType, this ,
351- GremlinBlock .PropNotNull (propertyName)
350+ return GremlinEntityIterable .query(
351+ this ,
352+ GremlinQuery .all
353+ .then(GremlinBlock .HasLabel (entityType))
354+ .then(GremlinBlock .PropNotNull (propertyName))
352355 // todo: move SortBy out of Condition
353- .andThen (GremlinBlock .SortBy ( propertyName, SortDirection .ASC ))
356+ .then (GremlinBlock .Sort ( GremlinBlock . Sort . ByProp ( propertyName) , SortDirection .ASC ))
354357 )
355358 }
356359
@@ -364,9 +367,9 @@ class YTDBGremlinStoreTransactionImpl(
364367 return GremlinEntityIterable .query(
365368 this ,
366369 GremlinQuery .all
367- .andThen (GremlinBlock .PropEqual (LOCAL_ENTITY_ID_PROPERTY_NAME , entity.id.localId))
368- .andThen (GremlinBlock .InLink (linkName))
369- .andThen (GremlinBlock .HasLabel (entityType))
370+ .then (GremlinBlock .PropEqual (LOCAL_ENTITY_ID_PROPERTY_NAME , entity.id.localId))
371+ .then (GremlinBlock .InLink (linkName))
372+ .then (GremlinBlock .HasLabel (entityType))
370373 )
371374 }
372375
@@ -380,15 +383,14 @@ class YTDBGremlinStoreTransactionImpl(
380383 return GremlinEntityIterable .query(
381384 this ,
382385 entityQuery
383- .andThen (GremlinBlock .InLink (linkName))
384- .andThen (GremlinBlock .HasLabel (entityType))
386+ .then (GremlinBlock .InLink (linkName))
387+ .then (GremlinBlock .HasLabel (entityType))
385388 )
386389 }
387390
388- // todo:
389391 override fun findWithLinks (entityType : String , linkName : String ): EntityIterable {
390392 requireActiveTransaction()
391- return YTDBLinkExistsEntityIterable ( this , entityType, linkName)
393+ return GremlinEntityIterable .where(entityType, this , GremlinBlock . HasLink ( linkName) )
392394 }
393395
394396 override fun findWithLinks (
@@ -398,7 +400,7 @@ class YTDBGremlinStoreTransactionImpl(
398400 oppositeLinkName : String
399401 ): EntityIterable {
400402 requireActiveTransaction()
401- return YTDBLinkExistsEntityIterable ( this , entityType, linkName)
403+ return GremlinEntityIterable .where(entityType, this , GremlinBlock . HasLink ( linkName) )
402404 }
403405
404406 override fun sort (
@@ -407,7 +409,17 @@ class YTDBGremlinStoreTransactionImpl(
407409 ascending : Boolean
408410 ): EntityIterable {
409411 requireActiveTransaction()
410- return YTDBPropertySortedIterable (this , entityType, propertyName, null , ascending)
412+ return GremlinEntityIterable .query(
413+ this ,
414+ GremlinQuery .all
415+ .then(GremlinBlock .HasLabel (entityType))
416+ .then(
417+ GremlinBlock .Sort (
418+ GremlinBlock .Sort .ByProp (propertyName),
419+ if (ascending) SortDirection .ASC else SortDirection .DESC
420+ )
421+ )
422+ )
411423 }
412424
413425 override fun sort (
@@ -417,12 +429,15 @@ class YTDBGremlinStoreTransactionImpl(
417429 ascending : Boolean
418430 ): EntityIterable {
419431 requireActiveTransaction()
420- return YTDBPropertySortedIterable (
432+ return GremlinEntityIterableImpl (
421433 this ,
422- entityType,
423- propertyName,
424- rightOrder.asOQueryIterable(),
425- ascending
434+ rightOrder.asGremlinIterable().query
435+ .then(
436+ GremlinBlock .Sort (
437+ GremlinBlock .Sort .ByProp (propertyName),
438+ if (ascending) SortDirection .ASC else SortDirection .DESC
439+ )
440+ )
426441 )
427442 }
428443
@@ -434,11 +449,12 @@ class YTDBGremlinStoreTransactionImpl(
434449 rightOrder : EntityIterable
435450 ): EntityIterable {
436451 requireActiveTransaction()
437- return YTDBLinkSortEntityIterable (
452+ return GremlinEntityIterable .query (
438453 this ,
439- sortedLinks.asOQueryIterable(),
440- linkName,
441- rightOrder.asOQueryIterable()
454+ sortedLinks.asGremlinIterable().query
455+ .then(GremlinBlock .InLink (linkName))
456+ .intersect(rightOrder.asGremlinIterable().query)
457+ .then(GremlinBlock .HasLabel (entityType))
442458 )
443459 }
444460
@@ -452,12 +468,14 @@ class YTDBGremlinStoreTransactionImpl(
452468 oppositeLinkName : String
453469 ): EntityIterable {
454470 requireActiveTransaction()
471+ // todo: check if we need this
455472 // Not sure about skipping oppositeEntityType and oppositeLinkName values
456- return YTDBLinkSortEntityIterable (
473+ return GremlinEntityIterable .query (
457474 this ,
458- sortedLinks.asOQueryIterable(),
459- linkName,
460- rightOrder.asOQueryIterable()
475+ sortedLinks.asGremlinIterable().query
476+ .then(GremlinBlock .InLink (linkName))
477+ .intersect(rightOrder.asGremlinIterable().query)
478+ .then(GremlinBlock .HasLabel (entityType))
461479 )
462480 }
463481
0 commit comments