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
91 uriOfResource :: Resource -> <ReadGraph> String
\r
93 @JavaName getObjects
\r
94 objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
\r
96 @JavaName getStatements
\r
97 statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement
\r
99 @JavaName hasStatement
\r
100 existsStatement :: Resource -> Resource -> <ReadGraph> Boolean
\r
102 @JavaName hasStatement
\r
103 existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean
\r
105 "Assumes that there is exactly one object with the given subject and predicate and returns it."
\r
106 @JavaName getSingleObject
\r
107 singleObject :: Resource -> Resource -> <ReadGraph> Resource
\r
110 If there is exactly one object with the given `subject` and `predicate`,
\r
111 `possibleObject subject predicate` returns it. Otherwise, it returns
\r
114 @JavaName getPossibleObject
\r
115 possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
117 "Assumes that there is exactly one statement with the given subject and predicate and returns it."
\r
118 @JavaName getSingleStatement
\r
119 singleStatement :: Resource -> Resource -> <ReadGraph> Statement
\r
121 @JavaName getRelatedVariantValue
\r
122 relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
\r
124 @JavaName getRelatedValue
\r
125 relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a
\r
127 @JavaName getRelatedValue
\r
128 untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a
\r
130 @JavaName getRelatedValue2
\r
131 relatedValue2 :: Resource -> Resource -> <ReadGraph> a
\r
133 @JavaName getRelatedVariantValue2
\r
134 relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
\r
136 @JavaName getPossibleRelatedValue
\r
137 possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
\r
139 @JavaName getPossibleRelatedValue
\r
140 untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
\r
144 valueOf_ :: Resource -> Binding a -> <ReadGraph> a
\r
147 @JavaName getVariantValue
\r
148 variantValueOf_ :: Resource -> <ReadGraph> Variant
\r
151 untypedValueOf :: Resource -> <ReadGraph> Dynamic
\r
153 @JavaName getPossibleValue
\r
154 untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
\r
156 @JavaName getInverse
\r
157 inverseOf :: Resource -> <ReadGraph> Resource
\r
159 @JavaName getSingleType
\r
160 singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
\r
162 @JavaName getPossibleType
\r
163 possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
165 "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
\r
166 isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
167 isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
168 isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
\r
170 getRootLibrary :: () -> <ReadGraph> Resource
\r
172 importJava "org.simantics.db.layer0.util.ExtendedUris" where
\r
173 "Converts an absolute URI to a resource"
\r
174 @JavaName resolveAbsoluteUri
\r
175 resource :: String -> <ReadGraph> Resource
\r
177 "Converts a relative URI to a resource starting from the given resource"
\r
178 @JavaName resolveRelativeUri
\r
179 relativeResource :: Resource -> String -> <ReadGraph> Resource
\r
181 "Reads the value of a literal that is an object with the given subject and predicate"
\r
183 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
\r
184 relatedValue s p = relatedValue_ s p binding
\r
187 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
\r
188 possibleRelatedValue s p = possibleRelatedValue_ s p binding
\r
190 class Browsable a where
\r
191 fromUri :: String -> <ReadGraph> a
\r
193 "Returns the URI of the given value."
\r
194 uriOf :: a -> <ReadGraph> String
\r
196 "Reads the name of the value."
\r
197 nameOf :: a -> <ReadGraph> String
\r
198 possibleNameOf :: a -> <ReadGraph> Maybe String
\r
200 valueOf :: Serializable v => a -> <ReadGraph> v
\r
202 variantValueOf :: a -> <ReadGraph> Variant
\r
204 children :: a -> <ReadGraph> [a]
\r
205 parent :: a -> <ReadGraph> a
\r
206 possibleParent :: a -> <ReadGraph> Maybe a
\r
208 child :: a -> String -> <ReadGraph> a
\r
209 possibleChild :: a -> String -> <ReadGraph> Maybe a
\r
211 instance Browsable Resource where
\r
213 uriOf = uriOfResource
\r
214 nameOf r = relatedValue r L0.HasName
\r
215 possibleNameOf r = possibleRelatedValue r L0.HasName
\r
217 valueOf r = valueOf_ r binding
\r
218 variantValueOf = variantValueOf_
\r
220 children r = r # L0.ConsistsOf
\r
221 parent r = singleObject r L0.PartOf
\r
222 possibleParent r = possibleObject r L0.PartOf
\r
224 possibleChild = possibleResourceChild
\r
225 child r n = fromJust (possibleResourceChild r n)
\r
227 importJava "org.simantics.db.WriteOnlyGraph" where
\r
228 markUndoPoint :: () -> <WriteGraph> ()
\r
230 importJava "org.simantics.db.WriteGraph" where
\r
231 "Creates a new resource."
\r
232 newResource :: () -> <WriteGraph> Resource
\r
233 "Adds a statement to the semantic graph."
\r
234 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
235 @JavaName claimLiteral
\r
236 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
237 @JavaName claimLiteral
\r
238 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
\r
239 @JavaName claimValue
\r
240 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
\r
241 @JavaName claimLiteral
\r
242 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
243 "Removes a statement with the given subject, predicate and object"
\r
244 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
246 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
\r
248 denyAllStatements :: Resource -> <WriteGraph> ()
\r
249 newClusterSet :: Resource -> <WriteGraph> ()
\r
250 @JavaName denyValue
\r
251 denyValue :: Resource -> <WriteGraph> ()
\r
253 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
254 claimAssertion type_ predicate object = do
\r
255 ass = newResource ()
\r
256 claim ass L0.HasPredicate predicate
\r
257 claim ass L0.HasObject object
\r
258 claim type_ L0.Asserts ass
\r
260 "Sets the value of the literal that is an object with the given subject and predicate."
\r
262 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
\r
263 claimRelatedValue s p v = claimRelatedValue_ s p v binding
\r
266 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
\r
267 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
\r
269 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
\r
270 @JavaName getPossibleChild
\r
271 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
\r
273 @deprecated "Use function children instead."
\r
274 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
\r
275 resourceChildrenOf r = r # L0.ConsistsOf
\r
277 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
\r
279 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
\r
282 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
\r
284 @JavaName getSingleOwnerList
\r
285 parentOrderedSet :: Resource -> <ReadGraph> Resource
\r
288 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
\r
290 importJava "org.simantics.db.common.utils.ListUtils" where
\r
292 elementsOfList :: Resource -> <ReadGraph> [Resource]
\r
294 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
295 isParent :: Resource -> Resource -> <ReadGraph> Boolean
\r
296 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
\r
297 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
\r
298 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
\r
299 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
\r
301 importJava "org.simantics.db.common.utils.NameUtils" where
\r
302 findFreshName :: String -> Resource -> <ReadGraph> String
\r
303 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
\r
305 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
\r
306 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
\r
307 subject # predicate = collectionToList $ objects_ subject predicate
\r
309 "statements subject predicate` returns all statements with the given subject and predicate."
\r
310 statements :: Resource -> Resource -> <ReadGraph> [Statement]
\r
311 statements subject predicate = collectionToList $ statements_ subject predicate
\r
313 importJava "org.simantics.scl.db.SCLFunctions" where
\r
314 "Executes a read transaction and waits that it completes."
\r
315 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
\r
316 "Executes a write transaction and waits that it completes."
\r
317 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
\r
318 "Executes a delayed write transaction and waits that it completes."
\r
319 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
\r
321 "Begins a read transaction and immediately returns."
\r
322 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
\r
323 "Begins a write transaction and immediately returns."
\r
324 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
\r
326 virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
327 virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
329 safeExec :: (() -> <Proc> a) -> <Proc> a
\r
330 activateOnce :: Resource -> <Proc> ()
\r
331 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
\r
332 resourceFromId :: Long -> <ReadGraph> Resource
\r
333 enableDependencies :: () -> <WriteGraph> ()
\r
334 disableDependencies :: () -> <WriteGraph> ()
\r
336 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
337 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
339 importJava "org.simantics.db.layer0.util.Layer0Utils" where
\r
340 undo :: () -> <Proc> String
\r
341 undoOperations :: Integer -> <Proc> String
\r
342 redo :: () -> <Proc> String
\r
343 queryDebugSupport :: String -> <Proc> String
\r
344 queryListSupport :: String -> <Proc> String
\r
345 addCommentMetadata :: String -> <WriteGraph> ()
\r
346 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
\r
347 makeSynchronous :: Boolean -> <ReadGraph> ()
\r
348 listOntologies :: () -> <ReadGraph> [Resource]
\r
352 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
\r
353 @JavaName getPossiblePredicateByName
\r
354 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
\r
356 copyTo :: Resource -> Resource -> <WriteGraph> Resource
\r
357 copyTo targetContainer source = do
\r
358 (collectionToList $ copyTo_ targetContainer source)!0
\r
360 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
361 selectClusterSet :: Resource -> <WriteGraph> ()
\r
363 importJava "org.simantics.Simantics" where
\r
364 @JavaName getProjectResource
\r
365 currentProject :: () -> /*<Proc>*/ Resource
\r
367 // Move to somewhere more generic module
\r
368 importJava "java.util.Collection" where
\r
371 importJava "java.util.ArrayList" where
\r
373 collectionToList :: Collection a -> [a]
\r
375 collectionToList :: Collection a -> [a]
\r
376 collectionToList x = Java.unsafeCoerce x
\r
379 resourceToCollection :: a -> Collection a
\r
380 resourceToCollection x = Java.unsafeCoerce x
\r
382 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
383 newEntity entitySpecs = do
\r
384 entity = newResource ()
\r
385 for entitySpecs (\spec -> spec entity)
\r
388 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
389 updateEntity entity entitySpecs = do
\r
390 for entitySpecs (\spec -> spec entity)
\r
393 hasStatement predicate object entity =
\r
394 claim entity predicate object
\r
395 hasProperty relation value entity =
\r
396 claimRelatedValue entity relation value
\r
397 hasPossibleProperty relation value entity =
\r
399 Just v -> claimRelatedValue entity relation v
\r
401 hasTypedProperty relation value t entity =
\r
402 claimRelatedValueWithType entity relation t value
\r
403 hasName (n :: String) = hasProperty L0.HasName n
\r
404 hasLabel (l :: String) = hasProperty L0.HasLabel l
\r
405 hasType t = hasStatement L0.InstanceOf t
\r
406 hasParent p = hasStatement L0.PartOf p
\r
408 importJava "org.simantics.databoard.util.URIStringUtils" where
\r
409 @JavaName splitURISCL
\r
410 splitURI :: String -> [String]
\r
412 escapeURI :: String -> String
\r
414 unescapeURI :: String -> String
\r
417 importJava "org.simantics.db.layer0.request.ActiveModels" where
\r
418 @JavaName getPossibleActiveModel
\r
419 activeModel :: Resource -> <ReadGraph> Maybe Resource
\r
421 "Gives the current active model."
\r
422 currentModel :: <ReadGraph> Resource
\r
423 currentModel = match activeModel (currentProject ()) with
\r
424 Just model -> model
\r
425 Nothing -> fail "No active model."
\r
427 startUndoPoint :: String -> <WriteGraph> ()
\r
428 startUndoPoint string = do
\r
430 addCommentMetadata (string)
\r
434 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
\r
435 lift1Read f x = syncRead (\_ -> f x)
\r
438 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
439 lift2Read f x y = syncRead (\_ -> f x y)
\r
442 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
443 lift3Read f x y z = syncRead (\_ -> f x y z)
\r
446 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
\r
447 lift1Write f x = syncWrite (\_ -> f x)
\r
450 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
451 lift2Write f x y = syncWrite (\_ -> f x y)
\r
454 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
455 lift3Write f x y z = syncWrite (\_ -> f x y z)