-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unknown classes and ERS API improvement (#264)
* Fix unknown classes and ERS API improvement [jacodb-core] Specify identity for UnknownField, UnknownMethod, JcTypedFieldImpl [jacodb-core] Fix operations with map names in LmdbKeyValueStorage [jacodb-core] Avoid creation of named maps for R/O operations [jacodb-core] Force use of sortedSet by getMapNames() [jacodb-core] For an entity type, add ability to get names of used properties/blobs/links The sets of names of properties/blobs/links returned by the API consist of names ever have been set to an entity of specified type. So the sets can contain names of properties/blobs/links that could actually have been deleted in all entities of specified type. As a bonus, the way how named map are created was changed. As of now, any R/O operation doesn't implicitly create name map, whereas R/W operation does. TODO: fix implementation atop of LMDB and SQLite. [jacodb-core] Define equals()/hashcode() in JcUnknownClass & JcUnknownType [jacodb-core] Apply JcUnknownClassLookup only for instances of JcUnknownClass As of now, there is no longer an ability to get and unknown field or an unknown method for instances other than JcUnknownClass. [jacodb-api] ERS API: inherit EntityIterable from Kotlin Sequence As of now, EntityIterable is no longer Iterable, but Kotlin Sequence. All methods and properties, except iterator(), have default implementations. Binary operations are implemented as lazy sequences. * [jacodb-core] Add to JcCacheSettings ability to specify cache SPI provider
- Loading branch information
Showing
34 changed files
with
622 additions
and
253 deletions.
There are no files selected for viewing
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
107 changes: 107 additions & 0 deletions
107
jacodb-api-jvm/src/main/kotlin/org/jacodb/api/jvm/storage/ers/EntityIterableEx.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,107 @@ | ||
/* | ||
* Copyright 2022 UnitTestBot contributors (utbot.org) | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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 org.jacodb.api.jvm.storage.ers | ||
|
||
/** | ||
* Default lazy implementations of binary operations over instances of `EntityIterable` | ||
*/ | ||
fun EntityIterable.union(other: EntityIterable): EntityIterable { | ||
val self = this | ||
return object : EntityIterable { | ||
override fun iterator(): Iterator<Entity> { | ||
return object : Iterator<Entity> { | ||
|
||
val iterated = HashSet<Entity>() | ||
var iter = self.iterator() | ||
var switchedToOther = false | ||
var next: Entity? = null | ||
|
||
override fun hasNext(): Boolean { | ||
advance() | ||
return next != null | ||
} | ||
|
||
override fun next(): Entity { | ||
advance() | ||
return (next ?: error("No more entities available")).also { next = null } | ||
} | ||
|
||
private fun advance() { | ||
if (next == null) { | ||
if (!switchedToOther) { | ||
if (iter.hasNext()) { | ||
next = iter.next().also { | ||
iterated.add(it) | ||
} | ||
return | ||
} | ||
iter = other.iterator() | ||
switchedToOther = true | ||
} | ||
while (iter.hasNext()) { | ||
iter.next().let { | ||
if (it !in iterated) { | ||
next = it | ||
return | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun EntityIterable.intersect(other: EntityIterable): EntityIterable { | ||
val self = this | ||
return object : EntityIterable { | ||
override fun iterator(): Iterator<Entity> { | ||
val otherSet = other.toEntityIdSet() | ||
return self.filter { it.id in otherSet }.iterator() | ||
} | ||
|
||
} | ||
} | ||
|
||
fun EntityIterable.subtract(other: EntityIterable): EntityIterable { | ||
val self = this | ||
return object : EntityIterable { | ||
override fun iterator(): Iterator<Entity> { | ||
val otherSet = other.toEntityIdSet() | ||
return self.filter { it.id !in otherSet }.iterator() | ||
} | ||
|
||
} | ||
} | ||
|
||
fun EntityIterable.toEntityIdSet(): Set<EntityId> { | ||
val it = iterator() | ||
if (!it.hasNext()) { | ||
return emptySet() | ||
} | ||
val element = it.next() | ||
if (!it.hasNext()) { | ||
return setOf(element.id) | ||
} | ||
val result = LinkedHashSet<EntityId>() | ||
result.add(element.id) | ||
while (it.hasNext()) { | ||
result.add(it.next().id) | ||
} | ||
return result | ||
} |
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
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
Oops, something went wrong.