-import "JavaBuiltin" as Java\r
-include "http://www.simantics.org/Layer0-1.1" as L0\r
-\r
-infixl 5 (#)\r
- \r
-effect ReadGraph\r
- "graph"\r
- "org.simantics.db.ReadGraph"\r
-\r
-effect WriteGraph\r
- "graph"\r
- "org.simantics.db.WriteGraph"\r
- \r
-importJava "org.simantics.db.Resource" where\r
- "A resource is a node in a semantic graph."\r
- data Resource\r
- \r
- "Returns the 64-bit unique identifier of the resource."\r
- @JavaName getResourceId\r
- resourceId :: Resource -> Long\r
- \r
-importJava "org.simantics.db.ReadGraph" where\r
- data ReadGraphX\r
- \r
-instance Ord Resource where\r
- compare a b = compare (resourceId a) (resourceId b)\r
- \r
-instance Show Resource where\r
- show r = "#" + show (resourceId r)\r
-\r
-instance Show Statement where\r
- show s = "#" + show (resourceId ( subjectOf s)) + "#" + show (resourceId ( predicateOf s)) + "#" + show (resourceId ( objectOf s))\r
-\r
-importJava "org.simantics.db.Statement" where\r
- "A statement is an edge in a semantic graph."\r
- data Statement\r
- \r
- @JavaName getSubject\r
- subjectOf :: Statement -> Resource\r
- @JavaName getPredicate\r
- predicateOf :: Statement -> Resource\r
- @JavaName getObject\r
- objectOf :: Statement -> Resource\r
- \r
-importJava "org.simantics.db.ReadGraph" where\r
- "Converts an absolute URI to a resource or returns `Nothing` if there is no such resource."\r
- @JavaName getPossibleResource\r
- possibleResource :: String -> <ReadGraph> (Maybe Resource)\r
- \r
- getDataType :: Resource -> <ReadGraph> Datatype\r
-\r
- @JavaName getSupertypes\r
- superTypesOf :: Resource -> <ReadGraph> Set.T Resource\r
- \r
- @private\r
- @JavaName getURI\r
- uriOfResource :: Resource -> <ReadGraph> String\r
- \r
- @JavaName getObjects\r
- objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource\r
- \r
- @JavaName getStatements\r
- statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement\r
- \r
- @JavaName hasStatement\r
- existsStatement :: Resource -> Resource -> <ReadGraph> Boolean\r
- \r
- @JavaName hasStatement\r
- existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean\r
-\r
- "Assumes that there is exactly one object with the given subject and predicate and returns it."\r
- @JavaName getSingleObject\r
- singleObject :: Resource -> Resource -> <ReadGraph> Resource\r
-\r
- """\r
- If there is exactly one object with the given `subject` and `predicate`,\r
- `possibleObject subject predicate` returns it. Otherwise, it returns\r
- `Nothing`.\r
- """\r
- @JavaName getPossibleObject\r
- possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource\r
-\r
- "Assumes that there is exactly one statement with the given subject and predicate and returns it."\r
- @JavaName getSingleStatement\r
- singleStatement :: Resource -> Resource -> <ReadGraph> Statement\r
-\r
- @JavaName getRelatedVariantValue\r
- relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant\r
-\r
- @JavaName getRelatedValue\r
- relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a\r
- \r
- @JavaName getRelatedValue\r
- untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a\r
-\r
- @JavaName getRelatedValue2\r
- relatedValue2 :: Resource -> Resource -> <ReadGraph> a\r
-\r
- @JavaName getRelatedVariantValue2\r
- relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant\r
- \r
- @JavaName getPossibleRelatedValue\r
- possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a\r
- \r
- @JavaName getPossibleRelatedValue\r
- untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a\r
- \r
- @private\r
- @JavaName getValue\r
- valueOf_ :: Resource -> Binding a -> <ReadGraph> a\r
- \r
- @private\r
- @JavaName getVariantValue\r
- variantValueOf_ :: Resource -> <ReadGraph> Variant\r
- \r
- @JavaName getValue\r
- untypedValueOf :: Resource -> <ReadGraph> Dynamic\r
- \r
- @JavaName getPossibleValue\r
- untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic\r
- \r
- @JavaName getInverse\r
- inverseOf :: Resource -> <ReadGraph> Resource\r
- \r
- @JavaName getSingleType\r
- singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource\r
- \r
- @JavaName getPossibleType\r
- possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource\r
- \r
- "`isInstanceOf r t` returns true, if `r` is an instance of `t`"\r
- isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean\r
- isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean\r
- isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean\r
- \r
- getRootLibrary :: () -> <ReadGraph> Resource\r
-\r
-importJava "org.simantics.db.layer0.util.ExtendedUris" where\r
- "Converts an absolute URI to a resource"\r
- @JavaName resolveAbsoluteUri \r
- resource :: String -> <ReadGraph> Resource\r
- \r
- "Converts a relative URI to a resource starting from the given resource"\r
- @JavaName resolveRelativeUri\r
- relativeResource :: Resource -> String -> <ReadGraph> Resource\r
-\r
-"Reads the value of a literal that is an object with the given subject and predicate"\r
-@inline\r
-relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a\r
-relatedValue s p = relatedValue_ s p binding\r
-\r
-@inline\r
-possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a\r
-possibleRelatedValue s p = possibleRelatedValue_ s p binding\r
-\r
-class Browsable a where\r
- fromUri :: String -> <ReadGraph> a\r
-\r
- "Returns the URI of the given value."\r
- uriOf :: a -> <ReadGraph> String\r
- \r
- "Reads the name of the value."\r
- nameOf :: a -> <ReadGraph> String\r
- possibleNameOf :: a -> <ReadGraph> Maybe String\r
- \r
- valueOf :: Serializable v => a -> <ReadGraph> v\r
- \r
- variantValueOf :: a -> <ReadGraph> Variant \r
- \r
- children :: a -> <ReadGraph> [a]\r
- parent :: a -> <ReadGraph> a\r
- possibleParent :: a -> <ReadGraph> Maybe a\r
- \r
- child :: a -> String -> <ReadGraph> a\r
- possibleChild :: a -> String -> <ReadGraph> Maybe a\r
- \r
-instance Browsable Resource where\r
- fromUri = resource\r
- uriOf = uriOfResource\r
- nameOf r = relatedValue r L0.HasName\r
- possibleNameOf r = possibleRelatedValue r L0.HasName\r
- @inline\r
- valueOf r = valueOf_ r binding\r
- variantValueOf = variantValueOf_\r
- \r
- children r = r # L0.ConsistsOf\r
- parent r = singleObject r L0.PartOf\r
- possibleParent r = possibleObject r L0.PartOf\r
- \r
- possibleChild = possibleResourceChild\r
- child r n = fromJust (possibleResourceChild r n)\r
-\r
-importJava "org.simantics.db.WriteOnlyGraph" where\r
- markUndoPoint :: () -> <WriteGraph> ()\r
-\r
-importJava "org.simantics.db.WriteGraph" where\r
- "Creates a new resource."\r
- newResource :: () -> <WriteGraph> Resource\r
- "Adds a statement to the semantic graph."\r
- claim :: Resource -> Resource -> Resource -> <WriteGraph> ()\r
- @JavaName claimLiteral\r
- claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()\r
- @JavaName claimLiteral\r
- untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()\r
- @JavaName claimValue\r
- untypedClaimValue :: Resource -> a -> <WriteGraph> ()\r
- @JavaName claimLiteral\r
- claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()\r
- "Removes a statement with the given subject, predicate and object"\r
- deny :: Resource -> Resource -> Resource -> <WriteGraph> ()\r
- @JavaName deny\r
- denyByPredicate :: Resource -> Resource -> <WriteGraph> ()\r
- @JavaName deny\r
- denyAllStatements :: Resource -> <WriteGraph> ()\r
- newClusterSet :: Resource -> <WriteGraph> ()\r
- @JavaName denyValue\r
- denyValue :: Resource -> <WriteGraph> ()\r
-\r
-claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()\r
-claimAssertion type_ predicate object = do\r
- ass = newResource ()\r
- claim ass L0.HasPredicate predicate\r
- claim ass L0.HasObject object\r
- claim type_ L0.Asserts ass\r
-\r
-"Sets the value of the literal that is an object with the given subject and predicate."\r
-@inline\r
-claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()\r
-claimRelatedValue s p v = claimRelatedValue_ s p v binding\r
-\r
-@inline\r
-claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()\r
-claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding\r
-\r
-importJava "org.simantics.layer0.utils.direct.GraphUtils" where\r
- @JavaName getPossibleChild\r
- possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)\r
-\r
-@deprecated "Use function children instead."\r
-resourceChildrenOf :: Resource -> <ReadGraph> [Resource]\r
-resourceChildrenOf r = r # L0.ConsistsOf\r
-\r
-importJava "org.simantics.db.common.utils.OrderedSetUtils" where\r
- @JavaName add\r
- addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean\r
- \r
- @JavaName set\r
- setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean\r
- \r
- @JavaName getSingleOwnerList\r
- parentOrderedSet :: Resource -> <ReadGraph> Resource\r
- \r
- @JavaName toList\r
- elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]\r
- \r
-importJava "org.simantics.db.common.utils.ListUtils" where\r
- @JavaName toList\r
- elementsOfList :: Resource -> <ReadGraph> [Resource]\r
-\r
-importJava "org.simantics.db.common.utils.CommonDBUtils" where\r
- isParent :: Resource -> Resource -> <ReadGraph> Boolean\r
- possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String\r
- possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer\r
- objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]\r
- possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource\r
-\r
-importJava "org.simantics.db.common.utils.NameUtils" where\r
- findFreshName :: String -> Resource -> <ReadGraph> String\r
- findFreshEscapedName :: String -> Resource -> <ReadGraph> String\r
-\r
-"`subject # predicate` returns all objects with the given `subject` and `predicate`."\r
-(#) :: Resource -> Resource -> <ReadGraph> [Resource]\r
-subject # predicate = collectionToList $ objects_ subject predicate\r
-\r
-"statements subject predicate` returns all statements with the given subject and predicate."\r
-statements :: Resource -> Resource -> <ReadGraph> [Statement]\r
-statements subject predicate = collectionToList $ statements_ subject predicate\r
-\r
-importJava "org.simantics.scl.db.SCLFunctions" where\r
- "Executes a read transaction and waits that it completes."\r
- syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a\r
- "Executes a write transaction and waits that it completes."\r
- syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a\r
- "Executes a delayed write transaction and waits that it completes."\r
- delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a\r
- \r
- "Begins a read transaction and immediately returns."\r
- asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()\r
- "Begins a write transaction and immediately returns."\r
- asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()\r
- \r
- virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a\r
- virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a\r
- \r
- safeExec :: (() -> <Proc> a) -> <Proc> a\r
- activateOnce :: Resource -> <Proc> ()\r
- syncActivateOnce :: Resource -> <WriteGraph, Proc> ()\r
- resourceFromId :: Long -> <ReadGraph> Resource\r
- enableDependencies :: () -> <WriteGraph> ()\r
- disableDependencies :: () -> <WriteGraph> ()\r
- \r
- unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b\r
- unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b\r
-\r
-importJava "org.simantics.db.layer0.util.Layer0Utils" where\r
- undo :: () -> <Proc> String\r
- undoOperations :: Integer -> <Proc> String\r
- redo :: () -> <Proc> String\r
- queryDebugSupport :: String -> <Proc> String\r
- queryListSupport :: String -> <Proc> String\r
- addCommentMetadata :: String -> <WriteGraph> ()\r
- sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]\r
- makeSynchronous :: Boolean -> <ReadGraph> ()\r
- listOntologies :: () -> <ReadGraph> [Resource]\r
-\r
- @private\r
- @JavaName copyTo\r
- copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource\r
- @JavaName getPossiblePredicateByName\r
- possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource\r
-\r
-copyTo :: Resource -> Resource -> <WriteGraph> Resource\r
-copyTo targetContainer source = do\r
- (collectionToList $ copyTo_ targetContainer source)!0\r
-\r
-importJava "org.simantics.db.common.utils.CommonDBUtils" where\r
- selectClusterSet :: Resource -> <WriteGraph> () \r
-\r
-importJava "org.simantics.Simantics" where\r
- @JavaName getProjectResource\r
- currentProject :: () -> /*<Proc>*/ Resource\r
-\r
-// Move to somewhere more generic module\r
-importJava "java.util.Collection" where\r
- data Collection a\r
-\r
-importJava "java.util.ArrayList" where\r
- @JavaName "<init>"\r
- collectionToList :: Collection a -> [a]\r
-/*@macro\r
-collectionToList :: Collection a -> [a]\r
-collectionToList x = Java.unsafeCoerce x\r
-*/ \r
-\r
-resourceToCollection :: a -> Collection a\r
-resourceToCollection x = Java.unsafeCoerce x\r
-\r
-newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource\r
-newEntity entitySpecs = do\r
- entity = newResource ()\r
- for entitySpecs (\spec -> spec entity)\r
- entity\r
-\r
-updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource\r
-updateEntity entity entitySpecs = do\r
- for entitySpecs (\spec -> spec entity)\r
- entity\r
-\r
-hasStatement predicate object entity = \r
- claim entity predicate object\r
-hasProperty relation value entity = \r
- claimRelatedValue entity relation value\r
-hasPossibleProperty relation value entity =\r
- match value with\r
- Just v -> claimRelatedValue entity relation v\r
- Nothing -> ()\r
-hasTypedProperty relation value t entity = \r
- claimRelatedValueWithType entity relation t value \r
-hasName (n :: String) = hasProperty L0.HasName n\r
-hasLabel (l :: String) = hasProperty L0.HasLabel l\r
-hasType t = hasStatement L0.InstanceOf t\r
-hasParent p = hasStatement L0.PartOf p\r
-\r
-importJava "org.simantics.databoard.util.URIStringUtils" where\r
- @JavaName splitURISCL\r
- splitURI :: String -> [String]\r
- @JavaName escape\r
- escapeURI :: String -> String\r
- @JavaName unescape\r
- unescapeURI :: String -> String\r
-\r
-@private\r
-importJava "org.simantics.db.layer0.request.ActiveModels" where\r
- @JavaName getPossibleActiveModel\r
- activeModel :: Resource -> <ReadGraph> Maybe Resource\r
-\r
-"Gives the current active model."\r
-currentModel :: <ReadGraph> Resource\r
-currentModel = match activeModel (currentProject ()) with\r
- Just model -> model\r
- Nothing -> fail "No active model."\r
-\r
-startUndoPoint :: String -> <WriteGraph> ()\r
-startUndoPoint string = do\r
- markUndoPoint ()\r
- addCommentMetadata (string)\r
- ()\r
-\r
-@inline\r
-lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)\r
-lift1Read f x = syncRead (\_ -> f x)\r
-\r
-@inline\r
-lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)\r
-lift2Read f x y = syncRead (\_ -> f x y)\r
-\r
-@inline\r
-lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)\r
-lift3Read f x y z = syncRead (\_ -> f x y z)\r
-\r
-@inline\r
-lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)\r
-lift1Write f x = syncWrite (\_ -> f x)\r
-\r
-@inline\r
-lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)\r
-lift2Write f x y = syncWrite (\_ -> f x y)\r
-\r
-@inline\r
-lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)\r
-lift3Write f x y z = syncWrite (\_ -> f x y z)\r
-\r
-"""\r
-Returns a child Browsable of the specified parent that has that is the child\r
-of the specified parent with the specified name path.\r
-"""\r
-childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a\r
-childWithPath parent path = \r
- foldl (\r name -> match possibleChild r name with\r
- Just c -> c\r
- Nothing -> fail ("Didn't find " + name + ".") \r
- ) \r
- parent path\r
-\r
-"""\r
-Like `childWithPath` but returns Maybe a which will be `Nothing` if no child\r
-was found.\r
-"""\r
-possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a\r
-possibleChildWithPath parent path = \r
- foldl (\r name -> match r with\r
- Just c -> possibleChild c name\r
- Nothing -> Nothing \r
- ) \r
- (Just parent) path\r
+import "JavaBuiltin" as Java
+include "http://www.simantics.org/Layer0-1.1" as L0
+import "Map" as Map
+
+infixl 5 (#)
+
+effect ReadGraph
+ "graph"
+ "org.simantics.db.ReadGraph"
+
+effect WriteGraph
+ "graph"
+ "org.simantics.db.WriteGraph"
+
+importJava "org.simantics.db.Resource" where
+ "A resource is a node in a semantic graph."
+ data Resource
+
+ "Returns the 64-bit unique identifier of the resource."
+ @JavaName getResourceId
+ resourceId :: Resource -> Long
+
+ isPersistent :: Resource -> Boolean
+
+importJava "org.simantics.db.ReadGraph" where
+ data ReadGraphX
+
+instance Ord Resource where
+ compare a b = compare (resourceId a) (resourceId b)
+
+instance Show Resource where
+ show r = "#" + show (resourceId r)
+
+instance Show Statement where
+ show s = "#" + show (resourceId ( subjectOf s)) + "#" + show (resourceId ( predicateOf s)) + "#" + show (resourceId ( objectOf s))
+
+importJava "org.simantics.db.Statement" where
+ "A statement is an edge in a semantic graph."
+ data Statement
+
+ @JavaName getSubject
+ subjectOf :: Statement -> Resource
+ @JavaName getPredicate
+ predicateOf :: Statement -> Resource
+ @JavaName getObject
+ objectOf :: Statement -> Resource
+
+ isAsserted :: Statement -> Resource -> <ReadGraph> Boolean
+
+importJava "org.simantics.db.ReadGraph" where
+ "Converts an absolute URI to a resource or returns `Nothing` if there is no such resource."
+ @JavaName getPossibleResource
+ possibleResource :: String -> <ReadGraph> (Maybe Resource)
+
+ getDataType :: Resource -> <ReadGraph> Datatype
+
+ @JavaName getSupertypes
+ superTypesOf :: Resource -> <ReadGraph> Set.T Resource
+
+ @private
+ @JavaName getURI
+ uriOfResource :: Resource -> <ReadGraph> String
+
+ @private
+ @JavaName getPossibleURI
+ possibleUriOfResource :: Resource -> <ReadGraph> Maybe String
+
+ @JavaName getObjects
+ objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
+
+ @JavaName getStatements
+ statements_ :: Resource -> Resource -> <ReadGraph> Collection Statement
+
+ @JavaName hasStatement
+ existsStatement :: Resource -> Resource -> <ReadGraph> Boolean
+
+ @JavaName hasStatement
+ existsStatement3 :: Resource -> Resource -> Resource -> <ReadGraph> Boolean
+
+ "Assumes that there is exactly one object with the given subject and predicate and returns it."
+ @JavaName getSingleObject
+ singleObject :: Resource -> Resource -> <ReadGraph> Resource
+
+ """
+ If there is exactly one object with the given `subject` and `predicate`,
+ `possibleObject subject predicate` returns it. Otherwise, it returns
+ `Nothing`.
+ """
+ @JavaName getPossibleObject
+ possibleObject :: Resource -> Resource -> <ReadGraph> Maybe Resource
+
+ "Assumes that there is exactly one statement with the given subject and predicate and returns it."
+ @JavaName getSingleStatement
+ singleStatement :: Resource -> Resource -> <ReadGraph> Statement
+
+ @JavaName getPossibleStatement
+ possibleStatement :: Resource -> Resource -> <ReadGraph> Maybe Statement
+
+ @JavaName getRelatedVariantValue
+ relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
+
+ @JavaName getRelatedValue
+ relatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> a
+
+ @JavaName getRelatedValue
+ untypedRelatedValue :: Resource -> Resource -> <ReadGraph> a
+
+ @JavaName getRelatedValue2
+ relatedValue2 :: Resource -> Resource -> <ReadGraph> a
+
+ @JavaName getPossibleRelatedValue2
+ possibleRelatedValue2 :: Resource -> Resource -> <ReadGraph> Maybe a
+
+ @JavaName getRelatedVariantValue2
+ relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
+
+ @JavaName getPossibleRelatedValue
+ possibleRelatedValue_ :: Resource -> Resource -> Binding a -> <ReadGraph> Maybe a
+
+ @JavaName getPossibleRelatedValue
+ untypedPossibleRelatedValue :: Resource -> Resource -> <ReadGraph> Maybe a
+
+ @private
+ @JavaName getValue
+ valueOf_ :: Resource -> Binding a -> <ReadGraph> a
+
+ @private
+ @JavaName getVariantValue
+ variantValueOf_ :: Resource -> <ReadGraph> Variant
+
+ @JavaName getValue
+ untypedValueOf :: Resource -> <ReadGraph> Dynamic
+
+ @JavaName getPossibleValue
+ untypedPossibleValueOf :: Resource -> <ReadGraph> Maybe Dynamic
+
+ @JavaName getInverse
+ inverseOf :: Resource -> <ReadGraph> Resource
+ @JavaName getPossibleInverse
+ possibleInverseOf :: Resource -> <ReadGraph> Maybe Resource
+
+ @JavaName getSingleType
+ singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
+
+ @JavaName getPossibleType
+ possibleTypeOf :: Resource -> Resource -> <ReadGraph> Maybe Resource
+
+ "`isInstanceOf r t` returns true, if `r` is an instance of `t`"
+ isInstanceOf :: Resource -> Resource -> <ReadGraph> Boolean
+ isSubrelationOf :: Resource -> Resource -> <ReadGraph> Boolean
+ isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
+
+ getRootLibrary :: () -> <ReadGraph> Resource
+
+ @JavaName getPredicates
+ predicatesOf :: Resource -> <ReadGraph> [Resource]
+
+ isImmutable :: Resource -> <ReadGraph> Boolean
+
+importJava "org.simantics.db.layer0.util.ExtendedUris" where
+ "Converts an absolute URI to a resource"
+ @JavaName resolveAbsoluteUri
+ resource :: String -> <ReadGraph> Resource
+
+ "Converts a relative URI to a resource starting from the given resource"
+ @JavaName resolveRelativeUri
+ relativeResource :: Resource -> String -> <ReadGraph> Resource
+
+"Reads the value of a literal that is an object with the given subject and predicate"
+@inline
+relatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> a
+relatedValue s p = relatedValue_ s p binding
+
+@inline
+possibleRelatedValue :: Serializable a => Resource -> Resource -> <ReadGraph> Maybe a
+possibleRelatedValue s p = possibleRelatedValue_ s p binding
+
+class Browsable a where
+ fromUri :: String -> <ReadGraph> a
+
+ "Returns the URI of the given value."
+ uriOf :: a -> <ReadGraph> String
+
+ "Returns the URI of the given value if it exists or Nothing."
+ possibleUriOf :: a -> <ReadGraph> Maybe String
+
+ "Reads the name of the value."
+ nameOf :: a -> <ReadGraph> String
+ possibleNameOf :: a -> <ReadGraph> Maybe String
+
+ valueOf :: Serializable v => a -> <ReadGraph> v
+
+ genericRelatedValue :: a -> Resource -> <ReadGraph> t
+ genericPossibleRelatedValue :: a -> Resource -> <ReadGraph> Maybe t
+
+ variantValueOf :: a -> <ReadGraph> Variant
+
+ children :: a -> <ReadGraph> [a]
+ parent :: a -> <ReadGraph> a
+ possibleParent :: a -> <ReadGraph> Maybe a
+
+ child :: a -> String -> <ReadGraph> a
+ possibleChild :: a -> String -> <ReadGraph> Maybe a
+
+instance Browsable Resource where
+ fromUri = resource
+ uriOf = uriOfResource
+ possibleUriOf = possibleUriOfResource
+ nameOf r = relatedValue r L0.HasName
+ possibleNameOf r = possibleRelatedValue r L0.HasName
+ @inline
+ valueOf r = valueOf_ r binding
+ variantValueOf = variantValueOf_
+
+ genericRelatedValue = relatedValue2
+ genericPossibleRelatedValue = possibleRelatedValue2
+
+ children r = r # L0.ConsistsOf
+ parent r = singleObject r L0.PartOf
+ possibleParent r = possibleObject r L0.PartOf
+
+ possibleChild = possibleResourceChild
+ child r n = fromJust (possibleResourceChild r n)
+
+importJava "org.simantics.db.WriteOnlyGraph" where
+ markUndoPoint :: () -> <WriteGraph> ()
+
+importJava "org.simantics.db.WriteGraph" where
+ "Creates a new resource."
+ newResource :: () -> <WriteGraph> Resource
+ "Adds a statement to the semantic graph."
+ claim :: Resource -> Resource -> Resource -> <WriteGraph> ()
+ @JavaName claim
+ claimWithInverse :: Resource -> Resource -> Maybe Resource -> Resource -> <WriteGraph> ()
+ @JavaName claimLiteral
+ claimRelatedValue_ :: Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
+ @JavaName claimLiteral
+ untypedClaimRelatedValue :: Resource -> Resource -> a -> <WriteGraph> ()
+ @JavaName claimValue
+ untypedClaimValue :: Resource -> a -> <WriteGraph> ()
+ @JavaName claimLiteral
+ claimRelatedValueWithType_ :: Resource -> Resource -> Resource -> a -> Binding a -> <WriteGraph> ()
+ "Removes a statement with the given subject, predicate and object"
+ deny :: Resource -> Resource -> Resource -> <WriteGraph> ()
+ @JavaName deny
+ denyByPredicate :: Resource -> Resource -> <WriteGraph> ()
+ @JavaName deny
+ denyAllStatements :: Resource -> <WriteGraph> ()
+ newClusterSet :: Resource -> <WriteGraph> ()
+ @JavaName denyValue
+ denyValue :: Resource -> <WriteGraph> ()
+
+"Sets the value of the literal that is an object with the given subject and predicate."
+@inline
+claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
+claimRelatedValue s p v = claimRelatedValue_ s p v binding
+
+@inline
+claimRelatedValueWithType :: Serializable a => Resource -> Resource -> Resource -> a -> <WriteGraph> ()
+claimRelatedValueWithType s p t v = claimRelatedValueWithType_ s p t v binding
+
+importJava "org.simantics.layer0.utils.direct.GraphUtils" where
+ @JavaName getPossibleChild
+ possibleResourceChild :: Resource -> String -> <ReadGraph> (Maybe Resource)
+
+@deprecated "Use function children instead."
+resourceChildrenOf :: Resource -> <ReadGraph> [Resource]
+resourceChildrenOf r = r # L0.ConsistsOf
+
+importJava "org.simantics.db.common.utils.OrderedSetUtils" where
+ "`addToOrderedSet s e` adds element `e` to ordered set `s`"
+ @JavaName add
+ addToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
+
+ "`addFirstToOrderedSet s e` adds element `e` to ordered set `s` as the first element"
+ @JavaName addFirst
+ addFirstToOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
+
+ "`addAfterToOrderedSet s p e` adds element `e` to ordered set `s` after element `p`"
+ @JavaName addAfter
+ addAfterToOrderedSet :: Resource -> Resource -> Resource -> <WriteGraph> Boolean
+
+ "`addBeforeToOrderedSet s p e` adds element `e` to ordered set `s` before element `p`"
+ @JavaName addBefore
+ addBeforeToOrderedSet :: Resource -> Resource -> Resource -> <WriteGraph> Boolean
+
+ "`removeFromOrderedSet s e` removes element `e` from ordered set `s`"
+ @JavaName remove
+ removeFromOrderedSet :: Resource -> Resource -> <WriteGraph> Boolean
+
+ @JavaName set
+ setOrderedSet :: Resource -> [Resource] -> <WriteGraph> Boolean
+
+ @JavaName getSingleOwnerList
+ parentOrderedSet :: Resource -> <ReadGraph> Resource
+
+ @JavaName toList
+ elementsOfOrderedSet :: Resource -> <ReadGraph> [Resource]
+
+importJava "org.simantics.db.common.utils.ListUtils" where
+ "`elementsOfList l` returns elements of list `l`"
+ @JavaName toList
+ elementsOfList :: Resource -> <ReadGraph> [Resource]
+
+ "`createList [e]` creates a new list containing elements `[e]`"
+ @JavaName create
+ createList :: [Resource] -> <WriteGraph> Resource
+
+ "`createListWithType t [e]` creates a new list with type `t` containing elements `[e]`"
+ @JavaName create
+ createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
+
+ "`insertListBack l [e]` inserts elements `[e]` back to the list `l`"
+ @JavaName insertBack
+ insertListBack :: Resource -> [Resource] -> <WriteGraph> ()
+
+ "`insertListFront l [e]` inserts elements `[e]` front of the list `l`"
+ @JavaName insertFront
+ insertListFront :: Resource -> [Resource] -> <WriteGraph> ()
+
+ "`removeListElement l e` removes a element `e` from the list `l`"
+ @JavaName removeElement
+ removeListElement :: Resource -> Resource -> <WriteGraph> Boolean
+
+ @JavaName swapWithPrevious
+ swapListElementWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
+
+ @JavaName swapWithNext
+ swapListElementWithNext :: Resource -> Resource -> <WriteGraph> Boolean
+
+
+importJava "org.simantics.db.common.utils.CommonDBUtils" where
+ isParent :: Resource -> Resource -> <ReadGraph> Boolean
+ possibleRelatedString :: Resource -> Resource -> <ReadGraph> Maybe String
+ possibleRelatedInteger :: Resource -> Resource -> <ReadGraph> Maybe Integer
+ objectsWithType :: Resource -> Resource -> Resource -> <ReadGraph> [Resource]
+ possibleObjectWithType :: Resource -> Resource -> Resource -> <ReadGraph> Maybe Resource
+
+importJava "org.simantics.db.common.utils.NameUtils" where
+ findFreshName :: String -> Resource -> <ReadGraph> String
+ findFreshEscapedName :: String -> Resource -> <ReadGraph> String
+
+"`subject # predicate` returns all objects with the given `subject` and `predicate`."
+(#) :: Resource -> Resource -> <ReadGraph> [Resource]
+subject # predicate = collectionToList $ objects_ subject predicate
+
+"statements subject predicate` returns all statements with the given subject and predicate."
+statements :: Resource -> Resource -> <ReadGraph> [Statement]
+statements subject predicate = collectionToList $ statements_ subject predicate
+
+importJava "org.simantics.scl.db.SCLFunctions" where
+ "Executes a read transaction and waits that it completes."
+ syncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> a
+ "Executes a write transaction and waits that it completes."
+ syncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> a
+ "Executes a delayed write transaction and waits that it completes."
+ delayedSyncWrite :: (() -> <Proc,WriteGraph> a) -> <Proc> a
+
+ "Begins a read transaction and immediately returns."
+ asyncRead :: (() -> <Proc,ReadGraph> a) -> <Proc> ()
+ "Begins a write transaction and immediately returns."
+ asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
+
+ virtualSyncWriteMem :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
+ virtualSyncWriteWS :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
+
+ safeExec :: (() -> <Proc> a) -> <Proc> a
+ activateOnce :: Resource -> <Proc> ()
+ syncActivateOnce :: Resource -> <WriteGraph, Proc> ()
+ resourceFromId :: Long -> <ReadGraph> Resource
+ enableDependencies :: () -> <WriteGraph> ()
+ disableDependencies :: () -> <WriteGraph> ()
+
+ unaryQuery :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
+ unaryQueryCached :: (a -> <ReadGraph,e> b) -> a -> <ReadGraph> b
+
+ "Makes a new read request with given procedure for calculating the result. The request is cached only if the current request is listened."
+ subquery :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
+ "Makes a new read request with given procedure for calculating the result. The request is always cached."
+ subqueryC :: (<ReadGraph,Proc> a) -> <ReadGraph,Proc> a
+ "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."
+ subqueryL :: (<ReadGraph,Proc> a) -> (a -> <ReadGraph, e> ()) -> (Throwable -> <ReadGraph, e> ()) -> (<e> Boolean) -> <ReadGraph, Proc, e> ()
+ "Tries to convert the given Dynamic value to a value with the inferred type"
+ possibleFromDynamic :: Typeable a => String -> Dynamic -> Maybe a
+
+importJava "org.simantics.db.layer0.util.Layer0Utils" where
+ undo :: () -> <Proc> String
+ undoOperations :: Integer -> <Proc> String
+ redo :: () -> <Proc> String
+ queryDebugSupport :: String -> <Proc> String
+ queryListSupport :: String -> <Proc> String
+ addCommentMetadata :: String -> <WriteGraph> ()
+ sortByCluster :: [a] -> (a->Resource) -> <ReadGraph> [a]
+ makeSynchronous :: Boolean -> <ReadGraph> ()
+ listOntologies :: () -> <ReadGraph> [Resource]
+ emptyTrashBin :: () -> <Proc> ()
+ purgeDatabase :: () -> <Proc> ()
+ prettyPrintResource :: Resource -> Boolean -> <ReadGraph> String
+
+ @private
+ @JavaName copyTo
+ copyTo_ :: Resource -> Resource -> <WriteGraph> Collection Resource
+ @JavaName getPossiblePredicateByName
+ possiblePredicateByName :: Resource -> String -> <ReadGraph> Maybe Resource
+ @JavaName getPossiblePredicateByNameFromType
+ possiblePredicateByNameFromType :: Resource -> String -> <ReadGraph> Maybe Resource
+
+ addMetadataListener :: ChangeListener -> <Proc> ()
+ removeMetadataListener :: ChangeListener -> <Proc> ()
+
+ @JavaName assert_
+ claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
+
+copyTo :: Resource -> Resource -> <WriteGraph> Resource
+copyTo targetContainer source = do
+ (collectionToList $ copyTo_ targetContainer source)!0
+
+importJava "org.simantics.db.common.utils.CommonDBUtils" where
+ selectClusterSet :: Resource -> <WriteGraph> ()
+
+importJava "org.simantics.Simantics" where
+ @JavaName getProjectResource
+ currentProject :: () -> /*<Proc>*/ Resource
+
+// Move to somewhere more generic module
+importJava "java.util.Collection" where
+ data Collection a
+
+importJava "java.util.ArrayList" where
+ @JavaName "<init>"
+ collectionToList :: Collection a -> [a]
+/*@macro
+collectionToList :: Collection a -> [a]
+collectionToList x = Java.unsafeCoerce x
+*/
+
+resourceToCollection :: a -> Collection a
+resourceToCollection x = Java.unsafeCoerce x
+
+newEntity :: [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
+newEntity entitySpecs = do
+ entity = newResource ()
+ for entitySpecs (\spec -> spec entity)
+ entity
+
+updateEntity :: Resource -> [Resource -> <ReadGraph,WriteGraph> ()] -> <ReadGraph,WriteGraph> Resource
+updateEntity entity entitySpecs = do
+ for entitySpecs (\spec -> spec entity)
+ entity
+
+hasStatement predicate object entity =
+ claim entity predicate object
+hasProperty relation value entity =
+ claimRelatedValue entity relation value
+hasPossibleProperty relation value entity =
+ match value with
+ Just v -> claimRelatedValue entity relation v
+ Nothing -> ()
+hasTypedProperty relation value t entity =
+ claimRelatedValueWithType entity relation t value
+hasName (n :: String) = hasProperty L0.HasName n
+hasLabel (l :: String) = hasProperty L0.HasLabel l
+hasType t = hasStatement L0.InstanceOf t
+hasParent p = hasStatement L0.PartOf p
+
+importJava "org.simantics.databoard.util.URIStringUtils" where
+ @JavaName splitURISCL
+ splitURI :: String -> [String]
+ @JavaName escape
+ escapeURI :: String -> String
+ @JavaName unescape
+ unescapeURI :: String -> String
+
+@private
+importJava "org.simantics.db.layer0.request.ActiveModels" where
+ @JavaName getPossibleActiveModel
+ activeModel :: Resource -> <ReadGraph> Maybe Resource
+
+"Gives the current active model."
+currentModel :: <ReadGraph> Resource
+currentModel = match activeModel (currentProject ()) with
+ Just model -> model
+ Nothing -> fail "No active model."
+
+"Gives the current active model if it exists or Nothing otherwise."
+possibleCurrentModel :: <ReadGraph> Maybe Resource
+possibleCurrentModel = activeModel (currentProject ())
+
+startUndoPoint :: String -> <WriteGraph> ()
+startUndoPoint string = do
+ markUndoPoint ()
+ addCommentMetadata (string)
+ ()
+
+@inline
+lift1Read :: (a -> <ReadGraph,Proc> b) -> (a -> <Proc> b)
+lift1Read f x = syncRead (\_ -> f x)
+
+@inline
+lift2Read :: (a -> b -> <ReadGraph,Proc> c) -> (a -> b -> <Proc> c)
+lift2Read f x y = syncRead (\_ -> f x y)
+
+@inline
+lift3Read :: (a -> b -> c -> <ReadGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
+lift3Read f x y z = syncRead (\_ -> f x y z)
+
+@inline
+lift1Write :: (a -> <WriteGraph,Proc> b) -> (a -> <Proc> b)
+lift1Write f x = syncWrite (\_ -> f x)
+
+@inline
+lift2Write :: (a -> b -> <WriteGraph,Proc> c) -> (a -> b -> <Proc> c)
+lift2Write f x y = syncWrite (\_ -> f x y)
+
+@inline
+lift3Write :: (a -> b -> c -> <WriteGraph,Proc> d) -> (a -> b -> c -> <Proc> d)
+lift3Write f x y z = syncWrite (\_ -> f x y z)
+
+"""
+Returns a child Browsable of the specified parent that has that is the child
+of the specified parent with the specified name path.
+"""
+childWithPath :: Browsable a => a -> [String] -> <ReadGraph> a
+childWithPath parent path =
+ foldl (\r name -> match possibleChild r name with
+ Just c -> c
+ Nothing -> fail ("Didn't find " + name + ".")
+ )
+ parent path
+
+"""
+Like `childWithPath` but returns Maybe a which will be `Nothing` if no child
+was found.
+"""
+possibleChildWithPath :: Browsable a => a -> [String] -> <ReadGraph> Maybe a
+possibleChildWithPath parent path =
+ foldl (\r name -> match r with
+ Just c -> possibleChild c name
+ Nothing -> Nothing
+ )
+ (Just parent) path
+
+importJava "org.simantics.db.MetadataI" where
+ data MetadataI
+
+importJava "org.simantics.db.event.ChangeListener" where
+ data ChangeListener
+
+importJava "org.simantics.db.layer0.genericrelation.DependencyChanges" where
+ data DependencyChanges