]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.db/scl/Simantics/DB.scl
Use the same implementation to claim assertions in SCL and in Java
[simantics/platform.git] / bundles / org.simantics.scl.db / scl / Simantics / DB.scl
index 30608067d7a6353545f53a5a4d00c5a93962826c..b69119eae0e345b65f153961cb289f85c752d63a 100644 (file)
@@ -20,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
     
@@ -58,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
@@ -102,6 +108,9 @@ importJava "org.simantics.db.ReadGraph" where
     @JavaName getRelatedValue2
     relatedValue2 :: Resource -> Resource -> <ReadGraph> a
 
+    @JavaName getPossibleRelatedValue2
+    possibleRelatedValue2 :: Resource -> Resource -> <ReadGraph> Maybe a
+
     @JavaName getRelatedVariantValue2
     relatedVariantValue2 :: Resource -> Resource -> <ReadGraph> Variant
     
@@ -127,6 +136,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
@@ -143,6 +154,8 @@ importJava "org.simantics.db.ReadGraph" where
     
     @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"
@@ -167,13 +180,19 @@ 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
     
     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]
@@ -186,12 +205,16 @@ 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
     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
@@ -207,6 +230,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
@@ -225,13 +250,6 @@ importJava "org.simantics.db.WriteGraph" where
     @JavaName denyValue
     denyValue :: Resource -> <WriteGraph> ()
 
-claimAssertion :: Resource -> Resource -> Resource -> <WriteGraph> ()
-claimAssertion type_ predicate object = do
-    ass = newResource ()
-    claim ass L0.HasPredicate predicate
-    claim ass L0.HasObject object
-    claim type_ L0.Asserts ass
-
 "Sets the value of the literal that is an object with the given subject and predicate."
 @inline
 claimRelatedValue :: Serializable a => Resource -> Resource -> a -> <WriteGraph> ()
@@ -250,9 +268,26 @@ 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
     
@@ -263,26 +298,35 @@ importJava "org.simantics.db.common.utils.OrderedSetUtils" where
     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
-    createList :: Resource -> [Resource] -> <WriteGraph> Resource
+    createListWithType :: Resource -> [Resource] -> <WriteGraph> Resource
+    
+    "`insertListBack l [e]` inserts elements `[e]` back to the list `l`"
+    @JavaName insertBack
+    insertListBack :: Resource -> [Resource] -> <WriteGraph> ()
     
-    @javaName insertBack
-    insertBack :: Resource -> [Resource] -> <WriteGraph> ()
+    "`insertListFront l [e]` inserts elements `[e]` front of the list `l`"
+    @JavaName insertFront
+    insertListFront :: Resource -> [Resource] -> <WriteGraph> ()
     
-    @javaName removeElement
-    removeElement :: Resource -> Resource -> <WriteGraph> Boolean
+    "`removeListElement l e` removes a element `e` from the list `l`"
+    @JavaName removeElement
+    removeListElement :: Resource -> Resource -> <WriteGraph> Boolean
     
-    @javaName swapWithPrevious
-    swapWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
+    @JavaName swapWithPrevious
+    swapListElementWithPrevious :: Resource -> Resource -> <WriteGraph> Boolean
 
-    @javaName swapWithNext
-    swapWithNext :: Resource -> Resource -> <WriteGraph> Boolean
+    @JavaName swapWithNext
+    swapListElementWithNext :: Resource -> Resource -> <WriteGraph> Boolean
 
 
 importJava "org.simantics.db.common.utils.CommonDBUtils" where
@@ -317,8 +361,8 @@ importJava "org.simantics.scl.db.SCLFunctions" where
     "Begins a write transaction and immediately returns."
     asyncWrite :: (() -> <Proc,ReadGraph,WriteGraph> a) -> <Proc> ()
     
-    virtualSyncWriteMem :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
-    virtualSyncWriteWS :: String -> (() -> <ReadGraph,WriteGraph> a) -> <WriteGraph> a
+    virtualSyncWriteMem :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
+    virtualSyncWriteWS :: String -> (() -> <e,WriteGraph> a) -> <e,WriteGraph> a
     
     safeExec :: (() -> <Proc> a) -> <Proc> a
     activateOnce :: Resource -> <Proc> ()
@@ -334,6 +378,8 @@ 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
 
@@ -356,6 +402,14 @@ importJava "org.simantics.db.layer0.util.Layer0Utils" where
     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
@@ -428,6 +482,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 ()
@@ -480,4 +538,13 @@ possibleChildWithPath parent path =
               Just c -> possibleChild c name
               Nothing -> Nothing 
           ) 
-          (Just parent) path
\ No newline at end of file
+          (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