Skip to content

Commit c39895f

Browse files
committed
Fixed warnings due to JOOQ issue #15286
1 parent 2160693 commit c39895f

7 files changed

Lines changed: 53 additions & 25 deletions

File tree

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/PgExpressionHandler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static de.fraunhofer.iosb.ilt.frostserver.property.SpecialNames.AT_IOT_ID;
2121

22+
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.PostGisGeometryBinding;
2223
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.ArrayConstandFieldWrapper;
2324
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.FieldListWrapper;
2425
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.fieldwrapper.FieldWrapper;
@@ -407,7 +408,7 @@ public FieldWrapper visit(IntegerConstant node) {
407408
@Override
408409
public FieldWrapper visit(LineStringConstant node) {
409410
Geometry geom = fromGeoJsonConstant(node);
410-
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText()));
411+
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText()));
411412
}
412413

413414
@Override
@@ -418,13 +419,13 @@ public FieldWrapper visit(NullConstant node) {
418419
@Override
419420
public FieldWrapper visit(PointConstant node) {
420421
Geometry geom = fromGeoJsonConstant(node);
421-
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText()));
422+
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText()));
422423
}
423424

424425
@Override
425426
public FieldWrapper visit(PolygonConstant node) {
426427
Geometry geom = fromGeoJsonConstant(node);
427-
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, Geometry.class, geom.asText()));
428+
return new SimpleFieldWrapper(DSL.field(ST_GEOM_FROM_EWKT, PostGisGeometryBinding.dataType(), geom.asText()));
428429
}
429430

430431
private static Geometry fromGeoJsonConstant(GeoJsonConstant<? extends GeoJsonObject> node) {

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/JsonBinding.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings;
1919

2020
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.factories.EntityFactories;
21-
import de.fraunhofer.iosb.ilt.frostserver.util.StringHelper;
2221
import java.sql.SQLException;
2322
import java.sql.SQLFeatureNotSupportedException;
2423
import java.sql.Types;
@@ -31,25 +30,24 @@
3130
import org.jooq.BindingSetSQLOutputContext;
3231
import org.jooq.BindingSetStatementContext;
3332
import org.jooq.Converter;
33+
import org.jooq.DataType;
3434
import org.jooq.conf.ParamType;
3535
import org.jooq.impl.DSL;
36+
import org.jooq.impl.SQLDataType;
3637

3738
/**
3839
*
3940
* @author scf
4041
*/
4142
public class JsonBinding implements Binding<Object, JsonValue> {
4243

44+
private static final JsonBinding INSTANCE = new JsonBinding();
4345
private static final Converter<Object, JsonValue> CONVERTER_INSTANCE = new Converter<Object, JsonValue>() {
4446
@Override
4547
public JsonValue from(Object databaseObject) {
4648
if (databaseObject == null) {
4749
return new JsonValue((String) null);
4850
}
49-
if (databaseObject instanceof byte[]) {
50-
String jsonString = new String((byte[]) databaseObject, StringHelper.UTF8);
51-
return new JsonValue(jsonString);
52-
}
5351
return new JsonValue(databaseObject.toString());
5452
}
5553

@@ -68,16 +66,25 @@ public Class<JsonValue> toType() {
6866
return JsonValue.class;
6967
}
7068
};
69+
private static final DataType<JsonValue> DATA_TYPE = SQLDataType.CLOB.asConvertedDataType(INSTANCE);
7170

7271
public static Converter<Object, JsonValue> getConverterInstance() {
7372
return CONVERTER_INSTANCE;
7473
}
7574

75+
public static JsonBinding instance() {
76+
return INSTANCE;
77+
}
78+
7679
@Override
7780
public Converter<Object, JsonValue> converter() {
7881
return CONVERTER_INSTANCE;
7982
}
8083

84+
public static DataType<JsonValue> dataType() {
85+
return DATA_TYPE;
86+
}
87+
8188
@Override
8289
public void sql(BindingSQLContext<JsonValue> ctx) throws SQLException {
8390
if (ctx.render().paramType() == ParamType.INLINED) {
@@ -104,12 +111,12 @@ public void set(BindingSetSQLOutputContext<JsonValue> ctx) throws SQLException {
104111

105112
@Override
106113
public void get(BindingGetResultSetContext<JsonValue> ctx) throws SQLException {
107-
ctx.convert(converter()).value(ctx.resultSet().getBytes(ctx.index()));
114+
ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()));
108115
}
109116

110117
@Override
111118
public void get(BindingGetStatementContext<JsonValue> ctx) throws SQLException {
112-
ctx.convert(converter()).value(ctx.statement().getBytes(ctx.index()));
119+
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
113120
}
114121

115122
@Override

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/MomentBinding.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@
3232
import org.jooq.BindingSetSQLOutputContext;
3333
import org.jooq.BindingSetStatementContext;
3434
import org.jooq.Converter;
35+
import org.jooq.DataType;
3536
import org.jooq.conf.ParamType;
3637
import org.jooq.impl.DSL;
38+
import org.jooq.impl.SQLDataType;
3739

3840
/**
3941
*
4042
* @author hylke
4143
*/
4244
public class MomentBinding implements Binding<Timestamp, Moment> {
4345

44-
private static final Converter<Timestamp, Moment> INSTANCE = new Converter<Timestamp, Moment>() {
46+
private static final MomentBinding INSTANCE = new MomentBinding();
47+
private static final Converter<Timestamp, Moment> CONVERTER_INSTANCE = new Converter<Timestamp, Moment>() {
4548
@Override
4649
public Moment from(Timestamp databaseObject) {
4750
if (databaseObject == null) {
@@ -68,10 +71,19 @@ public Class<Moment> toType() {
6871
return Moment.class;
6972
}
7073
};
74+
private static final DataType<Moment> DATA_TYPE = SQLDataType.TIMESTAMP.asConvertedDataType(INSTANCE);
75+
76+
public static MomentBinding instance() {
77+
return INSTANCE;
78+
}
7179

7280
@Override
7381
public Converter<Timestamp, Moment> converter() {
74-
return INSTANCE;
82+
return CONVERTER_INSTANCE;
83+
}
84+
85+
public static DataType<Moment> dataType() {
86+
return DATA_TYPE;
7587
}
7688

7789
@Override
@@ -83,37 +95,31 @@ public void sql(BindingSQLContext<Moment> ctx) throws SQLException {
8395
}
8496
}
8597

86-
// Registering VARCHAR types for JDBC CallableStatement OUT parameters
8798
@Override
8899
public void register(BindingRegisterContext<Moment> ctx) throws SQLException {
89100
ctx.statement().registerOutParameter(ctx.index(), Types.TIMESTAMP_WITH_TIMEZONE);
90101
}
91102

92-
// Converting the JsonElement to a String value and setting that on a JDBC PreparedStatement
93103
@Override
94104
public void set(BindingSetStatementContext<Moment> ctx) throws SQLException {
95105
ctx.statement().setTimestamp(ctx.index(), ctx.convert(converter()).value());
96106
}
97107

98-
// Getting a String value from a JDBC ResultSet and converting that to a JsonElement
99108
@Override
100109
public void get(BindingGetResultSetContext<Moment> ctx) throws SQLException {
101110
ctx.convert(converter()).value(ctx.resultSet().getTimestamp(ctx.index()));
102111
}
103112

104-
// Getting a String value from a JDBC CallableStatement and converting that to a JsonElement
105113
@Override
106114
public void get(BindingGetStatementContext<Moment> ctx) throws SQLException {
107115
ctx.convert(converter()).value(ctx.statement().getTimestamp(ctx.index()));
108116
}
109117

110-
// Setting a value on a JDBC SQLOutput (useful for Oracle OBJECT types)
111118
@Override
112119
public void set(BindingSetSQLOutputContext<Moment> ctx) throws SQLException {
113120
throw new SQLFeatureNotSupportedException();
114121
}
115122

116-
// Getting a value from a JDBC SQLInput (useful for Oracle OBJECT types)
117123
@Override
118124
public void get(BindingGetSQLInputContext<Moment> ctx) throws SQLException {
119125
throw new SQLFeatureNotSupportedException();

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/bindings/PostGisGeometryBinding.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
import org.jooq.BindingSetSQLOutputContext;
3131
import org.jooq.BindingSetStatementContext;
3232
import org.jooq.Converter;
33+
import org.jooq.DataType;
34+
import org.jooq.impl.SQLDataType;
3335

3436
/**
3537
*
3638
* @author scf
3739
*/
3840
public class PostGisGeometryBinding implements Binding<Object, Geometry> {
3941

42+
private static final PostGisGeometryBinding INSTANCE = new PostGisGeometryBinding();
4043
private static final Converter<Object, Geometry> CONVERTER_INSTANCE = new Converter<Object, Geometry>() {
4144
@Override
4245
public Geometry from(Object databaseObject) {
@@ -59,12 +62,21 @@ public Class<Geometry> toType() {
5962
return Geometry.class;
6063
}
6164
};
65+
private static final DataType<Geometry> DATA_TYPE = SQLDataType.VARBINARY.asConvertedDataType(INSTANCE);
66+
67+
public static PostGisGeometryBinding instance() {
68+
return INSTANCE;
69+
}
6270

6371
@Override
6472
public Converter<Object, Geometry> converter() {
6573
return CONVERTER_INSTANCE;
6674
}
6775

76+
public static DataType<Geometry> dataType() {
77+
return DATA_TYPE;
78+
}
79+
6880
@Override
6981
public void sql(BindingSQLContext<Geometry> ctx) throws SQLException {
7082
ctx.render().sql("ST_GeomFromEWKT(?)");

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaDateTimeWrapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.Utils.INTERVAL_PARAM;
2121

22+
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.MomentBinding;
2223
import net.time4j.Moment;
2324
import org.jooq.Condition;
2425
import org.jooq.Field;
@@ -46,7 +47,7 @@ public class StaDateTimeWrapper implements TimeFieldWrapper {
4647
* @param utc Flag indicating that the original time given was in utc.
4748
*/
4849
public StaDateTimeWrapper(final Moment ts, boolean utc) {
49-
field = DSL.inline(ts);
50+
field = DSL.inline(ts, MomentBinding.dataType());
5051
this.utc = utc;
5152
}
5253

@@ -90,7 +91,7 @@ private FieldWrapper specificOp(String op, StaDurationWrapper other) {
9091
case "+":
9192
case "-":
9293
String template = "(? " + op + " " + INTERVAL_PARAM + ")";
93-
Field<Moment> expression = DSL.field(template, Moment.class, field, other.getDuration());
94+
Field<Moment> expression = DSL.field(template, MomentBinding.dataType(), field, other.getDuration());
9495
return new StaDateTimeWrapper(expression);
9596

9697
default:

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/fieldwrapper/StaTimeIntervalWrapper.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.utils.Utils.INTERVAL_PARAM;
2121

22+
import de.fraunhofer.iosb.ilt.frostserver.persistence.pgjooq.bindings.MomentBinding;
2223
import de.fraunhofer.iosb.ilt.frostserver.property.type.TypeComplex;
2324
import java.util.Map;
2425
import net.time4j.Moment;
@@ -58,8 +59,8 @@ public StaTimeIntervalWrapper(Field<Moment> start, Field<Moment> end) {
5859
}
5960

6061
public StaTimeIntervalWrapper(Moment start, Moment end) {
61-
this.start = DSL.inline(start);
62-
this.end = DSL.inline(end);
62+
this.start = DSL.inline(start, MomentBinding.dataType());
63+
this.end = DSL.inline(end, MomentBinding.dataType());
6364
}
6465

6566
public Field<Moment> getStart() {
@@ -104,8 +105,8 @@ private FieldWrapper specificOp(String op, StaDurationWrapper other) {
104105
case "-":
105106
String template = "(? " + op + " " + INTERVAL_PARAM + ")";
106107
return new StaTimeIntervalWrapper(
107-
DSL.field(template, Moment.class, start, other.getDuration()),
108-
DSL.field(template, Moment.class, end, other.getDuration()));
108+
DSL.field(template, MomentBinding.dataType(), start, other.getDuration()),
109+
DSL.field(template, MomentBinding.dataType(), end, other.getDuration()));
109110

110111
default:
111112
throw new UnsupportedOperationException(INCOMPATIBLE_OP + op + "' " + other.getClass().getName());

FROST-Server.SQLjooq/src/main/java/de/fraunhofer/iosb/ilt/frostserver/persistence/pgjooq/tables/StaTableAbstract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public static JsonFieldWrapper jsonFieldFromPath(final Field mainField, final En
500500
}
501501

502502
protected PropertyFields<T> propertyFieldForJsonField(final JsonFieldWrapper jsonFactory, final EntityPropertyCustomSelect epCustomSelect) {
503-
final Field deepField = jsonFactory.materialise().getJsonExpression();
503+
final Field<Object> deepField = jsonFactory.materialise().getJsonExpression();
504504
PropertyFields<T> pfs = new PropertyFields<>(
505505
epCustomSelect,
506506
new PropertyFieldRegistry.ConverterRecordDeflt<>(

0 commit comments

Comments
 (0)