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.db.Resource" where
\r
15 "A resource is a node in a semantic graph."
\r
18 "Returns the 64-bit unique identifier of the resource."
\r
19 @JavaName getResourceId
\r
20 resourceId :: Resource -> Long
\r
22 importJava "org.simantics.db.ReadGraph" where
\r
25 instance Ord Resource where
\r
26 compare a b = compare (resourceId a) (resourceId b)
\r
28 instance Show Resource where
\r
29 show r = "#" + show (resourceId r)
\r
31 instance Show Statement where
\r
32 show s = "#" + show (resourceId ( subjectOf s)) + "#" + show (resourceId ( predicateOf s)) + "#" + show (resourceId ( objectOf s))
\r
34 importJava "org.simantics.db.Statement" where
\r
35 "A statement is an edge in a semantic graph."
\r
38 @JavaName getSubject
\r
39 subjectOf :: Statement -> Resource
\r
40 @JavaName getPredicate
\r
41 predicateOf :: Statement -> Resource
\r
43 objectOf :: Statement -> Resource
\r
45 importJava "org.simantics.db.ReadGraph" where
\r
46 "Converts an absolute URI to a resource or returns `Nothing` if there is no such resource."
\r
47 @JavaName getPossibleResource
\r
48 possibleResource :: String -> <ReadGraph> (Maybe Resource)
\r
50 getDataType :: Resource -> <ReadGraph> Datatype
\r
52 @JavaName getSupertypes
\r
53 superTypesOf :: Resource -> <ReadGraph> Set.T Resource
\r
57 uriOfResource :: Resource -> <ReadGraph> String
\r
59 @JavaName getObjects
\r
60 objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
\r
62 @JavaName getStatements
\r
63 statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement
\r
65 @JavaName hasStatement
\r
66 existsStatement :: Resource -> Resource -> <ReadGraph> Boolean
\r
68 @JavaName hasStatement
\r
69 existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean
\r
71 "Assumes that there is exactly one object with the given subject and predicate and returns it."
\r
72 @JavaName getSingleObject
\r
73 singleObject :: Resource -> Resource -> <ReadGraph> Resource
\r
76 If there is exactly one object with the given `subject` and `predicate`,
\r
77 `possibleObject subject predicate` returns it. Otherwise, it returns
\r
80 @JavaName getPossibleObject
\r
81 possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
83 "Assumes that there is exactly one statement with the given subject and predicate and returns it."
\r
84 @JavaName getSingleStatement
\r
85 singleStatement :: Resource -> Resource -> <ReadGraph> Statement
\r
87 @JavaName getRelatedVariantValue
\r
88 relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
\r
90 @JavaName getRelatedValue
\r
91 relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a
\r
93 @JavaName getRelatedValue
\r
94 untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a
\r
96 @JavaName getRelatedValue2
\r
97 relatedValue2 :: Resource -> Resource -> <ReadGraph> a
\r
99 @JavaName getRelatedVariantValue2
\r
100 relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
\r
102 @JavaName getPossibleRelatedValue
\r
103 possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
\r
105 @JavaName getPossibleRelatedValue
\r
106 untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
\r
110 valueOf_ :: Resource -> Binding a -> <ReadGraph> a
\r
113 @JavaName getVariantValue
\r
114 variantValueOf_ :: Resource -> <ReadGraph> Variant
\r
117 untypedValueOf :: Resource -> <ReadGraph> Dynamic
\r
119 @JavaName getPossibleValue
\r
120 untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
\r
122 @JavaName getInverse
\r
123 inverseOf :: Resource -> <ReadGraph> Resource
\r
125 @JavaName getSingleType
\r
126 singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
\r
128 @JavaName getPossibleType
\r
129 possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
\r
131 "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
\r
132 isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
133 isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
\r
134 isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
\r
136 getRootLibrary :: () -> <ReadGraph> Resource
\r
138 importJava "org.simantics.db.layer0.util.ExtendedUris" where
\r
139 "Converts an absolute URI to a resource"
\r
140 @JavaName resolveAbsoluteUri
\r
141 resource :: String -> <ReadGraph> Resource
\r
143 "Converts a relative URI to a resource starting from the given resource"
\r
144 @JavaName resolveRelativeUri
\r
145 relativeResource :: Resource -> String -> <ReadGraph> Resource
\r
147 "Reads the value of a literal that is an object with the given subject and predicate"
\r
149 relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
\r
150 relatedValue s p = relatedValue_ s p binding
\r
153 possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
\r
154 possibleRelatedValue s p = possibleRelatedValue_ s p binding
\r
156 class Browsable a where
\r
157 fromUri :: String -> <ReadGraph> a
\r
159 "Returns the URI of the given value."
\r
160 uriOf :: a -> <ReadGraph> String
\r
162 "Reads the name of the value."
\r
163 nameOf :: a -> <ReadGraph> String
\r
164 possibleNameOf :: a -> <ReadGraph> Maybe String
\r
166 valueOf :: Serializable v => a -> <ReadGraph> v
\r
168 variantValueOf :: a -> <ReadGraph> Variant
\r
170 children :: a -> <ReadGraph> [a]
\r
171 parent :: a -> <ReadGraph> a
\r
172 possibleParent :: a -> <ReadGraph> Maybe a
\r
174 child :: a -> String -> <ReadGraph> a
\r
175 possibleChild :: a -> String -> <ReadGraph> Maybe a
\r
177 instance Browsable Resource where
\r
179 uriOf = uriOfResource
\r
180 nameOf r = relatedValue r L0.HasName
\r
181 possibleNameOf r = possibleRelatedValue r L0.HasName
\r
183 valueOf r = valueOf_ r binding
\r
184 variantValueOf = variantValueOf_
\r
186 children r = r # L0.ConsistsOf
\r
187 parent r = singleObject r L0.PartOf
\r
188 possibleParent r = possibleObject r L0.PartOf
\r
190 possibleChild = possibleResourceChild
\r
191 child r n = fromJust (possibleResourceChild r n)
\r
193 importJava "org.simantics.db.WriteOnlyGraph" where
\r
194 markUndoPoint :: () -> <WriteGraph> ()
\r
196 importJava "org.simantics.db.WriteGraph" where
\r
197 "Creates a new resource."
\r
198 newResource :: () -> <WriteGraph> Resource
\r
199 "Adds a statement to the semantic graph."
\r
200 claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
201 @JavaName claimLiteral
\r
202 claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
203 @JavaName claimLiteral
\r
204 untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
\r
205 @JavaName claimValue
\r
206 untypedClaimValue :: Resource -> a -> <WriteGraph> ()
\r
207 @JavaName claimLiteral
\r
208 claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
\r
209 "Removes a statement with the given subject, predicate and object"
\r
210 deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
212 denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
\r
214 denyAllStatements :: Resource -> <WriteGraph> ()
\r
215 newClusterSet :: Resource -> <WriteGraph> ()
\r
216 @JavaName denyValue
\r
217 denyValue :: Resource -> <WriteGraph> ()
\r
219 claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
\r
220 claimAssertion type_ predicate object = do
\r
221 ass = newResource ()
\r
222 claim ass L0.HasPredicate predicate
\r
223 claim ass L0.HasObject object
\r
224 claim type_ L0.Asserts ass
\r
226 "Sets the value of the literal that is an object with the given subject and predicate."
\r
228 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
\r
229 claimRelatedValue s p v = claimRelatedValue_ s p v binding
\r
232 claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
\r
233 claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
\r
235 importJava "org.simantics.layer0.utils.direct.GraphUtils" where
\r
236 @JavaName getPossibleChild
\r
237 possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
\r
239 @deprecated "Use function children instead."
\r
240 resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
\r
241 resourceChildrenOf r = r # L0.ConsistsOf
\r
243 importJava "org.simantics.db.common.utils.OrderedSetUtils" where
\r
245 addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
\r
248 setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
\r
250 @JavaName getSingleOwnerList
\r
251 parentOrderedSet :: Resource -> <ReadGraph> Resource
\r
254 elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
\r
256 importJava "org.simantics.db.common.utils.ListUtils" where
\r
258 elementsOfList :: Resource -> <ReadGraph> [Resource]
\r
260 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
261 isParent :: Resource -> Resource -> <ReadGraph> Boolean
\r
262 possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
\r
263 possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
\r
264 objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
\r
265 possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
\r
267 importJava "org.simantics.db.common.utils.NameUtils" where
\r
268 findFreshName :: String -> Resource -> <ReadGraph> String
\r
269 findFreshEscapedName :: String -> Resource -> <ReadGraph> String
\r
271 "`subject # predicate` returns all objects with the given `subject` and `predicate`."
\r
272 (#) :: Resource -> Resource -> <ReadGraph> [Resource]
\r
273 subject # predicate = collectionToList $ objects_ subject predicate
\r
275 "statements subject predicate` returns all statements with the given subject and predicate."
\r
276 statements :: Resource -> Resource -> <ReadGraph> [Statement]
\r
277 statements subject predicate = collectionToList $ statements_ subject predicate
\r
279 importJava "org.simantics.scl.db.SCLFunctions" where
\r
280 "Executes a read transaction and waits that it completes."
\r
281 syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
\r
282 "Executes a write transaction and waits that it completes."
\r
283 syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
\r
284 "Executes a delayed write transaction and waits that it completes."
\r
285 delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
\r
287 "Begins a read transaction and immediately returns."
\r
288 asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
\r
289 "Begins a write transaction and immediately returns."
\r
290 asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
\r
292 virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
293 virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
\r
295 safeExec :: (() -> <Proc> a) -> <Proc> a
\r
296 activateOnce :: Resource -> <Proc> ()
\r
297 syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
\r
298 resourceFromId :: Long -> <ReadGraph> Resource
\r
299 enableDependencies :: () -> <WriteGraph> ()
\r
300 disableDependencies :: () -> <WriteGraph> ()
\r
302 unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
303 unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
\r
305 importJava "org.simantics.db.layer0.util.Layer0Utils" where
\r
306 undo :: () -> <Proc> String
\r
307 undoOperations :: Integer -> <Proc> String
\r
308 redo :: () -> <Proc> String
\r
309 queryDebugSupport :: String -> <Proc> String
\r
310 queryListSupport :: String -> <Proc> String
\r
311 addCommentMetadata :: String -> <WriteGraph> ()
\r
312 sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
\r
313 makeSynchronous :: Boolean -> <ReadGraph> ()
\r
314 listOntologies :: () -> <ReadGraph> [Resource]
\r
318 copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
\r
319 @JavaName getPossiblePredicateByName
\r
320 possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
\r
322 copyTo :: Resource -> Resource -> <WriteGraph> Resource
\r
323 copyTo targetContainer source = do
\r
324 (collectionToList $ copyTo_ targetContainer source)!0
\r
326 importJava "org.simantics.db.common.utils.CommonDBUtils" where
\r
327 selectClusterSet :: Resource -> <WriteGraph> ()
\r
329 importJava "org.simantics.Simantics" where
\r
330 @JavaName getProjectResource
\r
331 currentProject :: () -> /*<Proc>*/ Resource
\r
333 // Move to somewhere more generic module
\r
334 importJava "java.util.Collection" where
\r
337 importJava "java.util.ArrayList" where
\r
339 collectionToList :: Collection a -> [a]
\r
341 collectionToList :: Collection a -> [a]
\r
342 collectionToList x = Java.unsafeCoerce x
\r
345 resourceToCollection :: a -> Collection a
\r
346 resourceToCollection x = Java.unsafeCoerce x
\r
348 newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
349 newEntity entitySpecs = do
\r
350 entity = newResource ()
\r
351 for entitySpecs (\spec -> spec entity)
\r
354 updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
\r
355 updateEntity entity entitySpecs = do
\r
356 for entitySpecs (\spec -> spec entity)
\r
359 hasStatement predicate object entity =
\r
360 claim entity predicate object
\r
361 hasProperty relation value entity =
\r
362 claimRelatedValue entity relation value
\r
363 hasPossibleProperty relation value entity =
\r
365 Just v -> claimRelatedValue entity relation v
\r
367 hasTypedProperty relation value t entity =
\r
368 claimRelatedValueWithType entity relation t value
\r
369 hasName (n :: String) = hasProperty L0.HasName n
\r
370 hasLabel (l :: String) = hasProperty L0.HasLabel l
\r
371 hasType t = hasStatement L0.InstanceOf t
\r
372 hasParent p = hasStatement L0.PartOf p
\r
374 importJava "org.simantics.databoard.util.URIStringUtils" where
\r
375 @JavaName splitURISCL
\r
376 splitURI :: String -> [String]
\r
378 escapeURI :: String -> String
\r
380 unescapeURI :: String -> String
\r
383 importJava "org.simantics.db.layer0.request.ActiveModels" where
\r
384 @JavaName getPossibleActiveModel
\r
385 activeModel :: Resource -> <ReadGraph> Maybe Resource
\r
387 "Gives the current active model."
\r
388 currentModel :: <ReadGraph> Resource
\r
389 currentModel = match activeModel (currentProject ()) with
\r
390 Just model -> model
\r
391 Nothing -> fail "No active model."
\r
393 startUndoPoint :: String -> <WriteGraph> ()
\r
394 startUndoPoint string = do
\r
396 addCommentMetadata (string)
\r
400 lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
\r
401 lift1Read f x = syncRead (\_ -> f x)
\r
404 lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
405 lift2Read f x y = syncRead (\_ -> f x y)
\r
408 lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
409 lift3Read f x y z = syncRead (\_ -> f x y z)
\r
412 lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
\r
413 lift1Write f x = syncWrite (\_ -> f x)
\r
416 lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
\r
417 lift2Write f x y = syncWrite (\_ -> f x y)
\r
420 lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
\r
421 lift3Write f x y z = syncWrite (\_ -> f x y z)
\r
424 Returns a child Browsable of the specified parent that has that is the child
\r
425 of the specified parent with the specified name path.
\r
427 childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a
\r
428 childWithPath parent path =
\r
429 foldl (\r name -> match possibleChild r name with
\r
431 Nothing -> fail ("Didn't find " + name + ".")
\r
436 Like `childWithPath` but returns Maybe a which will be `Nothing` if no child
\r
439 possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a
\r
440 possibleChildWithPath parent path =
\r
441 foldl (\r name -> match r with
\r
442 Just c -> possibleChild c name
\r
443 Nothing -> Nothing
\r