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 getRelatedVariantValue2
112 relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
114 @JavaName getPossibleRelatedValue
115 possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
117 @JavaName getPossibleRelatedValue
118 untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
122 valueOf_ :: Resource -> Binding a -> <ReadGraph> a
125 @JavaName getVariantValue
126 variantValueOf_ :: Resource -> <ReadGraph> Variant
129 untypedValueOf :: Resource -> <ReadGraph> Dynamic
131 @JavaName getPossibleValue
132 untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
135 inverseOf :: Resource -> <ReadGraph> Resource
136 @JavaName getPossibleInverse
137 possibleInverseOf :: Resource -> <ReadGraph> Maybe Resource
139 @JavaName getSingleType
140 singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
142 @JavaName getPossibleType
143 possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
145 "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
146 isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
147 isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
148 isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
150 getRootLibrary :: () -> <ReadGraph> Resource
152 @JavaName getPredicates
153 predicatesOf :: Resource -> <ReadGraph> [Resource]
155 importJava "org.simantics.db.layer0.util.ExtendedUris" where
156 "Converts an absolute URI to a resource"
157 @JavaName resolveAbsoluteUri
158 resource :: String -> <ReadGraph> Resource
160 "Converts a relative URI to a resource starting from the given resource"
161 @JavaName resolveRelativeUri
162 relativeResource :: Resource -> String -> <ReadGraph> Resource
164 "Reads the value of a literal that is an object with the given subject and predicate"
166 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
167 relatedValue s p = relatedValue_ s p binding
170 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
171 possibleRelatedValue s p = possibleRelatedValue_ s p binding
173 class Browsable a where
174 fromUri :: String -> <ReadGraph> a
176 "Returns the URI of the given value."
177 uriOf :: a -> <ReadGraph> String
179 "Returns the URI of the given value if it exists or Nothing."
180 possibleUriOf :: a -> <ReadGraph> Maybe String
182 "Reads the name of the value."
183 nameOf :: a -> <ReadGraph> String
184 possibleNameOf :: a -> <ReadGraph> Maybe String
186 valueOf :: Serializable v => a -> <ReadGraph> v
188 variantValueOf :: a -> <ReadGraph> Variant
190 children :: a -> <ReadGraph> [a]
191 parent :: a -> <ReadGraph> a
192 possibleParent :: a -> <ReadGraph> Maybe a
194 child :: a -> String -> <ReadGraph> a
195 possibleChild :: a -> String -> <ReadGraph> Maybe a
197 instance Browsable Resource where
199 uriOf = uriOfResource
200 possibleUriOf = possibleUriOfResource
201 nameOf r = relatedValue r L0.HasName
202 possibleNameOf r = possibleRelatedValue r L0.HasName
204 valueOf r = valueOf_ r binding
205 variantValueOf = variantValueOf_
207 children r = r # L0.ConsistsOf
208 parent r = singleObject r L0.PartOf
209 possibleParent r = possibleObject r L0.PartOf
211 possibleChild = possibleResourceChild
212 child r n = fromJust (possibleResourceChild r n)
214 importJava "org.simantics.db.WriteOnlyGraph" where
215 markUndoPoint :: () -> <WriteGraph> ()
217 importJava "org.simantics.db.WriteGraph" where
218 "Creates a new resource."
219 newResource :: () -> <WriteGraph> Resource
220 "Adds a statement to the semantic graph."
221 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
223 claimWithInverse :: Resource -> Resource -> Maybe Resource -> Resource -> <WriteGraph> ()
224 @JavaName claimLiteral
225 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
226 @JavaName claimLiteral
227 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
229 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
230 @JavaName claimLiteral
231 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
232 "Removes a statement with the given subject, predicate and object"
233 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
235 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
237 denyAllStatements :: Resource -> <WriteGraph> ()
238 newClusterSet :: Resource -> <WriteGraph> ()
240 denyValue :: Resource -> <WriteGraph> ()
242 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
243 claimAssertion type_ predicate object = do
245 claim ass L0.HasPredicate predicate
246 claim ass L0.HasObject object
247 claim type_ L0.Asserts ass
249 "Sets the value of the literal that is an object with the given subject and predicate."
251 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
252 claimRelatedValue s p v = claimRelatedValue_ s p v binding
255 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
256 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
258 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
259 @JavaName getPossibleChild
260 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
262 @deprecated "Use function children instead."
263 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
264 resourceChildrenOf r = r # L0.ConsistsOf
266 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
268 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
271 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
273 @JavaName getSingleOwnerList
274 parentOrderedSet :: Resource -> <ReadGraph> Resource
277 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
279 importJava "org.simantics.db.common.utils.ListUtils" where
281 elementsOfList :: Resource -> <ReadGraph> [Resource]
284 createList :: [Resource] -> <WriteGraph> Resource
287 createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
290 insertBack :: Resource -> [Resource] -> <WriteGraph> ()
292 @javaName removeElement
293 removeElement :: Resource -> Resource -> <WriteGraph> Boolean
295 @javaName swapWithPrevious
296 swapWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
298 @javaName swapWithNext
299 swapWithNext :: Resource -> Resource -> <WriteGraph> Boolean
302 importJava "org.simantics.db.common.utils.CommonDBUtils" where
303 isParent :: Resource -> Resource -> <ReadGraph> Boolean
304 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
305 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
306 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
307 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
309 importJava "org.simantics.db.common.utils.NameUtils" where
310 findFreshName :: String -> Resource -> <ReadGraph> String
311 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
313 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
314 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
315 subject # predicate = collectionToList $ objects_ subject predicate
317 "statements subject predicate` returns all statements with the given subject and predicate."
318 statements :: Resource -> Resource -> <ReadGraph> [Statement]
319 statements subject predicate = collectionToList $ statements_ subject predicate
321 importJava "org.simantics.scl.db.SCLFunctions" where
322 "Executes a read transaction and waits that it completes."
323 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
324 "Executes a write transaction and waits that it completes."
325 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
326 "Executes a delayed write transaction and waits that it completes."
327 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
329 "Begins a read transaction and immediately returns."
330 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
331 "Begins a write transaction and immediately returns."
332 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
334 virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
335 virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
337 safeExec :: (() -> <Proc> a) -> <Proc> a
338 activateOnce :: Resource -> <Proc> ()
339 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
340 resourceFromId :: Long -> <ReadGraph> Resource
341 enableDependencies :: () -> <WriteGraph> ()
342 disableDependencies :: () -> <WriteGraph> ()
344 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
345 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
347 "Makes a new read request with given procedure for calculating the result. The request is cached only if the current request is listened."
348 subquery :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
349 "Makes a new read request with given procedure for calculating the result. The request is always cached."
350 subqueryC :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
351 "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."
352 subqueryL :: (<ReadGraph,Proc> a) -> (a -> <ReadGraph, e> ()) -> (Throwable -> <ReadGraph, e> ()) -> (<e> Boolean) -> <ReadGraph, Proc, e> ()
353 "Tries to convert the given Dynamic value to a value with the inferred type"
354 possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a
356 importJava "org.simantics.db.layer0.util.Layer0Utils" where
357 undo :: () -> <Proc> String
358 undoOperations :: Integer -> <Proc> String
359 redo :: () -> <Proc> String
360 queryDebugSupport :: String -> <Proc> String
361 queryListSupport :: String -> <Proc> String
362 addCommentMetadata :: String -> <WriteGraph> ()
363 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
364 makeSynchronous :: Boolean -> <ReadGraph> ()
365 listOntologies :: () -> <ReadGraph> [Resource]
366 emptyTrashBin :: () -> <Proc> ()
367 purgeDatabase :: () -> <Proc> ()
368 prettyPrintResource :: Resource -> Boolean -> <ReadGraph> String
372 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
373 @JavaName getPossiblePredicateByName
374 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
375 @JavaName getPossiblePredicateByNameFromType
376 possiblePredicateByNameFromType :: Resource -> String -> <ReadGraph> Maybe Resource
378 addMetadataListener :: ChangeListener -> <Proc> ()
379 removeMetadataListener :: ChangeListener -> <Proc> ()
381 copyTo :: Resource -> Resource -> <WriteGraph> Resource
382 copyTo targetContainer source = do
383 (collectionToList $ copyTo_ targetContainer source)!0
385 importJava "org.simantics.db.common.utils.CommonDBUtils" where
386 selectClusterSet :: Resource -> <WriteGraph> ()
388 importJava "org.simantics.Simantics" where
389 @JavaName getProjectResource
390 currentProject :: () -> /*<Proc>*/ Resource
392 // Move to somewhere more generic module
393 importJava "java.util.Collection" where
396 importJava "java.util.ArrayList" where
398 collectionToList :: Collection a -> [a]
400 collectionToList :: Collection a -> [a]
401 collectionToList x = Java.unsafeCoerce x
404 resourceToCollection :: a -> Collection a
405 resourceToCollection x = Java.unsafeCoerce x
407 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
408 newEntity entitySpecs = do
409 entity = newResource ()
410 for entitySpecs (\spec -> spec entity)
413 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
414 updateEntity entity entitySpecs = do
415 for entitySpecs (\spec -> spec entity)
418 hasStatement predicate object entity =
419 claim entity predicate object
420 hasProperty relation value entity =
421 claimRelatedValue entity relation value
422 hasPossibleProperty relation value entity =
424 Just v -> claimRelatedValue entity relation v
426 hasTypedProperty relation value t entity =
427 claimRelatedValueWithType entity relation t value
428 hasName (n :: String) = hasProperty L0.HasName n
429 hasLabel (l :: String) = hasProperty L0.HasLabel l
430 hasType t = hasStatement L0.InstanceOf t
431 hasParent p = hasStatement L0.PartOf p
433 importJava "org.simantics.databoard.util.URIStringUtils" where
434 @JavaName splitURISCL
435 splitURI :: String -> [String]
437 escapeURI :: String -> String
439 unescapeURI :: String -> String
442 importJava "org.simantics.db.layer0.request.ActiveModels" where
443 @JavaName getPossibleActiveModel
444 activeModel :: Resource -> <ReadGraph> Maybe Resource
446 "Gives the current active model."
447 currentModel :: <ReadGraph> Resource
448 currentModel = match activeModel (currentProject ()) with
450 Nothing -> fail "No active model."
452 "Gives the current active model if it exists or Nothing otherwise."
453 possibleCurrentModel :: <ReadGraph> Maybe Resource
454 possibleCurrentModel = activeModel (currentProject ())
456 startUndoPoint :: String -> <WriteGraph> ()
457 startUndoPoint string = do
459 addCommentMetadata (string)
463 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
464 lift1Read f x = syncRead (\_ -> f x)
467 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
468 lift2Read f x y = syncRead (\_ -> f x y)
471 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
472 lift3Read f x y z = syncRead (\_ -> f x y z)
475 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
476 lift1Write f x = syncWrite (\_ -> f x)
479 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
480 lift2Write f x y = syncWrite (\_ -> f x y)
483 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
484 lift3Write f x y z = syncWrite (\_ -> f x y z)
487 Returns a child Browsable of the specified parent that has that is the child
488 of the specified parent with the specified name path.
490 childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a
491 childWithPath parent path =
492 foldl (\r name -> match possibleChild r name with
494 Nothing -> fail ("Didn't find " + name + ".")
499 Like `childWithPath` but returns Maybe a which will be `Nothing` if no child
502 possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a
503 possibleChildWithPath parent path =
504 foldl (\r name -> match r with
505 Just c -> possibleChild c name
510 importJava "org.simantics.db.MetadataI" where
513 importJava "org.simantics.db.event.ChangeListener" where
516 importJava "org.simantics.db.layer0.genericrelation.DependencyChanges" where
517 data DependencyChanges