From: Marko Luukkainen Date: Wed, 16 Nov 2022 08:43:47 +0000 (+0200) Subject: Adapters to convert various literals to Strings X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F27%2F4927%2F1;p=simantics%2Fplatform.git Adapters to convert various literals to Strings Boolean, Double, and Integer conversions. gitlab #881 Change-Id: Idaa4885470e580a0b0b4e5994c6a1e2a88bfd020 --- diff --git a/bundles/org.simantics.db.layer0/adapters.xml b/bundles/org.simantics.db.layer0/adapters.xml index bdf1f1435..42ff10ec7 100644 --- a/bundles/org.simantics.db.layer0/adapters.xml +++ b/bundles/org.simantics.db.layer0/adapters.xml @@ -25,6 +25,17 @@ adapterClass="org.simantics.db.layer0.adapter.LiteralStringAdapter"/> + + + + + + 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 index 000000000..508ad2722 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralBooleanStringAdapter.java @@ -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 { + + @Override + public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure procedure) { + g.forValue(s.getStatement().getObject(), Bindings.BOOLEAN, new ProcedureWrapper(procedure)); + } + + private static class ProcedureWrapper implements AsyncProcedure { + AsyncProcedure procedure; + + public ProcedureWrapper(AsyncProcedure 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 index 000000000..c58c66fb2 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleArrayStringAdapter.java @@ -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 { + + @Override + public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure procedure) { + g.forValue(s.getStatement().getObject(), Bindings.DOUBLE_ARRAY, new ProcedureWrapper(procedure)); + } + + private static class ProcedureWrapper implements AsyncProcedure { + AsyncProcedure procedure; + + public ProcedureWrapper(AsyncProcedure 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 index 000000000..3518b702b --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralDoubleStringAdapter.java @@ -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 { + + @Override + public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure procedure) { + g.forValue(s.getStatement().getObject(), Bindings.DOUBLE, new ProcedureWrapper(procedure)); + } + + private static class ProcedureWrapper implements AsyncProcedure { + AsyncProcedure procedure; + + public ProcedureWrapper(AsyncProcedure 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 index 000000000..39aeb71c8 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerArrayStringAdapter.java @@ -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 { + + @Override + public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure procedure) { + g.forValue(s.getStatement().getObject(), Bindings.INT_ARRAY, new ProcedureWrapper(procedure)); + } + + private static class ProcedureWrapper implements AsyncProcedure { + AsyncProcedure procedure; + + public ProcedureWrapper(AsyncProcedure 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 index 000000000..178b4b270 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/LiteralIntegerStringAdapter.java @@ -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 { + + @Override + public void adapt(AsyncReadGraph g, Resource source, RelationContext s, final AsyncProcedure procedure) { + g.forValue(s.getStatement().getObject(), Bindings.INTEGER, new ProcedureWrapper(procedure)); + } + + private static class ProcedureWrapper implements AsyncProcedure { + AsyncProcedure procedure; + + public ProcedureWrapper(AsyncProcedure 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); + + } + } + +}