@@ -13,6 +13,8 @@ import org.modelix.streams.IStream
13
13
import org.modelix.streams.IStreamExecutorProvider
14
14
import org.modelix.streams.plus
15
15
16
+ typealias IModelTree = IGenericModelTree <INodeReference >
17
+
16
18
/* *
17
19
* Persistent model implementation that supports bulk requests, bulk updates and non-Long node IDs.
18
20
* Consistently using the streams API enables efficient lazy loading of model data.
@@ -22,14 +24,14 @@ import org.modelix.streams.plus
22
24
* as the primary ID. This makes importing and updating models from source such as MPS easier and more efficient. No
23
25
* need for maintaining a mapping between the MPS ID and the Modelix ID. Also, since there is no generated ID that has
24
26
* a different value for each import, we don't have to check if a node already exists and reuse it. We can just run a
25
- * fresh import and then do a diff. All the data stored in the [IModelTree ] also exists in the original source and if it
27
+ * fresh import and then do a diff. All the data stored in the [IGenericModelTree ] also exists in the original source and if it
26
28
* didn't change, we will end up with the same hash.
27
29
* With a prefix tree like the [org.modelix.datastructures.patricia.PatriciaTrie] we can even re-run the import for
28
30
* individual MPS models very efficiently, because all the nodes in the same model have the same model ID as a common
29
31
* prefix of their node ID and will end up in the same subtree of the trie data structure, giving us a single hash for
30
32
* the imported MPS model.
31
33
*/
32
- interface IModelTree <NodeId > : IStreamExecutorProvider {
34
+ interface IGenericModelTree <NodeId > : IStreamExecutorProvider {
33
35
fun asObject (): Object <CPTree >
34
36
fun getNodeIdType (): IDataTypeConfiguration <NodeId >
35
37
@@ -57,17 +59,19 @@ interface IModelTree<NodeId> : IStreamExecutorProvider {
57
59
fun getChildRoles (parentId : NodeId ): IStream .Many <IChildLinkReference >
58
60
fun getChildrenAndRoles (parentId : NodeId ): IStream .Many <Pair <IChildLinkReference , IStream .Many <NodeId >>>
59
61
60
- fun getChanges (oldVersion : IModelTree <NodeId >, changesOnly : Boolean ): IStream .Many <ModelChangeEvent <NodeId >>
62
+ fun getChanges (oldVersion : IGenericModelTree <NodeId >, changesOnly : Boolean ): IStream .Many <ModelChangeEvent <NodeId >>
61
63
62
- fun mutate (operations : Iterable <MutationParameters <NodeId >>): IStream .One <IModelTree <NodeId >>
64
+ fun mutate (operations : Iterable <MutationParameters <NodeId >>): IStream .One <IGenericModelTree <NodeId >>
63
65
64
- fun mutate (operation : MutationParameters <NodeId >): IStream .One <IModelTree <NodeId >> = mutate(listOf (operation))
66
+ fun mutate (operation : MutationParameters <NodeId >): IStream .One <IGenericModelTree <NodeId >> = mutate(listOf (operation))
65
67
66
68
companion object {
67
69
fun builder (): ModelTreeBuilder <Long > = ModelTreeBuilder .newWithInt64Ids()
68
70
}
69
71
}
70
72
73
+ fun IGenericModelTree <* >.getHash () = asObject().getHash()
74
+
71
75
sealed class MutationParameters <NodeId > {
72
76
sealed class Node <NodeId > : MutationParameters <NodeId >() {
73
77
abstract val nodeId: NodeId
@@ -112,36 +116,36 @@ sealed class MutationParameters<NodeId> {
112
116
data class Remove <NodeId >(override val nodeId : NodeId ) : Node<NodeId>()
113
117
}
114
118
115
- fun <NodeId > IModelTree <NodeId>.getDescendants (nodeId : NodeId , includeSelf : Boolean ): IStream .Many <NodeId > {
119
+ fun <NodeId > IGenericModelTree <NodeId>.getDescendants (nodeId : NodeId , includeSelf : Boolean ): IStream .Many <NodeId > {
116
120
return if (includeSelf) {
117
121
IStream .of(nodeId).plus(getDescendants(nodeId, false ))
118
122
} else {
119
123
getChildren(nodeId).flatMap { getDescendants(it, true ) }
120
124
}
121
125
}
122
126
123
- fun <NodeId > IModelTree <NodeId>.getAncestors (nodeId : NodeId , includeSelf : Boolean ): IStream .Many <NodeId > {
127
+ fun <NodeId > IGenericModelTree <NodeId>.getAncestors (nodeId : NodeId , includeSelf : Boolean ): IStream .Many <NodeId > {
124
128
return if (includeSelf) {
125
129
IStream .of(nodeId).plus(getAncestors(nodeId, false ))
126
130
} else {
127
131
getParent(nodeId).flatMap { getAncestors(it, true ) }
128
132
}
129
133
}
130
134
131
- fun <NodeId > IModelTree <NodeId>.setProperty (nodeId : NodeId , role : IPropertyReference , value : String? ): IStream .One <IModelTree <NodeId >> =
135
+ fun <NodeId > IGenericModelTree <NodeId>.setProperty (nodeId : NodeId , role : IPropertyReference , value : String? ): IStream .One <IGenericModelTree <NodeId >> =
132
136
mutate(MutationParameters .Property (nodeId, role, value))
133
137
134
- fun <NodeId > IModelTree <NodeId>.setReferenceTarget (sourceId : NodeId , role : IReferenceLinkReference , target : INodeReference ): IStream .One <IModelTree <NodeId >> =
138
+ fun <NodeId > IGenericModelTree <NodeId>.setReferenceTarget (sourceId : NodeId , role : IReferenceLinkReference , target : INodeReference ): IStream .One <IGenericModelTree <NodeId >> =
135
139
mutate(MutationParameters .Reference (sourceId, role, target))
136
140
137
- fun <NodeId > IModelTree <NodeId>.moveNode (newParentId : NodeId , newRole : IChildLinkReference , newIndex : Int , childId : NodeId ): IStream .One <IModelTree <NodeId >> =
141
+ fun <NodeId > IGenericModelTree <NodeId>.moveNode (newParentId : NodeId , newRole : IChildLinkReference , newIndex : Int , childId : NodeId ): IStream .One <IGenericModelTree <NodeId >> =
138
142
mutate(MutationParameters .Move (newParentId, newRole, newIndex, listOf (childId)))
139
143
140
- fun <NodeId > IModelTree <NodeId>.addNewChild (parentId : NodeId , role : IChildLinkReference , index : Int , childId : NodeId , concept : ConceptReference ): IStream .One <IModelTree <NodeId >> =
144
+ fun <NodeId > IGenericModelTree <NodeId>.addNewChild (parentId : NodeId , role : IChildLinkReference , index : Int , childId : NodeId , concept : ConceptReference ): IStream .One <IGenericModelTree <NodeId >> =
141
145
mutate(MutationParameters .AddNew (parentId, role, index, listOf (childId to concept)))
142
146
143
- fun <NodeId > IModelTree <NodeId>.removeNode (nodeId : NodeId ): IStream .One <IModelTree <NodeId >> =
147
+ fun <NodeId > IGenericModelTree <NodeId>.removeNode (nodeId : NodeId ): IStream .One <IGenericModelTree <NodeId >> =
144
148
mutate(MutationParameters .Remove (nodeId))
145
149
146
- fun <NodeId > IModelTree <NodeId>.changeConcept (nodeId : NodeId , concept : ConceptReference ): IStream .One <IModelTree <NodeId >> =
150
+ fun <NodeId > IGenericModelTree <NodeId>.changeConcept (nodeId : NodeId , concept : ConceptReference ): IStream .One <IGenericModelTree <NodeId >> =
147
151
mutate(MutationParameters .Concept (nodeId, concept))
0 commit comments