]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.db/scl/Simantics/DB.scl
claimWithInverse & possibleInverseOf function to DB.scl
[simantics/platform.git] / bundles / org.simantics.scl.db / scl / Simantics / DB.scl
index 3d71ae5143a577bf7ec7aeafa3f863b4b978260b..d7c1dde060eb923949520f96a52da6785164c465 100644 (file)
@@ -1,5 +1,6 @@
 import "JavaBuiltin" as Java
 include "http://www.simantics.org/Layer0-1.1" as L0
+import "Map" as Map
 
 infixl 5 (#)
  
@@ -19,6 +20,8 @@ importJava "org.simantics.db.Resource" where
     @JavaName getResourceId
     resourceId :: Resource -> Long
     
+    isPersistent :: Resource -> Boolean
+    
 importJava "org.simantics.db.ReadGraph" where
     data ReadGraphX
     
@@ -42,6 +45,8 @@ importJava "org.simantics.db.Statement" where
     @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
@@ -55,6 +60,10 @@ importJava "org.simantics.db.ReadGraph" where
     @private
     @JavaName getURI
     uriOfResource :: Resource -> <ReadGraph> String
+
+    @private
+    @JavaName getPossibleURI
+    possibleUriOfResource :: Resource -> <ReadGraph> Maybe String
     
     @JavaName getObjects
     objects_ :: Resource -> Resource -> <ReadGraph> Collection Resource
@@ -84,6 +93,9 @@ importJava "org.simantics.db.ReadGraph" where
     @JavaName getSingleStatement
     singleStatement :: Resource -> Resource -> <ReadGraph> Statement
 
+    @JavaName getPossibleStatement
+    possibleStatement :: Resource -> Resource -> <ReadGraph> Maybe Statement
+
     @JavaName getRelatedVariantValue
     relatedVariantValue :: Resource -> Resource -> <ReadGraph> Variant
 
@@ -121,6 +133,8 @@ importJava "org.simantics.db.ReadGraph" where
     
     @JavaName getInverse
     inverseOf :: Resource -> <ReadGraph> Resource
+    @JavaName getPossibleInverse
+    possibleInverseOf :: Resource -> <ReadGraph> Maybe Resource
     
     @JavaName getSingleType
     singleTypeOf :: Resource -> Resource -> <ReadGraph> Resource
@@ -134,6 +148,9 @@ importJava "org.simantics.db.ReadGraph" where
     isInheritedFrom :: Resource -> Resource -> <ReadGraph> Boolean
     
     getRootLibrary :: () -> <ReadGraph> Resource
+    
+    @JavaName getPredicates
+    predicatesOf :: Resource -> <ReadGraph> [Resource]
 
 importJava "org.simantics.db.layer0.util.ExtendedUris" where
     "Converts an absolute URI to a resource"
@@ -158,7 +175,10 @@ class Browsable a where
 
     "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
@@ -177,6 +197,7 @@ class Browsable a where
 instance Browsable Resource where
     fromUri = resource
     uriOf = uriOfResource
+    possibleUriOf = possibleUriOfResource
     nameOf r = relatedValue r L0.HasName
     possibleNameOf r = possibleRelatedValue r L0.HasName
     @inline
@@ -198,6 +219,8 @@ importJava "org.simantics.db.WriteGraph" where
     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
@@ -259,6 +282,9 @@ importJava "org.simantics.db.common.utils.ListUtils" where
     
     @JavaName create
     createList :: [Resource] -> <WriteGraph> Resource
+
+    @JavaName create
+    createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
     
     @javaName insertBack
     insertBack :: Resource -> [Resource] -> <WriteGraph> ()
@@ -322,6 +348,10 @@ importJava "org.simantics.scl.db.SCLFunctions" where
     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
@@ -335,12 +365,18 @@ importJava "org.simantics.db.layer0.util.Layer0Utils" where
     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> ()
 
 copyTo :: Resource -> Resource -> <WriteGraph> Resource
 copyTo targetContainer source = do
@@ -413,6 +449,10 @@ 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 ()
@@ -466,3 +506,12 @@ possibleChildWithPath parent path =
               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