Skip to content

Commit d1a7cff

Browse files
committed
refactor(model-datastructure): redesign of objects references
1 parent be7f998 commit d1a7cff

File tree

85 files changed

+1391
-1327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1391
-1327
lines changed

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/AbstractModelSyncTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.api.getRootNode
88
import org.modelix.model.client.IdGenerator
99
import org.modelix.model.data.ModelData
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.AddNewChildOp
1313
import org.modelix.model.operations.DeleteNodeOp
1414
import org.modelix.model.operations.IOperation
@@ -601,11 +601,11 @@ abstract class AbstractModelSyncTest {
601601
internal fun OTBranch.getNumOfUsedOperationsByType() = getPendingChanges().first.numOpsByType()
602602

603603
internal fun createOTBranchFromModel(model: ModelData): OTBranch {
604-
val pBranch = PBranch(CLTree(ObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
604+
val pBranch = PBranch(CLTree(createObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
605605
pBranch.runWrite {
606606
ModelImporter(pBranch.getRootNode()).import(model)
607607
}
608-
return OTBranch(pBranch, IdGenerator.getInstance(1), ObjectStoreCache(MapBasedStore()))
608+
return OTBranch(pBranch, IdGenerator.getInstance(1), createObjectStoreCache(MapBasedStore()))
609609
}
610610

611611
internal fun IBranch.importIncrementally(model: ModelData) {

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelExporterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import org.modelix.model.api.getRootNode
66
import org.modelix.model.client.IdGenerator
77
import org.modelix.model.data.ModelData
88
import org.modelix.model.lazy.CLTree
9-
import org.modelix.model.lazy.ObjectStoreCache
9+
import org.modelix.model.lazy.createObjectStoreCache
1010
import org.modelix.model.persistent.MapBasedStore
1111
import kotlin.js.JsName
1212
import kotlin.test.Test
@@ -52,7 +52,7 @@ class ModelExporterTest {
5252
private val model = ModelData.fromJson(serializedModel)
5353

5454
private fun runTest(body: IBranch.() -> Unit) {
55-
val branch = PBranch(CLTree(ObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
55+
val branch = PBranch(CLTree(createObjectStoreCache(MapBasedStore())), IdGenerator.getInstance(1))
5656
branch.runWrite {
5757
model.load(branch)
5858
}

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelImporterOrderPropertyTest.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.modelix.model.api.getRootNode
1010
import org.modelix.model.client.IdGenerator
1111
import org.modelix.model.data.ModelData
1212
import org.modelix.model.lazy.CLTree
13-
import org.modelix.model.lazy.ObjectStoreCache
13+
import org.modelix.model.lazy.createObjectStoreCache
1414
import org.modelix.model.persistent.MapBasedStore
1515
import org.modelix.model.withAutoTransactions
1616
import kotlin.js.JsName
@@ -61,13 +61,8 @@ class ModelImporterOrderPropertyTest {
6161
}
6262

6363
private fun loadModelIntoBranch(modelData: ModelData): IBranch {
64-
val store = ObjectStoreCache(MapBasedStore())
65-
val tree = CLTree(
66-
data = null,
67-
repositoryId_ = null,
68-
store_ = store,
69-
useRoleIds = true,
70-
)
64+
val store = createObjectStoreCache(MapBasedStore())
65+
val tree = CLTree.builder(store).useRoleIds(true).build()
7166
val idGenerator = IdGenerator.getInstance(1)
7267
val pBranch = PBranch(tree, idGenerator)
7368

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelImporterTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.data.ModelData
88
import org.modelix.model.data.NodeData
99
import org.modelix.model.data.NodeData.Companion.ID_PROPERTY_KEY
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.OTBranch
1313
import org.modelix.model.persistent.MapBasedStore
1414
import org.modelix.model.test.RandomModelChangeGenerator
@@ -24,7 +24,7 @@ class ModelImporterTest : AbstractModelSyncTest() {
2424
}
2525

2626
override fun runRandomTest(seed: Int) {
27-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
27+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
2828
val branch0 = PBranch(tree0, IdGenerator.getInstance(1))
2929

3030
println("Seed for random change test: $seed")
@@ -49,7 +49,7 @@ class ModelImporterTest : AbstractModelSyncTest() {
4949
specification = rootNode.asExported()
5050
}
5151

52-
val store = ObjectStoreCache(MapBasedStore())
52+
val store = createObjectStoreCache(MapBasedStore())
5353
val tree1 = CLTree(store)
5454
val idGenerator = IdGenerator.getInstance(1)
5555
val branch1 = PBranch(tree1, idGenerator)

bulk-model-sync-lib/src/commonTest/kotlin/org/modelix/model/sync/bulk/ModelSynchronizerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.modelix.model.client.IdGenerator
1111
import org.modelix.model.data.ModelData
1212
import org.modelix.model.data.NodeData
1313
import org.modelix.model.lazy.CLTree
14-
import org.modelix.model.lazy.ObjectStoreCache
14+
import org.modelix.model.lazy.createObjectStoreCache
1515
import org.modelix.model.operations.AddNewChildOp
1616
import org.modelix.model.operations.AddNewChildrenOp
1717
import org.modelix.model.operations.DeleteNodeOp
@@ -141,7 +141,7 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
141141
}
142142

143143
override fun runRandomTest(seed: Int) {
144-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
144+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
145145
val sourceBranch = PBranch(tree0, IdGenerator.getInstance(1))
146146

147147
println("Seed for random change test: $seed")
@@ -162,7 +162,7 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
162162
}
163163
}
164164

165-
val store = ObjectStoreCache(MapBasedStore())
165+
val store = createObjectStoreCache(MapBasedStore())
166166
val tree1 = CLTree(store)
167167
val idGenerator = IdGenerator.getInstance(1)
168168
val targetBranch = PBranch(tree1, idGenerator)
@@ -196,5 +196,5 @@ open class ModelSynchronizerTest : AbstractModelSyncTest() {
196196
}
197197

198198
private fun IBranch.toOTBranch(): OTBranch {
199-
return OTBranch(this, IdGenerator.getInstance(1), ObjectStoreCache(MapBasedStore()))
199+
return OTBranch(this, IdGenerator.getInstance(1), createObjectStoreCache(MapBasedStore()))
200200
}

bulk-model-sync-lib/src/jvmTest/kotlin/org/modelix/model/sync/bulk/ModelSynchronizerWithInvalidationTreeTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import org.modelix.model.client.IdGenerator
88
import org.modelix.model.data.ModelData
99
import org.modelix.model.data.NodeData.Companion.ID_PROPERTY_KEY
1010
import org.modelix.model.lazy.CLTree
11-
import org.modelix.model.lazy.ObjectStoreCache
11+
import org.modelix.model.lazy.createObjectStoreCache
1212
import org.modelix.model.operations.OTBranch
1313
import org.modelix.model.persistent.MapBasedStore
1414
import org.modelix.model.test.RandomModelChangeGenerator
@@ -46,7 +46,7 @@ class ModelSynchronizerWithInvalidationTreeTest : ModelSynchronizerTest() {
4646
}
4747

4848
override fun runRandomTest(seed: Int) {
49-
val tree0 = CLTree(ObjectStoreCache(MapBasedStore()))
49+
val tree0 = CLTree(createObjectStoreCache(MapBasedStore()))
5050
val sourceBranch = PBranch(tree0, IdGenerator.getInstance(1))
5151

5252
println("Seed for random change test: $seed")
@@ -67,7 +67,7 @@ class ModelSynchronizerWithInvalidationTreeTest : ModelSynchronizerTest() {
6767
}
6868
}
6969

70-
val store = ObjectStoreCache(MapBasedStore())
70+
val store = createObjectStoreCache(MapBasedStore())
7171
val tree1 = CLTree(store)
7272
val idGenerator = IdGenerator.getInstance(1)
7373
val targetBranch = PBranch(tree1, idGenerator)

model-client/src/commonMain/kotlin/org/modelix/model/ModelFacade.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ import org.modelix.model.client.IdGenerator
1414
import org.modelix.model.lazy.BranchReference
1515
import org.modelix.model.lazy.CLTree
1616
import org.modelix.model.lazy.CLVersion
17-
import org.modelix.model.lazy.ObjectStoreCache
1817
import org.modelix.model.lazy.RepositoryId
18+
import org.modelix.model.lazy.createObjectStoreCache
19+
import org.modelix.model.objects.Object
20+
import org.modelix.model.objects.ObjectHash
21+
import org.modelix.model.objects.ObjectReference
1922
import org.modelix.model.operations.OTBranch
2023
import org.modelix.model.persistent.CPVersion
21-
import org.modelix.model.persistent.MapBaseStore
24+
import org.modelix.model.persistent.MapBasedStore
2225
import kotlin.jvm.JvmOverloads
2326

2427
object ModelFacade {
2528

2629
@JvmOverloads
2730
fun newLocalTree(useRoleIds: Boolean = true): ITree {
28-
return CLTree(ObjectStoreCache(MapBaseStore()), useRoleIds = useRoleIds)
31+
return CLTree.builder(createObjectStoreCache(MapBasedStore())).useRoleIds(useRoleIds).build()
2932
}
3033

3134
fun getRootNode(branch: IBranch): INode {
@@ -95,7 +98,10 @@ object ModelFacade {
9598
?: throw RuntimeException("$branch doesn't exist")
9699
val baseVersionData: CPVersion = client.storeCache.get(actualBaseVersionHash) { CPVersion.deserialize(it) }
97100
?: throw RuntimeException("version not found: $actualBaseVersionHash")
98-
val baseVersion = CLVersion(baseVersionData, client.storeCache)
101+
val baseVersion = CLVersion(
102+
Object(baseVersionData, ObjectReference(ObjectHash(actualBaseVersionHash), baseVersionData)),
103+
client.storeCache.getAsyncStore(),
104+
)
99105
return applyUpdate(client, baseVersion, branch, userName, body)
100106
}
101107

model-client/src/commonMain/kotlin/org/modelix/model/client2/IModelClientV2.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.modelix.model.IVersion
55
import org.modelix.model.ObjectDeltaFilter
66
import org.modelix.model.api.IIdGenerator
77
import org.modelix.model.api.INode
8+
import org.modelix.model.async.IAsyncObjectStore
89
import org.modelix.model.lazy.BranchReference
910
import org.modelix.model.lazy.RepositoryId
1011
import org.modelix.modelql.core.IMonoStep
@@ -28,6 +29,8 @@ interface IModelClientV2 {
2829
fun getIdGenerator(): IIdGenerator
2930
fun getUserId(): String?
3031

32+
fun getStore(repository: RepositoryId): IAsyncObjectStore
33+
3134
suspend fun initRepository(repository: RepositoryId, useRoleIds: Boolean = true): IVersion
3235
suspend fun initRepositoryWithLegacyStorage(repository: RepositoryId): IVersion
3336
suspend fun listRepositories(): List<RepositoryId>

model-client/src/commonMain/kotlin/org/modelix/model/client2/ModelClientAsStore.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import kotlinx.coroutines.flow.flow
44
import org.modelix.model.IKeyValueStore
55
import org.modelix.model.async.AsyncStoreAsLegacyDeserializingStore
66
import org.modelix.model.async.IAsyncObjectStore
7-
import org.modelix.model.async.ObjectHash
7+
import org.modelix.model.async.ObjectRequest
88
import org.modelix.model.lazy.IDeserializingKeyValueStore
99
import org.modelix.model.lazy.RepositoryId
10+
import org.modelix.model.objects.IObjectData
1011
import org.modelix.model.persistent.HashUtil
11-
import org.modelix.model.persistent.IKVValue
1212
import org.modelix.streams.IStream
1313
import org.modelix.streams.IStreamExecutor
1414
import org.modelix.streams.SimpleStreamExecutor
@@ -25,23 +25,25 @@ class ModelClientAsStore(client: IModelClientV2, val repositoryId: RepositoryId)
2525
return AsyncStoreAsLegacyDeserializingStore(this)
2626
}
2727

28-
override fun <T : Any> getIfCached(key: ObjectHash<T>): T? {
28+
override fun clearCache() {}
29+
30+
override fun <T : Any> getIfCached(key: ObjectRequest<T>): T? {
2931
return null
3032
}
3133

32-
override fun <T : Any> get(key: ObjectHash<T>): IStream.ZeroOrOne<T> {
34+
override fun <T : Any> get(key: ObjectRequest<T>): IStream.ZeroOrOne<T> {
3335
return getAllAsStream(IStream.of(key)).map {
3436
checkNotNull(it.second) { "Entry not found: ${key.hash}" } as T
3537
}.exactlyOne()
3638
}
3739

38-
override fun getAllAsStream(keys: IStream.Many<ObjectHash<*>>): IStream.Many<Pair<ObjectHash<*>, Any?>> {
40+
override fun getAllAsStream(keys: IStream.Many<ObjectRequest<*>>): IStream.Many<Pair<ObjectRequest<*>, Any?>> {
3941
return keys.toList().flatMap { keysAsList ->
4042
getAllAsMap(keysAsList).flatMapIterable { it.entries }.map { it.key to it.value }
4143
}
4244
}
4345

44-
override fun getAllAsMap(keys: List<ObjectHash<*>>): IStream.One<Map<ObjectHash<*>, Any?>> {
46+
override fun getAllAsMap(keys: List<ObjectRequest<*>>): IStream.One<Map<ObjectRequest<*>, Any?>> {
4547
return IStream.fromFlow(
4648
flow {
4749
val serializedObjects = client.getObjects(repositoryId, keys.asSequence().map { it.hash })
@@ -53,7 +55,7 @@ class ModelClientAsStore(client: IModelClientV2, val repositoryId: RepositoryId)
5355
).exactlyOne()
5456
}
5557

56-
override fun putAll(entries: Map<ObjectHash<*>, IKVValue>): IStream.Zero {
58+
override fun putAll(entries: Map<ObjectRequest<*>, IObjectData>): IStream.Zero {
5759
return IStream.fromFlow<Nothing>(
5860
flow {
5961
client.pushObjects(

0 commit comments

Comments
 (0)