1 import "JavaBuiltin" as Java
2 include "http://www.simantics.org/Layer0-1.1" as L0
9 "org.simantics.db.ReadGraph"
13 "org.simantics.db.WriteGraph"
15 importJava "org.simantics.db.Resource" where
16 "A resource is a node in a semantic graph."
19 "Returns the 64-bit unique identifier of the resource."
20 @JavaName getResourceId
21 resourceId :: Resource -> Long
23 isPersistent :: Resource -> Boolean
25 importJava "org.simantics.db.ReadGraph" where
28 instance Ord Resource where
29 compare a b = compare (resourceId a) (resourceId b)
31 instance Show Resource where
32 show r = "#" + show (resourceId r)
34 instance Show Statement where
35 show s = "#" + show (resourceId ( subjectOf s)) + "#" + show (resourceId ( predicateOf s)) + "#" + show (resourceId ( objectOf s))
37 importJava "org.simantics.db.Statement" where
38 "A statement is an edge in a semantic graph."
42 subjectOf :: Statement -> Resource
43 @JavaName getPredicate
44 predicateOf :: Statement -> Resource
46 objectOf :: Statement -> Resource
48 isAsserted :: Statement -> Resource -> <ReadGraph> Boolean
50 importJava "org.simantics.db.ReadGraph" where
51 "Converts an absolute URI to a resource or returns `Nothing` if there is no such resource."
52 @JavaName getPossibleResource
53 possibleResource :: String -> <ReadGraph> (Maybe Resource)
55 getDataType :: Resource -> <ReadGraph> Datatype
57 @JavaName getSupertypes
58 superTypesOf :: Resource -> <ReadGraph> Set.T Resource
62 uriOfResource :: Resource -> <ReadGraph> String
65 @JavaName getPossibleURI
66 possibleUriOfResource :: Resource -> <ReadGraph> Maybe String
69 objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
71 @JavaName getStatements
72 statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement
74 @JavaName hasStatement
75 existsStatement :: Resource -> Resource -> <ReadGraph> Boolean
77 @JavaName hasStatement
78 existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean
80 "Assumes that there is exactly one object with the given subject and predicate and returns it."
81 @JavaName getSingleObject
82 singleObject :: Resource -> Resource -> <ReadGraph> Resource
85 If there is exactly one object with the given `subject` and `predicate`,
86 `possibleObject subject predicate` returns it. Otherwise, it returns
89 @JavaName getPossibleObject
90 possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource
92 "Assumes that there is exactly one statement with the given subject and predicate and returns it."
93 @JavaName getSingleStatement
94 singleStatement :: Resource -> Resource -> <ReadGraph> Statement
96 @JavaName getPossibleStatement
97 possibleStatement :: Resource -> Resource -> <ReadGraph> Maybe Statement
99 @JavaName getRelatedVariantValue
100 relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
102 @JavaName getRelatedValue
103 relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a
105 @JavaName getRelatedValue
106 untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a
108 @JavaName getRelatedValue2
109 relatedValue2 :: Resource -> Resource -> <ReadGraph> a
111 @JavaName getPossibleRelatedValue2
112 possibleRelatedValue2 :: Resource -> Resource -> <ReadGraph> Maybe a
114 @JavaName getRelatedVariantValue2
115 relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
117 @JavaName getPossibleRelatedValue
118 possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
120 @JavaName getPossibleRelatedValue
121 untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
125 valueOf_ :: Resource -> Binding a -> <ReadGraph> a
128 @JavaName getVariantValue
129 variantValueOf_ :: Resource -> <ReadGraph> Variant
132 untypedValueOf :: Resource -> <ReadGraph> Dynamic
134 @JavaName getPossibleValue
135 untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
138 inverseOf :: Resource -> <ReadGraph> Resource
139 @JavaName getPossibleInverse
140 possibleInverseOf :: Resource -> <ReadGraph> Maybe Resource
142 @JavaName getSingleType
143 singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
145 @JavaName getPossibleType
146 possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
148 "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
149 isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
150 isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
151 isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
153 getRootLibrary :: () -> <ReadGraph> Resource
155 @JavaName getPredicates
156 predicatesOf :: Resource -> <ReadGraph> [Resource]
158 isImmutable :: Resource -> <ReadGraph> Boolean
160 importJava "org.simantics.db.layer0.util.ExtendedUris" where
161 "Converts an absolute URI to a resource"
162 @JavaName resolveAbsoluteUri
163 resource :: String -> <ReadGraph> Resource
165 "Converts a relative URI to a resource starting from the given resource"
166 @JavaName resolveRelativeUri
167 relativeResource :: Resource -> String -> <ReadGraph> Resource
169 "Reads the value of a literal that is an object with the given subject and predicate"
171 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
172 relatedValue s p = relatedValue_ s p binding
175 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
176 possibleRelatedValue s p = possibleRelatedValue_ s p binding
178 class Browsable a where
179 fromUri :: String -> <ReadGraph> a
181 "Returns the URI of the given value."
182 uriOf :: a -> <ReadGraph> String
184 "Returns the URI of the given value if it exists or Nothing."
185 possibleUriOf :: a -> <ReadGraph> Maybe String
187 "Reads the name of the value."
188 nameOf :: a -> <ReadGraph> String
189 possibleNameOf :: a -> <ReadGraph> Maybe String
191 valueOf :: Serializable v => a -> <ReadGraph> v
193 genericRelatedValue :: a -> Resource -> <ReadGraph> t
194 genericPossibleRelatedValue :: a -> Resource -> <ReadGraph> Maybe t
196 variantValueOf :: a -> <ReadGraph> Variant
198 children :: a -> <ReadGraph> [a]
199 parent :: a -> <ReadGraph> a
200 possibleParent :: a -> <ReadGraph> Maybe a
202 child :: a -> String -> <ReadGraph> a
203 possibleChild :: a -> String -> <ReadGraph> Maybe a
205 instance Browsable Resource where
207 uriOf = uriOfResource
208 possibleUriOf = possibleUriOfResource
209 nameOf r = relatedValue r L0.HasName
210 possibleNameOf r = possibleRelatedValue r L0.HasName
212 valueOf r = valueOf_ r binding
213 variantValueOf = variantValueOf_
215 genericRelatedValue = relatedValue2
216 genericPossibleRelatedValue = possibleRelatedValue2
218 children r = r # L0.ConsistsOf
219 parent r = singleObject r L0.PartOf
220 possibleParent r = possibleObject r L0.PartOf
222 possibleChild = possibleResourceChild
223 child r n = fromJust (possibleResourceChild r n)
225 importJava "org.simantics.db.WriteOnlyGraph" where
226 markUndoPoint :: () -> <WriteGraph> ()
228 importJava "org.simantics.db.WriteGraph" where
229 "Creates a new resource."
230 newResource :: () -> <WriteGraph> Resource
231 "Adds a statement to the semantic graph."
232 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
234 claimWithInverse :: Resource -> Resource -> Maybe Resource -> Resource -> <WriteGraph> ()
235 @JavaName claimLiteral
236 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
237 @JavaName claimLiteral
238 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
240 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
241 @JavaName claimLiteral
242 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
243 "Removes a statement with the given subject, predicate and object"
244 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
246 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
248 denyAllStatements :: Resource -> <WriteGraph> ()
249 newClusterSet :: Resource -> <WriteGraph> ()
251 denyValue :: Resource -> <WriteGraph> ()
253 "Sets the value of the literal that is an object with the given subject and predicate."
255 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
256 claimRelatedValue s p v = claimRelatedValue_ s p v binding
259 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
260 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
262 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
263 @JavaName getPossibleChild
264 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
266 @deprecated "Use function children instead."
267 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
268 resourceChildrenOf r = r # L0.ConsistsOf
270 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
271 "`addToOrderedSet s e` adds element `e` to ordered set `s`"
273 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
275 "`addFirstToOrderedSet s e` adds element `e` to ordered set `s` as the first element"
277 addFirstToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
279 "`addAfterToOrderedSet s p e` adds element `e` to ordered set `s` after element `p`"
281 addAfterToOrderedSet :: Resource -> Resource -> Resource -> <WriteGraph> Boolean
283 "`addBeforeToOrderedSet s p e` adds element `e` to ordered set `s` before element `p`"
285 addBeforeToOrderedSet :: Resource -> Resource -> Resource -> <WriteGraph> Boolean
287 "`removeFromOrderedSet s e` removes element `e` from ordered set `s`"
289 removeFromOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
292 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
294 @JavaName getSingleOwnerList
295 parentOrderedSet :: Resource -> <ReadGraph> Resource
298 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
300 importJava "org.simantics.db.common.utils.ListUtils" where
301 "`elementsOfList l` returns elements of list `l`"
303 elementsOfList :: Resource -> <ReadGraph> [Resource]
305 "`createList [e]` creates a new list containing elements `[e]`"
307 createList :: [Resource] -> <WriteGraph> Resource
309 "`createListWithType t [e]` creates a new list with type `t` containing elements `[e]`"
311 createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
313 "`insertListBack l [e]` inserts elements `[e]` back to the list `l`"
315 insertListBack :: Resource -> [Resource] -> <WriteGraph> ()
317 "`insertListFront l [e]` inserts elements `[e]` front of the list `l`"
318 @JavaName insertFront
319 insertListFront :: Resource -> [Resource] -> <WriteGraph> ()
321 "`removeListElement l e` removes a element `e` from the list `l`"
322 @JavaName removeElement
323 removeListElement :: Resource -> Resource -> <WriteGraph> Boolean
325 @JavaName swapWithPrevious
326 swapListElementWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
328 @JavaName swapWithNext
329 swapListElementWithNext :: Resource -> Resource -> <WriteGraph> Boolean
332 importJava "org.simantics.db.common.utils.CommonDBUtils" where
333 isParent :: Resource -> Resource -> <ReadGraph> Boolean
334 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
335 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
336 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
337 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
339 importJava "org.simantics.db.common.utils.NameUtils" where
340 findFreshName :: String -> Resource -> <ReadGraph> String
341 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
343 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
344 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
345 subject # predicate = collectionToList $ objects_ subject predicate
347 "statements subject predicate` returns all statements with the given subject and predicate."
348 statements :: Resource -> Resource -> <ReadGraph> [Statement]
349 statements subject predicate = collectionToList $ statements_ subject predicate
351 importJava "org.simantics.scl.db.SCLFunctions" where
352 "Executes a read transaction and waits that it completes."
353 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
354 "Executes a write transaction and waits that it completes."
355 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
356 "Executes a delayed write transaction and waits that it completes."
357 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
359 "Begins a read transaction and immediately returns."
360 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
361 "Begins a write transaction and immediately returns."
362 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
364 virtualSyncWriteMem :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
365 virtualSyncWriteWS :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
367 safeExec :: (() -> <Proc> a) -> <Proc> a
368 activateOnce :: Resource -> <Proc> ()
369 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
370 resourceFromId :: Long -> <ReadGraph> Resource
371 enableDependencies :: () -> <WriteGraph> ()
372 disableDependencies :: () -> <WriteGraph> ()
374 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
375 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
377 "Makes a new read request with given procedure for calculating the result. The request is cached only if the current request is listened."
378 subquery :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
379 "Makes a new read request with given procedure for calculating the result. The request is always cached."
380 subqueryC :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
381 "Makes a new read asynchronous request with function to handle the request result. The last `isDisposed` function parameter is used to determine if the listener is still alive or not."
382 subqueryL :: (<ReadGraph,Proc> a) -> (a -> <ReadGraph, e> ()) -> (Throwable -> <ReadGraph, e> ()) -> (<e> Boolean) -> <ReadGraph, Proc, e> ()
383 "Tries to convert the given Dynamic value to a value with the inferred type"
384 possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a
386 importJava "org.simantics.db.layer0.util.Layer0Utils" where
387 undo :: () -> <Proc> String
388 undoOperations :: Integer -> <Proc> String
389 redo :: () -> <Proc> String
390 queryDebugSupport :: String -> <Proc> String
391 queryListSupport :: String -> <Proc> String
392 addCommentMetadata :: String -> <WriteGraph> ()
393 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
394 makeSynchronous :: Boolean -> <ReadGraph> ()
395 listOntologies :: () -> <ReadGraph> [Resource]
396 emptyTrashBin :: () -> <Proc> ()
397 purgeDatabase :: () -> <Proc> ()
398 prettyPrintResource :: Resource -> Boolean -> <ReadGraph> String
402 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
403 @JavaName getPossiblePredicateByName
404 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
405 @JavaName getPossiblePredicateByNameFromType
406 possiblePredicateByNameFromType :: Resource -> String -> <ReadGraph> Maybe Resource
408 addMetadataListener :: ChangeListener -> <Proc> ()
409 removeMetadataListener :: ChangeListener -> <Proc> ()
412 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
414 copyTo :: Resource -> Resource -> <WriteGraph> Resource
415 copyTo targetContainer source = do
416 (collectionToList $ copyTo_ targetContainer source)!0
418 importJava "org.simantics.db.common.utils.CommonDBUtils" where
419 selectClusterSet :: Resource -> <WriteGraph> ()
421 importJava "org.simantics.Simantics" where
422 @JavaName getProjectResource
423 currentProject :: () -> /*<Proc>*/ Resource
425 // Move to somewhere more generic module
426 importJava "java.util.Collection" where
429 importJava "java.util.ArrayList" where
431 collectionToList :: Collection a -> [a]
433 collectionToList :: Collection a -> [a]
434 collectionToList x = Java.unsafeCoerce x
437 resourceToCollection :: a -> Collection a
438 resourceToCollection x = Java.unsafeCoerce x
440 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
441 newEntity entitySpecs = do
442 entity = newResource ()
443 for entitySpecs (\spec -> spec entity)
446 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
447 updateEntity entity entitySpecs = do
448 for entitySpecs (\spec -> spec entity)
451 hasStatement predicate object entity =
452 claim entity predicate object
453 hasProperty relation value entity =
454 claimRelatedValue entity relation value
455 hasPossibleProperty relation value entity =
457 Just v -> claimRelatedValue entity relation v
459 hasTypedProperty relation value t entity =
460 claimRelatedValueWithType entity relation t value
461 hasName (n :: String) = hasProperty L0.HasName n
462 hasLabel (l :: String) = hasProperty L0.HasLabel l
463 hasType t = hasStatement L0.InstanceOf t
464 hasParent p = hasStatement L0.PartOf p
466 importJava "org.simantics.databoard.util.URIStringUtils" where
467 @JavaName splitURISCL
468 splitURI :: String -> [String]
470 escapeURI :: String -> String
472 unescapeURI :: String -> String
475 importJava "org.simantics.db.layer0.request.ActiveModels" where
476 @JavaName getPossibleActiveModel
477 activeModel :: Resource -> <ReadGraph> Maybe Resource
479 "Gives the current active model."
480 currentModel :: <ReadGraph> Resource
481 currentModel = match activeModel (currentProject ()) with
483 Nothing -> fail "No active model."
485 "Gives the current active model if it exists or Nothing otherwise."
486 possibleCurrentModel :: <ReadGraph> Maybe Resource
487 possibleCurrentModel = activeModel (currentProject ())
489 startUndoPoint :: String -> <WriteGraph> ()
490 startUndoPoint string = do
492 addCommentMetadata (string)
496 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
497 lift1Read f x = syncRead (\_ -> f x)
500 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
501 lift2Read f x y = syncRead (\_ -> f x y)
504 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
505 lift3Read f x y z = syncRead (\_ -> f x y z)
508 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
509 lift1Write f x = syncWrite (\_ -> f x)
512 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
513 lift2Write f x y = syncWrite (\_ -> f x y)
516 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
517 lift3Write f x y z = syncWrite (\_ -> f x y z)
520 Returns a child Browsable of the specified parent that has that is the child
521 of the specified parent with the specified name path.
523 childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a
524 childWithPath parent path =
525 foldl (\r name -> match possibleChild r name with
527 Nothing -> fail ("Didn't find " + name + ".")
532 Like `childWithPath` but returns Maybe a which will be `Nothing` if no child
535 possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a
536 possibleChildWithPath parent path =
537 foldl (\r name -> match r with
538 Just c -> possibleChild c name
543 importJava "org.simantics.db.MetadataI" where
546 importJava "org.simantics.db.event.ChangeListener" where
549 importJava "org.simantics.db.layer0.genericrelation.DependencyChanges" where
550 data DependencyChanges