Skip to content

Commit

Permalink
XD-1189 implemented inplace operations
Browse files Browse the repository at this point in the history
  • Loading branch information
leostryuk committed Jan 16, 2025
1 parent d94f142 commit 347f6d9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class OStoreTransactionImpl(
requireActiveTransaction()
try {
return session.load(id.asOId())
} catch (e: RecordNotFoundException) {
} catch (_: RecordNotFoundException) {
throw EntityRemovedInDatabaseException(id.getTypeName(), id)
}

Expand Down Expand Up @@ -259,7 +259,7 @@ class OStoreTransactionImpl(
try {
val vertex: Vertex = session.load(oId.asOId())
return OVertexEntity(vertex, store)
} catch (e: RecordNotFoundException) {
} catch (_: RecordNotFoundException) {
throw EntityRemovedInDatabaseException(oId.getTypeName(), id)
}
}
Expand All @@ -276,7 +276,7 @@ class OStoreTransactionImpl(

override fun getSingletonIterable(entity: Entity): EntityIterable {
requireActiveTransaction()
return OSingleEntityIterable(this, entity)
return OMultipleEntitiesIterable(this, listOf(entity))
}

override fun find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import jetbrains.exodus.entitystore.orientdb.iterate.binop.OMinusEntityIterable
import jetbrains.exodus.entitystore.orientdb.iterate.binop.OUnionEntityIterable
import jetbrains.exodus.entitystore.orientdb.iterate.link.OLinkIterableToEntityIterableFiltered
import jetbrains.exodus.entitystore.orientdb.iterate.link.OLinkSelectEntityIterable
import jetbrains.exodus.entitystore.orientdb.iterate.link.OSingleEntityIterable
import jetbrains.exodus.entitystore.orientdb.iterate.link.OMultipleEntitiesIterable
import jetbrains.exodus.entitystore.orientdb.query.*
import jetbrains.exodus.entitystore.util.unsupported

Expand Down Expand Up @@ -224,7 +224,7 @@ abstract class OEntityIterableBase(tx: OStoreTransaction) : OEntityIterable {

override fun contains(entity: Entity): Boolean {
val currentTx = oStore.requireActiveTransaction()
return OIntersectionEntityIterable(currentTx, this, OSingleEntityIterable(currentTx, entity)).iterator().hasNext()
return OIntersectionEntityIterable(currentTx, this, OMultipleEntitiesIterable(currentTx, listOf(entity))).iterator().hasNext()
}

override fun unwrap() = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,61 @@ class OMultipleEntitiesIterable(tx: OStoreTransaction, val entities: List<Entity
}

override fun skip(number: Int): EntityIterable {
return OMultipleEntitiesIterable(transaction as OStoreTransaction, entities.drop(number) )
return if (number > entities.size){
EMPTY
} else {
OMultipleEntitiesIterable(transaction as OStoreTransaction, entities.drop(number))
}
}

override fun take(number: Int): EntityIterable {
return OMultipleEntitiesIterable(transaction as OStoreTransaction, entities.take(number) )
}

override fun union(right: EntityIterable): EntityIterable {
return if (right is OMultipleEntitiesIterable) {
OMultipleEntitiesIterable(transaction as OStoreTransaction, entities.union(right.entities).toList())
} else super.union(right)
}

override fun intersect(right: EntityIterable): EntityIterable {
return if (right is OMultipleEntitiesIterable) {
val otherEntitiesAsSet = right.entities.toSet()
val intersect = entities.filter { otherEntitiesAsSet.contains(it) }
if (intersect.isEmpty()){
EMPTY
} else {
OMultipleEntitiesIterable(transaction as OStoreTransaction, intersect)
}
} else super.intersect(right)
}

override fun intersectSavingOrder(right: EntityIterable): EntityIterable {
return if (right is OMultipleEntitiesIterable) {
val otherEntitiesAsSet = right.entities.toSet()
val intersect = entities.filter { otherEntitiesAsSet.contains(it) }
if (intersect.isEmpty()){
EMPTY
} else {
OMultipleEntitiesIterable(transaction as OStoreTransaction, intersect)
}
} else super.intersectSavingOrder(right)
}

override fun concat(right: EntityIterable): EntityIterable {
return if (right is OMultipleEntitiesIterable) {
OMultipleEntitiesIterable(transaction as OStoreTransaction, entities + right.entities)
} else super.concat(right)
}

override fun minus(right: EntityIterable): EntityIterable {
return if (right is OMultipleEntitiesIterable) {
val minus = entities.toSet().minus(right.entities)
if (minus.isEmpty()){
EMPTY
} else {
OMultipleEntitiesIterable(transaction as OStoreTransaction, entities + right.entities)
}
} else super.minus(right)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ object OQueryFunctions {

fun difference(left: OSelect, right: OSelect): OSelect {
return when {
left is ORecordIdSelect && right is ORecordIdSelect -> {
ensureLimitIsNotUsed(left, right)
ensureSkipIsNotUsed(left, right)

val newOrder = left.order.merge(right.order)
val ids = left.recordIds - right.recordIds.toSet()
ORecordIdSelect(ids, newOrder)
}

left is OClassSelect && right is OClassSelect && isSameClassName(left, right) -> {
ensureInvariants(left, right)
Expand Down

0 comments on commit 347f6d9

Please sign in to comment.