]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Adapters to convert various literals to Strings 27/4927/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 16 Nov 2022 08:43:47 +0000 (10:43 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Wed, 16 Nov 2022 08:43:47 +0000 (10:43 +0200)
Boolean, Double, and Integer conversions.

gitlab #881

Change-Id: Idaa4885470e580a0b0b4e5994c6a1e2a88bfd020

bundles/org.simantics.db.layer0/adapters.xml
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralBooleanStringAdapter.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleArrayStringAdapter.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleStringAdapter.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerArrayStringAdapter.java [new file with mode: 0644]
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerStringAdapter.java [new file with mode: 0644]

index bdf1f143574e9cf62caeec571ec9a12607f461ce..42ff10ec7141e3fa45bb7a2bf5d14dba793336b7 100644 (file)
                        adapterClass="org.simantics.db.layer0.adapter.LiteralStringAdapter"/>
                <adapter uri="http://www.simantics.org/Layer0-0.0/RVI"
                        adapterClass="org.simantics.db.layer0.adapter.RVIStringAdapter"/>
+               
+               <adapter uri="http://www.simantics.org/Layer0-0.0/Double"
+                       contextClass="org.simantics.db.RelationContext" adapterClass="org.simantics.db.layer0.adapter.LiteralDoubleStringAdapter" />
+               <adapter uri="http://www.simantics.org/Layer0-0.0/DoubleArray"
+                       contextClass="org.simantics.db.RelationContext" adapterClass="org.simantics.db.layer0.adapter.LiteralDoubleArrayStringAdapter" />
+               <adapter uri="http://www.simantics.org/Layer0-0.0/Integer"
+                       contextClass="org.simantics.db.RelationContext" adapterClass="org.simantics.db.layer0.adapter.LiteralIntegerStringAdapter" />
+               <adapter uri="http://www.simantics.org/Layer0-0.0/IntegerArray"
+                       contextClass="org.simantics.db.RelationContext" adapterClass="org.simantics.db.layer0.adapter.LiteralIntegerArrayStringAdapter" />
+               <adapter uri="http://www.simantics.org/Layer0-0.0/Boolean"
+                       contextClass="org.simantics.db.RelationContext" adapterClass="org.simantics.db.layer0.adapter.LiteralBooleanStringAdapter" />
        </target>
 
        <target interface="java.lang.String">
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralBooleanStringAdapter.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralBooleanStringAdapter.java
new file mode 100644 (file)
index 0000000..508ad27
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationContext;
+import org.simantics.db.Resource;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class LiteralBooleanStringAdapter implements Adapter<String, RelationContext> {
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure<String> procedure) {
+        g.forValue(s.getStatement().getObject(), Bindings.BOOLEAN, new  ProcedureWrapper(procedure));
+    }
+    
+    private static class ProcedureWrapper implements AsyncProcedure<Boolean> {
+       AsyncProcedure<String> procedure;
+       
+       public ProcedureWrapper(AsyncProcedure<String> procedure) {
+                       this.procedure = procedure;
+               }
+       
+       public void execute(AsyncReadGraph graph, Boolean result) {
+               procedure.execute(graph, result.toString());
+       };
+       
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable throwable) {
+               procedure.exception(graph, throwable);
+               
+       }
+    }
+    
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleArrayStringAdapter.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleArrayStringAdapter.java
new file mode 100644 (file)
index 0000000..c58c66f
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.db.layer0.adapter;
+
+import java.util.Arrays;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationContext;
+import org.simantics.db.Resource;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class LiteralDoubleArrayStringAdapter implements Adapter<String, RelationContext> {
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure<String> procedure) {
+        g.forValue(s.getStatement().getObject(), Bindings.DOUBLE_ARRAY, new  ProcedureWrapper(procedure));
+    }
+    
+    private static class ProcedureWrapper implements AsyncProcedure<double[]> {
+       AsyncProcedure<String> procedure;
+       
+       public ProcedureWrapper(AsyncProcedure<String> procedure) {
+                       this.procedure = procedure;
+               }
+       
+       public void execute(AsyncReadGraph graph, double[] result) {
+               procedure.execute(graph, Arrays.toString(result));
+       };
+       
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable throwable) {
+               procedure.exception(graph, throwable);
+               
+       }
+    }
+    
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleStringAdapter.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleStringAdapter.java
new file mode 100644 (file)
index 0000000..3518b70
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationContext;
+import org.simantics.db.Resource;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class LiteralDoubleStringAdapter implements Adapter<String, RelationContext> {
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure<String> procedure) {
+        g.forValue(s.getStatement().getObject(), Bindings.DOUBLE, new  ProcedureWrapper(procedure));
+    }
+    
+    private static class ProcedureWrapper implements AsyncProcedure<Double> {
+       AsyncProcedure<String> procedure;
+       
+       public ProcedureWrapper(AsyncProcedure<String> procedure) {
+                       this.procedure = procedure;
+               }
+       
+       public void execute(AsyncReadGraph graph, Double result) {
+               procedure.execute(graph, result.toString());
+       };
+       
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable throwable) {
+               procedure.exception(graph, throwable);
+               
+       }
+    }
+    
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerArrayStringAdapter.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerArrayStringAdapter.java
new file mode 100644 (file)
index 0000000..39aeb71
--- /dev/null
@@ -0,0 +1,37 @@
+package org.simantics.db.layer0.adapter;
+
+import java.util.Arrays;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationContext;
+import org.simantics.db.Resource;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class LiteralIntegerArrayStringAdapter implements Adapter<String, RelationContext> {
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure<String> procedure) {
+        g.forValue(s.getStatement().getObject(), Bindings.INT_ARRAY, new  ProcedureWrapper(procedure));
+    }
+    
+    private static class ProcedureWrapper implements AsyncProcedure<int[]> {
+       AsyncProcedure<String> procedure;
+       
+       public ProcedureWrapper(AsyncProcedure<String> procedure) {
+                       this.procedure = procedure;
+               }
+       
+       public void execute(AsyncReadGraph graph, int[] result) {
+               procedure.execute(graph, Arrays.toString(result));
+       };
+       
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable throwable) {
+               procedure.exception(graph, throwable);
+               
+       }
+    }
+    
+}
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerStringAdapter.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerStringAdapter.java
new file mode 100644 (file)
index 0000000..178b4b2
--- /dev/null
@@ -0,0 +1,35 @@
+package org.simantics.db.layer0.adapter;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationContext;
+import org.simantics.db.Resource;
+import org.simantics.db.adaption.Adapter;
+import org.simantics.db.procedure.AsyncProcedure;
+
+public class LiteralIntegerStringAdapter implements Adapter<String, RelationContext> {
+
+    @Override
+    public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure<String> procedure) {
+        g.forValue(s.getStatement().getObject(), Bindings.INTEGER, new  ProcedureWrapper(procedure));
+    }
+    
+    private static class ProcedureWrapper implements AsyncProcedure<Integer> {
+       AsyncProcedure<String> procedure;
+       
+       public ProcedureWrapper(AsyncProcedure<String> procedure) {
+                       this.procedure = procedure;
+               }
+       
+       public void execute(AsyncReadGraph graph, Integer result) {
+               procedure.execute(graph, result.toString());
+       };
+       
+       @Override
+       public void exception(AsyncReadGraph graph, Throwable throwable) {
+               procedure.exception(graph, throwable);
+               
+       }
+    }
+    
+}