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 isImmutable :: Resource -> <ReadGraph> Boolean
157 importJava "org.simantics.db.layer0.util.ExtendedUris" where
158 "Converts an absolute URI to a resource"
159 @JavaName resolveAbsoluteUri
160 resource :: String -> <ReadGraph> Resource
162 "Converts a relative URI to a resource starting from the given resource"
163 @JavaName resolveRelativeUri
164 relativeResource :: Resource -> String -> <ReadGraph> Resource
166 "Reads the value of a literal that is an object with the given subject and predicate"
168 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
169 relatedValue s p = relatedValue_ s p binding
172 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
173 possibleRelatedValue s p = possibleRelatedValue_ s p binding
175 class Browsable a where
176 fromUri :: String -> <ReadGraph> a
178 "Returns the URI of the given value."
179 uriOf :: a -> <ReadGraph> String
181 "Returns the URI of the given value if it exists or Nothing."
182 possibleUriOf :: a -> <ReadGraph> Maybe String
184 "Reads the name of the value."
185 nameOf :: a -> <ReadGraph> String
186 possibleNameOf :: a -> <ReadGraph> Maybe String
188 valueOf :: Serializable v => a -> <ReadGraph> v
190 variantValueOf :: a -> <ReadGraph> Variant
192 children :: a -> <ReadGraph> [a]
193 parent :: a -> <ReadGraph> a
194 possibleParent :: a -> <ReadGraph> Maybe a
196 child :: a -> String -> <ReadGraph> a
197 possibleChild :: a -> String -> <ReadGraph> Maybe a
199 instance Browsable Resource where
201 uriOf = uriOfResource
202 possibleUriOf = possibleUriOfResource
203 nameOf r = relatedValue r L0.HasName
204 possibleNameOf r = possibleRelatedValue r L0.HasName
206 valueOf r = valueOf_ r binding
207 variantValueOf = variantValueOf_
209 children r = r # L0.ConsistsOf
210 parent r = singleObject r L0.PartOf
211 possibleParent r = possibleObject r L0.PartOf
213 possibleChild = possibleResourceChild
214 child r n = fromJust (possibleResourceChild r n)
216 importJava "org.simantics.db.WriteOnlyGraph" where
217 markUndoPoint :: () -> <WriteGraph> ()
219 importJava "org.simantics.db.WriteGraph" where
220 "Creates a new resource."
221 newResource :: () -> <WriteGraph> Resource
222 "Adds a statement to the semantic graph."
223 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
225 claimWithInverse :: Resource -> Resource -> Maybe Resource -> Resource -> <WriteGraph> ()
226 @JavaName claimLiteral
227 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
228 @JavaName claimLiteral
229 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
231 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
232 @JavaName claimLiteral
233 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
234 "Removes a statement with the given subject, predicate and object"
235 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
237 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
239 denyAllStatements :: Resource -> <WriteGraph> ()
240 newClusterSet :: Resource -> <WriteGraph> ()
242 denyValue :: Resource -> <WriteGraph> ()
244 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
245 claimAssertion type_ predicate object = do
247 claim ass L0.HasPredicate predicate
248 claim ass L0.HasObject object
249 claim type_ L0.Asserts ass
251 "Sets the value of the literal that is an object with the given subject and predicate."
253 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
254 claimRelatedValue s p v = claimRelatedValue_ s p v binding
257 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
258 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
260 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
261 @JavaName getPossibleChild
262 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
264 @deprecated "Use function children instead."
265 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
266 resourceChildrenOf r = r # L0.ConsistsOf
268 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
270 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
273 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
275 @JavaName getSingleOwnerList
276 parentOrderedSet :: Resource -> <ReadGraph> Resource
279 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
281 importJava "org.simantics.db.common.utils.ListUtils" where
283 elementsOfList :: Resource -> <ReadGraph> [Resource]
286 createList :: [Resource] -> <WriteGraph> Resource
289 createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
292 insertBack :: Resource -> [Resource] -> <WriteGraph> ()
294 @javaName removeElement
295 removeElement :: Resource -> Resource -> <WriteGraph> Boolean
297 @javaName swapWithPrevious
298 swapWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
300 @javaName swapWithNext
301 swapWithNext :: Resource -> Resource -> <WriteGraph> Boolean
304 importJava "org.simantics.db.common.utils.CommonDBUtils" where
305 isParent :: Resource -> Resource -> <ReadGraph> Boolean
306 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
307 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
308 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
309 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
311 importJava "org.simantics.db.common.utils.NameUtils" where
312 findFreshName :: String -> Resource -> <ReadGraph> String
313 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
315 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
316 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
317 subject # predicate = collectionToList $ objects_ subject predicate
319 "statements subject predicate` returns all statements with the given subject and predicate."
320 statements :: Resource -> Resource -> <ReadGraph> [Statement]
321 statements subject predicate = collectionToList $ statements_ subject predicate
323 importJava "org.simantics.scl.db.SCLFunctions" where
324 "Executes a read transaction and waits that it completes."
325 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
326 "Executes a write transaction and waits that it completes."
327 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
328 "Executes a delayed write transaction and waits that it completes."
329 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
331 "Begins a read transaction and immediately returns."
332 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
333 "Begins a write transaction and immediately returns."
334 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
336 virtualSyncWriteMem :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
337 virtualSyncWriteWS :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
339 safeExec :: (() -> <Proc> a) -> <Proc> a
340 activateOnce :: Resource -> <Proc> ()
341 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
342 resourceFromId :: Long -> <ReadGraph> Resource
343 enableDependencies :: () -> <WriteGraph> ()
344 disableDependencies :: () -> <WriteGraph> ()
346 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
347 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
349 "Makes a new read request with given procedure for calculating the result. The request is cached only if the current request is listened."
350 subquery :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
351 "Makes a new read request with given procedure for calculating the result. The request is always cached."
352 subqueryC :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
353 "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."
354 subqueryL :: (<ReadGraph,Proc> a) -> (a -> <ReadGraph, e> ()) -> (Throwable -> <ReadGraph, e> ()) -> (<e> Boolean) -> <ReadGraph, Proc, e> ()
355 "Tries to convert the given Dynamic value to a value with the inferred type"
356 possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a
358 importJava "org.simantics.db.layer0.util.Layer0Utils" where
359 undo :: () -> <Proc> String
360 undoOperations :: Integer -> <Proc> String
361 redo :: () -> <Proc> String
362 queryDebugSupport :: String -> <Proc> String
363 queryListSupport :: String -> <Proc> String
364 addCommentMetadata :: String -> <WriteGraph> ()
365 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
366 makeSynchronous :: Boolean -> <ReadGraph> ()
367 listOntologies :: () -> <ReadGraph> [Resource]
368 emptyTrashBin :: () -> <Proc> ()
369 purgeDatabase :: () -> <Proc> ()
370 prettyPrintResource :: Resource -> Boolean -> <ReadGraph> String
374 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
375 @JavaName getPossiblePredicateByName
376 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
377 @JavaName getPossiblePredicateByNameFromType
378 possiblePredicateByNameFromType :: Resource -> String -> <ReadGraph> Maybe Resource
380 addMetadataListener :: ChangeListener -> <Proc> ()
381 removeMetadataListener :: ChangeListener -> <Proc> ()
383 copyTo :: Resource -> Resource -> <WriteGraph> Resource
384 copyTo targetContainer source = do
385 (collectionToList $ copyTo_ targetContainer source)!0
387 importJava "org.simantics.db.common.utils.CommonDBUtils" where
388 selectClusterSet :: Resource -> <WriteGraph> ()
390 importJava "org.simantics.Simantics" where
391 @JavaName getProjectResource
392 currentProject :: () -> /*<Proc>*/ Resource
394 // Move to somewhere more generic module
395 importJava "java.util.Collection" where
398 importJava "java.util.ArrayList" where
400 collectionToList :: Collection a -> [a]
402 collectionToList :: Collection a -> [a]
403 collectionToList x = Java.unsafeCoerce x
406 resourceToCollection :: a -> Collection a
407 resourceToCollection x = Java.unsafeCoerce x
409 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
410 newEntity entitySpecs = do
411 entity = newResource ()
412 for entitySpecs (\spec -> spec entity)
415 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
416 updateEntity entity entitySpecs = do
417 for entitySpecs (\spec -> spec entity)
420 hasStatement predicate object entity =
421 claim entity predicate object
422 hasProperty relation value entity =
423 claimRelatedValue entity relation value
424 hasPossibleProperty relation value entity =
426 Just v -> claimRelatedValue entity relation v
428 hasTypedProperty relation value t entity =
429 claimRelatedValueWithType entity relation t value
430 hasName (n :: String) = hasProperty L0.HasName n
431 hasLabel (l :: String) = hasProperty L0.HasLabel l
432 hasType t = hasStatement L0.InstanceOf t
433 hasParent p = hasStatement L0.PartOf p
435 importJava "org.simantics.databoard.util.URIStringUtils" where
436 @JavaName splitURISCL
437 splitURI :: String -> [String]
439 escapeURI :: String -> String
441 unescapeURI :: String -> String
444 importJava "org.simantics.db.layer0.request.ActiveModels" where
445 @JavaName getPossibleActiveModel
446 activeModel :: Resource -> <ReadGraph> Maybe Resource
448 "Gives the current active model."
449 currentModel :: <ReadGraph> Resource
450 currentModel = match activeModel (currentProject ()) with
452 Nothing -> fail "No active model."
454 "Gives the current active model if it exists or Nothing otherwise."
455 possibleCurrentModel :: <ReadGraph> Maybe Resource
456 possibleCurrentModel = activeModel (currentProject ())
458 startUndoPoint :: String -> <WriteGraph> ()
459 startUndoPoint string = do
461 addCommentMetadata (string)
465 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
466 lift1Read f x = syncRead (\_ -> f x)
469 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
470 lift2Read f x y = syncRead (\_ -> f x y)
473 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
474 lift3Read f x y z = syncRead (\_ -> f x y z)
477 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
478 lift1Write f x = syncWrite (\_ -> f x)
481 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
482 lift2Write f x y = syncWrite (\_ -> f x y)
485 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
486 lift3Write f x y z = syncWrite (\_ -> f x y z)
489 Returns a child Browsable of the specified parent that has that is the child
490 of the specified parent with the specified name path.
492 childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a
493 childWithPath parent path =
494 foldl (\r name -> match possibleChild r name with
496 Nothing -> fail ("Didn't find " + name + ".")
501 Like `childWithPath` but returns Maybe a which will be `Nothing` if no child
504 possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a
505 possibleChildWithPath parent path =
506 foldl (\r name -> match r with
507 Just c -> possibleChild c name
512 importJava "org.simantics.db.MetadataI" where
515 importJava "org.simantics.db.event.ChangeListener" where
518 importJava "org.simantics.db.layer0.genericrelation.DependencyChanges" where
519 data DependencyChanges