1 import "JavaBuiltin" as Java
\r
2 include "http://www.simantics.org/Layer0-1.1" as L0
\r
8 "org.simantics.db.ReadGraph"
\r
12 "org.simantics.db.WriteGraph"
\r
14 importJava "org.simantics.databoard.type.Datatype" where
\r
17 showDatatype :: Datatype -> String
\r
19 instance Show Datatype where
\r
22 importJava "org.simantics.databoard.Bindings" where
\r
23 @JavaName getBinding
\r
24 datatypeBinding :: Datatype -> Binding Dynamic
\r
26 importJava "org.simantics.databoard.binding.mutable.Variant" where
\r
28 createVariant_ :: Binding Dynamic -> Dynamic -> Variant
\r
30 variantDatatype :: Variant -> Datatype
\r
32 createVariant :: Datatype -> Dynamic -> Variant
\r
33 createVariant dt v = createVariant_ (datatypeBinding dt) v
\r
35 importJava "org.simantics.databoard.Datatypes" where
\r
37 translateDatatype :: String -> Datatype
\r
39 importJava "org.simantics.db.Resource" where
\r
40 "A resource is a node in a semantic graph."
\r
43 "Returns the 64-bit unique identifier of the resource."
\r
44 @JavaName getResourceId
\r
45 resourceId :: Resource -> Long
\r
47 importJava "org.simantics.db.ReadGraph" where
\r
50 importJava "java.lang.Object" where
\r
52 resourceEquals :: Resource -> Resource -> Boolean
\r
54 resourceHash :: Resource -> Integer
\r
56 instance Eq Resource where
\r
57 (==) = resourceEquals
\r
59 instance Ord Resource where
\r
60 compare a b = compare (resourceId a) (resourceId b)
\r
62 instance Hashable Resource where
\r
63 hashP = hashP . resourceHash
\r
65 instance Show Resource where
\r
66 show r = "#" + show (resourceId r)
\r
68 instance Show Statement where
\r
69 show s = "#" + show (resourceId ( subjectOf s)) + "#" + show (resourceId ( predicateOf s)) + "#" + show (resourceId ( objectOf s))
\r
71 importJava "org.simantics.db.Statement" where
\r
72 "A statement is an edge in a semantic graph."
\r
75 @JavaName getSubject
\r
76 subjectOf :: Statement -> Resource
\r
77 @JavaName getPredicate
\r
78 predicateOf :: Statement -> Resource
\r
80 objectOf :: Statement -> Resource
\r
82 importJava "org.simantics.db.ReadGraph" where
\r
83 "Converts an absolute URI to a resource or returns `Nothing` if there is no such resource."
\r
84 @JavaName getPossibleResource
\r
85 possibleResource :: String -> <ReadGraph> (Maybe Resource)
\r
87 getDataType :: Resource -> <ReadGraph> Datatype
\r
89 @JavaName getSupertypes
\r
90 superTypesOf :: Resource -> <ReadGraph> Set.T Resource
\r
94 uriOfResource :: Resource -> <ReadGraph> String
\r
96 @JavaName getObjects
\r
97 objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
\r
99 @JavaName getStatements
\r
100 statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement
\r
102 @JavaName hasStatement
\r
103 existsStatement :: Resource -> Resource -> <ReadGraph> Boolean
\r
105 @JavaName hasStatement
\r
106 existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean
\r
108 "Assumes that there is exactly one object with the given subject and predicate and returns it."
\r
109 @JavaName getSingleObject
\r
110 singleObject :: Resource -> Resource -> <ReadGraph> Resource
\r
113 If there is exactly one object with the given `subject` and `predicate`,
\r
114 `possibleObject subject predicate` returns it. Otherwise, it returns
\r
117 @JavaName getPossibleObject
\r
118 possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
120 "Assumes that there is exactly one statement with the given subject and predicate and returns it."
\r
121 @JavaName getSingleStatement
\r
122 singleStatement :: Resource -> Resource -> <ReadGraph> Statement
\r
124 @JavaName getRelatedVariantValue
\r
125 relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
\r
127 @JavaName getRelatedValue
\r
128 relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a
\r
130 @JavaName getRelatedValue
\r
131 untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a
\r
133 @JavaName getRelatedValue2
\r
134 relatedValue2 :: Resource -> Resource -> <ReadGraph> a
\r
136 @JavaName getRelatedVariantValue2
\r
137 relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
\r
139 @JavaName getPossibleRelatedValue
\r
140 possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
\r
142 @JavaName getPossibleRelatedValue
\r
143 untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
\r
147 valueOf_ :: Resource -> Binding a -> <ReadGraph> a
\r
150 @JavaName getVariantValue
\r
151 variantValueOf_ :: Resource -> <ReadGraph> Variant
\r
154 untypedValueOf :: Resource -> <ReadGraph> Dynamic
\r
156 @JavaName getPossibleValue
\r
157 untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
\r
159 @JavaName getInverse
\r
160 inverseOf :: Resource -> <ReadGraph> Resource
\r
162 @JavaName getSingleType
\r
163 singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
\r
165 @JavaName getPossibleType
\r
166 possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
168 "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
\r
169 isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
170 isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
171 isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
\r
173 getRootLibrary :: () -> <ReadGraph> Resource
\r
175 importJava "org.simantics.db.layer0.util.ExtendedUris" where
\r
176 "Converts an absolute URI to a resource"
\r
177 @JavaName resolveAbsoluteUri
\r
178 resource :: String -> <ReadGraph> Resource
\r
180 "Converts a relative URI to a resource starting from the given resource"
\r
181 @JavaName resolveRelativeUri
\r
182 relativeResource :: Resource -> String -> <ReadGraph> Resource
\r
184 "Reads the value of a literal that is an object with the given subject and predicate"
\r
186 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
\r
187 relatedValue s p = relatedValue_ s p binding
\r
190 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
\r
191 possibleRelatedValue s p = possibleRelatedValue_ s p binding
\r
193 class Browsable a where
\r
194 fromUri :: String -> <ReadGraph> a
\r
196 "Returns the URI of the given value."
\r
197 uriOf :: a -> <ReadGraph> String
\r
199 "Reads the name of the value."
\r
200 nameOf :: a -> <ReadGraph> String
\r
201 possibleNameOf :: a -> <ReadGraph> Maybe String
\r
203 valueOf :: Serializable v => a -> <ReadGraph> v
\r
205 variantValueOf :: a -> <ReadGraph> Variant
\r
207 children :: a -> <ReadGraph> [a]
\r
208 parent :: a -> <ReadGraph> a
\r
209 possibleParent :: a -> <ReadGraph> Maybe a
\r
211 child :: a -> String -> <ReadGraph> a
\r
212 possibleChild :: a -> String -> <ReadGraph> Maybe a
\r
214 instance Browsable Resource where
\r
216 uriOf = uriOfResource
\r
217 nameOf r = relatedValue r L0.HasName
\r
218 possibleNameOf r = possibleRelatedValue r L0.HasName
\r
220 valueOf r = valueOf_ r binding
\r
221 variantValueOf = variantValueOf_
\r
223 children r = r # L0.ConsistsOf
\r
224 parent r = singleObject r L0.PartOf
\r
225 possibleParent r = possibleObject r L0.PartOf
\r
227 possibleChild = possibleResourceChild
\r
228 child r n = fromJust (possibleResourceChild r n)
\r
230 importJava "org.simantics.db.WriteOnlyGraph" where
\r
231 markUndoPoint :: () -> <WriteGraph> ()
\r
233 importJava "org.simantics.db.WriteGraph" where
\r
234 "Creates a new resource."
\r
235 newResource :: () -> <WriteGraph> Resource
\r
236 "Adds a statement to the semantic graph."
\r
237 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
238 @JavaName claimLiteral
\r
239 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
240 @JavaName claimLiteral
\r
241 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
\r
242 @JavaName claimValue
\r
243 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
\r
244 @JavaName claimLiteral
\r
245 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
246 "Removes a statement with the given subject, predicate and object"
\r
247 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
249 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
\r
251 denyAllStatements :: Resource -> <WriteGraph> ()
\r
252 newClusterSet :: Resource -> <WriteGraph> ()
\r
253 @JavaName denyValue
\r
254 denyValue :: Resource -> <WriteGraph> ()
\r
256 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
257 claimAssertion type_ predicate object = do
\r
258 ass = newResource ()
\r
259 claim ass L0.HasPredicate predicate
\r
260 claim ass L0.HasObject object
\r
261 claim type_ L0.Asserts ass
\r
263 "Sets the value of the literal that is an object with the given subject and predicate."
\r
265 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
\r
266 claimRelatedValue s p v = claimRelatedValue_ s p v binding
\r
269 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
\r
270 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
\r
272 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
\r
273 @JavaName getPossibleChild
\r
274 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
\r
276 @deprecated "Use function children instead."
\r
277 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
\r
278 resourceChildrenOf r = r # L0.ConsistsOf
\r
280 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
\r
282 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
\r
285 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
\r
287 @JavaName getSingleOwnerList
\r
288 parentOrderedSet :: Resource -> <ReadGraph> Resource
\r
291 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
\r
293 importJava "org.simantics.db.common.utils.ListUtils" where
\r
295 elementsOfList :: Resource -> <ReadGraph> [Resource]
\r
297 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
298 isParent :: Resource -> Resource -> <ReadGraph> Boolean
\r
299 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
\r
300 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
\r
301 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
\r
302 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
\r
304 importJava "org.simantics.db.common.utils.NameUtils" where
\r
305 findFreshName :: String -> Resource -> <ReadGraph> String
\r
306 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
\r
308 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
\r
309 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
\r
310 subject # predicate = collectionToList $ objects_ subject predicate
\r
312 "statements subject predicate` returns all statements with the given subject and predicate."
\r
313 statements :: Resource -> Resource -> <ReadGraph> [Statement]
\r
314 statements subject predicate = collectionToList $ statements_ subject predicate
\r
316 importJava "org.simantics.scl.db.SCLFunctions" where
\r
317 "Executes a read transaction and waits that it completes."
\r
318 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
\r
319 "Executes a write transaction and waits that it completes."
\r
320 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
\r
321 "Executes a delayed write transaction and waits that it completes."
\r
322 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
\r
324 "Begins a read transaction and immediately returns."
\r
325 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
\r
326 "Begins a write transaction and immediately returns."
\r
327 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
\r
329 virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
330 virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
332 safeExec :: (() -> <Proc> a) -> <Proc> a
\r
333 activateOnce :: Resource -> <Proc> ()
\r
334 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
\r
335 resourceFromId :: Long -> <ReadGraph> Resource
\r
336 enableDependencies :: () -> <WriteGraph> ()
\r
337 disableDependencies :: () -> <WriteGraph> ()
\r
339 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
340 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
342 importJava "org.simantics.db.layer0.util.Layer0Utils" where
\r
343 undo :: () -> <Proc> String
\r
344 undoOperations :: Integer -> <Proc> String
\r
345 redo :: () -> <Proc> String
\r
346 queryDebugSupport :: String -> <Proc> String
\r
347 queryListSupport :: String -> <Proc> String
\r
348 addCommentMetadata :: String -> <WriteGraph> ()
\r
349 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
\r
350 makeSynchronous :: Boolean -> <ReadGraph> ()
\r
351 listOntologies :: () -> <ReadGraph> [Resource]
\r
355 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
\r
356 @JavaName getPossiblePredicateByName
\r
357 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
\r
359 copyTo :: Resource -> Resource -> <WriteGraph> Resource
\r
360 copyTo targetContainer source = do
\r
361 (collectionToList $ copyTo_ targetContainer source)!0
\r
363 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
364 selectClusterSet :: Resource -> <WriteGraph> ()
\r
366 importJava "org.simantics.Simantics" where
\r
367 @JavaName getProjectResource
\r
368 currentProject :: () -> /*<Proc>*/ Resource
\r
370 // Move to somewhere more generic module
\r
371 importJava "java.util.Collection" where
\r
374 importJava "java.util.ArrayList" where
\r
376 collectionToList :: Collection a -> [a]
\r
378 collectionToList :: Collection a -> [a]
\r
379 collectionToList x = Java.unsafeCoerce x
\r
382 resourceToCollection :: a -> Collection a
\r
383 resourceToCollection x = Java.unsafeCoerce x
\r
385 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
386 newEntity entitySpecs = do
\r
387 entity = newResource ()
\r
388 for entitySpecs (\spec -> spec entity)
\r
391 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
392 updateEntity entity entitySpecs = do
\r
393 for entitySpecs (\spec -> spec entity)
\r
396 hasStatement predicate object entity =
\r
397 claim entity predicate object
\r
398 hasProperty relation value entity =
\r
399 claimRelatedValue entity relation value
\r
400 hasPossibleProperty relation value entity =
\r
402 Just v -> claimRelatedValue entity relation v
\r
404 hasTypedProperty relation value t entity =
\r
405 claimRelatedValueWithType entity relation t value
\r
406 hasName (n :: String) = hasProperty L0.HasName n
\r
407 hasLabel (l :: String) = hasProperty L0.HasLabel l
\r
408 hasType t = hasStatement L0.InstanceOf t
\r
409 hasParent p = hasStatement L0.PartOf p
\r
411 importJava "org.simantics.databoard.util.URIStringUtils" where
\r
412 @JavaName splitURISCL
\r
413 splitURI :: String -> [String]
\r
415 escapeURI :: String -> String
\r
417 unescapeURI :: String -> String
\r
420 importJava "org.simantics.db.layer0.request.ActiveModels" where
\r
421 @JavaName getPossibleActiveModel
\r
422 activeModel :: Resource -> <ReadGraph> Maybe Resource
\r
424 "Gives the current active model."
\r
425 currentModel :: <ReadGraph> Resource
\r
426 currentModel = match activeModel (currentProject ()) with
\r
427 Just model -> model
\r
428 Nothing -> fail "No active model."
\r
430 startUndoPoint :: String -> <WriteGraph> ()
\r
431 startUndoPoint string = do
\r
433 addCommentMetadata (string)
\r
437 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
\r
438 lift1Read f x = syncRead (\_ -> f x)
\r
441 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
442 lift2Read f x y = syncRead (\_ -> f x y)
\r
445 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
446 lift3Read f x y z = syncRead (\_ -> f x y z)
\r
449 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
\r
450 lift1Write f x = syncWrite (\_ -> f x)
\r
453 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
454 lift2Write f x y = syncWrite (\_ -> f x y)
\r
457 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
458 lift3Write f x y z = syncWrite (\_ -> f x y z)