From c39895f2ed8eafefa40e34d20114adb3a4d2b8bf Mon Sep 17 00:00:00 2001 From: Hylke van der Schaaf Date: Tue, 9 Jan 2024 19:50:00 +0100 Subject: [PATCH] Fixed warnings due to JOOQ issue #15286 --- .../pgjooq/PgExpressionHandler.java | 7 +++--- .../pgjooq/bindings/JsonBinding.java | 21 ++++++++++++------ .../pgjooq/bindings/MomentBinding.java | 22 ++++++++++++------- .../bindings/PostGisGeometryBinding.java | 12 ++++++++++ .../fieldwrapper/StaDateTimeWrapper.java | 5 +++-- .../fieldwrapper/StaTimeIntervalWrapper.java | 9 ++++---- .../pgjooq/tables/StaTableAbstract.java | 2 +- 7 files changed, 53 insertions(+), 25 deletions(-) diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java index 92f743074..f84f6bfc0 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java @@ -19,6 +19,7 @@ import static de.fraunhofer.iosb.ilt.frostserver.property.SpecialNames.AT_IOT_ID; +import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.PostGisGeometryBinding; import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.ArrayConstandFieldWrapper; import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.FieldListWrapper; import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.FieldWrapper; @@ -407,7 +408,7 @@ public FieldWrapper visit(IntegerConstant node) { @Override public FieldWrapper visit(LineStringConstant node) { Geometry geom = fromGeoJsonConstant(node); - return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText())); + return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText())); } @Override @@ -418,13 +419,13 @@ public FieldWrapper visit(NullConstant node) { @Override public FieldWrapper visit(PointConstant node) { Geometry geom = fromGeoJsonConstant(node); - return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText())); + return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText())); } @Override public FieldWrapper visit(PolygonConstant node) { Geometry geom = fromGeoJsonConstant(node); - return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText())); + return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText())); } private static Geometry fromGeoJsonConstant(GeoJsonConstant node) { diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/JsonBinding.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/JsonBinding.java index 57fba1a1b..81fe3f447 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/JsonBinding.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/JsonBinding.java @@ -18,7 +18,6 @@ package de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings; import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.factories.EntityFactories; -import de.fraunhofer.iosb.ilt.frostserver.util.StringHelper; import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.Types; @@ -31,8 +30,10 @@ import org.jooq.BindingSetSQLOutputContext; import org.jooq.BindingSetStatementContext; import org.jooq.Converter; +import org.jooq.DataType; import org.jooq.conf.ParamType; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; /** * @@ -40,16 +41,13 @@ */ public class JsonBinding implements Binding { + private static final JsonBinding INSTANCE = new JsonBinding(); private static final Converter CONVERTER_INSTANCE = new Converter() { @Override public JsonValue from(Object databaseObject) { if (databaseObject == null) { return new JsonValue((String) null); } - if (databaseObject instanceof byte[]) { - String jsonString = new String((byte[]) databaseObject, StringHelper.UTF8); - return new JsonValue(jsonString); - } return new JsonValue(databaseObject.toString()); } @@ -68,16 +66,25 @@ public Class toType() { return JsonValue.class; } }; + private static final DataType DATA_TYPE = SQLDataType.CLOB.asConvertedDataType(INSTANCE); public static Converter getConverterInstance() { return CONVERTER_INSTANCE; } + public static JsonBinding instance() { + return INSTANCE; + } + @Override public Converter converter() { return CONVERTER_INSTANCE; } + public static DataType dataType() { + return DATA_TYPE; + } + @Override public void sql(BindingSQLContext ctx) throws SQLException { if (ctx.render().paramType() == ParamType.INLINED) { @@ -104,12 +111,12 @@ public void set(BindingSetSQLOutputContext ctx) throws SQLException { @Override public void get(BindingGetResultSetContext ctx) throws SQLException { - ctx.convert(converter()).value(ctx.resultSet().getBytes(ctx.index())); + ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index())); } @Override public void get(BindingGetStatementContext ctx) throws SQLException { - ctx.convert(converter()).value(ctx.statement().getBytes(ctx.index())); + ctx.convert(converter()).value(ctx.statement().getString(ctx.index())); } @Override diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/MomentBinding.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/MomentBinding.java index 7f348dae5..656a38b5b 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/MomentBinding.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/MomentBinding.java @@ -32,8 +32,10 @@ import org.jooq.BindingSetSQLOutputContext; import org.jooq.BindingSetStatementContext; import org.jooq.Converter; +import org.jooq.DataType; import org.jooq.conf.ParamType; import org.jooq.impl.DSL; +import org.jooq.impl.SQLDataType; /** * @@ -41,7 +43,8 @@ */ public class MomentBinding implements Binding { - private static final Converter INSTANCE = new Converter() { + private static final MomentBinding INSTANCE = new MomentBinding(); + private static final Converter CONVERTER_INSTANCE = new Converter() { @Override public Moment from(Timestamp databaseObject) { if (databaseObject == null) { @@ -68,10 +71,19 @@ public Class toType() { return Moment.class; } }; + private static final DataType DATA_TYPE = SQLDataType.TIMESTAMP.asConvertedDataType(INSTANCE); + + public static MomentBinding instance() { + return INSTANCE; + } @Override public Converter converter() { - return INSTANCE; + return CONVERTER_INSTANCE; + } + + public static DataType dataType() { + return DATA_TYPE; } @Override @@ -83,37 +95,31 @@ public void sql(BindingSQLContext ctx) throws SQLException { } } - // Registering VARCHAR types for JDBC CallableStatement OUT parameters @Override public void register(BindingRegisterContext ctx) throws SQLException { ctx.statement().registerOutParameter(ctx.index(), Types.TIMESTAMP_WITH_TIMEZONE); } - // Converting the JsonElement to a String value and setting that on a JDBC PreparedStatement @Override public void set(BindingSetStatementContext ctx) throws SQLException { ctx.statement().setTimestamp(ctx.index(), ctx.convert(converter()).value()); } - // Getting a String value from a JDBC ResultSet and converting that to a JsonElement @Override public void get(BindingGetResultSetContext ctx) throws SQLException { ctx.convert(converter()).value(ctx.resultSet().getTimestamp(ctx.index())); } - // Getting a String value from a JDBC CallableStatement and converting that to a JsonElement @Override public void get(BindingGetStatementContext ctx) throws SQLException { ctx.convert(converter()).value(ctx.statement().getTimestamp(ctx.index())); } - // Setting a value on a JDBC SQLOutput (useful for Oracle OBJECT types) @Override public void set(BindingSetSQLOutputContext ctx) throws SQLException { throw new SQLFeatureNotSupportedException(); } - // Getting a value from a JDBC SQLInput (useful for Oracle OBJECT types) @Override public void get(BindingGetSQLInputContext ctx) throws SQLException { throw new SQLFeatureNotSupportedException(); diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/PostGisGeometryBinding.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/PostGisGeometryBinding.java index 889149226..10d994a17 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/PostGisGeometryBinding.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/PostGisGeometryBinding.java @@ -30,6 +30,8 @@ import org.jooq.BindingSetSQLOutputContext; import org.jooq.BindingSetStatementContext; import org.jooq.Converter; +import org.jooq.DataType; +import org.jooq.impl.SQLDataType; /** * @@ -37,6 +39,7 @@ */ public class PostGisGeometryBinding implements Binding { + private static final PostGisGeometryBinding INSTANCE = new PostGisGeometryBinding(); private static final Converter CONVERTER_INSTANCE = new Converter() { @Override public Geometry from(Object databaseObject) { @@ -59,12 +62,21 @@ public Class toType() { return Geometry.class; } }; + private static final DataType DATA_TYPE = SQLDataType.VARBINARY.asConvertedDataType(INSTANCE); + + public static PostGisGeometryBinding instance() { + return INSTANCE; + } @Override public Converter converter() { return CONVERTER_INSTANCE; } + public static DataType dataType() { + return DATA_TYPE; + } + @Override public void sql(BindingSQLContext ctx) throws SQLException { ctx.render().sql("ST_GeomFromEWKT(?)"); diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaDateTimeWrapper.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaDateTimeWrapper.java index c00f11b13..282e32484 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaDateTimeWrapper.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaDateTimeWrapper.java @@ -19,6 +19,7 @@ import static de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.Utils.INTERVAL_PARAM; +import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.MomentBinding; import net.time4j.Moment; import org.jooq.Condition; import org.jooq.Field; @@ -46,7 +47,7 @@ public class StaDateTimeWrapper implements TimeFieldWrapper { * @param utc Flag indicating that the original time given was in utc. */ public StaDateTimeWrapper(final Moment ts, boolean utc) { - field = DSL.inline(ts); + field = DSL.inline(ts, MomentBinding.dataType()); this.utc = utc; } @@ -90,7 +91,7 @@ private FieldWrapper specificOp(String op, StaDurationWrapper other) { case "+": case "-": String template = "(? " + op + " " + INTERVAL_PARAM + ")"; - Field expression = DSL.field(template, Moment.class, field, other.getDuration()); + Field expression = DSL.field(template, MomentBinding.dataType(), field, other.getDuration()); return new StaDateTimeWrapper(expression); default: diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaTimeIntervalWrapper.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaTimeIntervalWrapper.java index de92f2781..d5929db22 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaTimeIntervalWrapper.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaTimeIntervalWrapper.java @@ -19,6 +19,7 @@ import static de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.Utils.INTERVAL_PARAM; +import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.MomentBinding; import de.fraunhofer.iosb.ilt.frostserver.property.type.TypeComplex; import java.util.Map; import net.time4j.Moment; @@ -58,8 +59,8 @@ public StaTimeIntervalWrapper(Field start, Field end) { } public StaTimeIntervalWrapper(Moment start, Moment end) { - this.start = DSL.inline(start); - this.end = DSL.inline(end); + this.start = DSL.inline(start, MomentBinding.dataType()); + this.end = DSL.inline(end, MomentBinding.dataType()); } public Field getStart() { @@ -104,8 +105,8 @@ private FieldWrapper specificOp(String op, StaDurationWrapper other) { case "-": String template = "(? " + op + " " + INTERVAL_PARAM + ")"; return new StaTimeIntervalWrapper( - DSL.field(template, Moment.class, start, other.getDuration()), - DSL.field(template, Moment.class, end, other.getDuration())); + DSL.field(template, MomentBinding.dataType(), start, other.getDuration()), + DSL.field(template, MomentBinding.dataType(), end, other.getDuration())); default: throw new UnsupportedOperationException(INCOMPATIBLE_OP + op + "' " + other.getClass().getName()); diff --git a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/tables/StaTableAbstract.java b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/tables/StaTableAbstract.java index 5942320fd..f363197c8 100644 --- a/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/tables/StaTableAbstract.java +++ b/FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/tables/StaTableAbstract.java @@ -500,7 +500,7 @@ public static JsonFieldWrapper jsonFieldFromPath(final Field mainField, final En } protected PropertyFields propertyFieldForJsonField(final JsonFieldWrapper jsonFactory, final EntityPropertyCustomSelect epCustomSelect) { - final Field deepField = jsonFactory.materialise().getJsonExpression(); + final Field deepField = jsonFactory.materialise().getJsonExpression(); PropertyFields pfs = new PropertyFields<>( epCustomSelect, new PropertyFieldRegistry.ConverterRecordDeflt<>(