Skip to content

Commit

Permalink
Fixed warnings due to JOOQ issue #15286
Browse files Browse the repository at this point in the history
  • Loading branch information
hylkevds committed Jan 9, 2024
1 parent 2160693 commit c39895f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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<? extends GeoJsonObject> node) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,25 +30,24 @@
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;

/**
*
* @author scf
*/
public class JsonBinding implements Binding<Object, JsonValue> {

private static final JsonBinding INSTANCE = new JsonBinding();
private static final Converter<Object, JsonValue> CONVERTER_INSTANCE = new Converter<Object, JsonValue>() {
@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());
}

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

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

public static JsonBinding instance() {
return INSTANCE;
}

@Override
public Converter<Object, JsonValue> converter() {
return CONVERTER_INSTANCE;
}

public static DataType<JsonValue> dataType() {
return DATA_TYPE;
}

@Override
public void sql(BindingSQLContext<JsonValue> ctx) throws SQLException {
if (ctx.render().paramType() == ParamType.INLINED) {
Expand All @@ -104,12 +111,12 @@ public void set(BindingSetSQLOutputContext<JsonValue> ctx) throws SQLException {

@Override
public void get(BindingGetResultSetContext<JsonValue> 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<JsonValue> ctx) throws SQLException {
ctx.convert(converter()).value(ctx.statement().getBytes(ctx.index()));
ctx.convert(converter()).value(ctx.statement().getString(ctx.index()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,19 @@
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;

/**
*
* @author hylke
*/
public class MomentBinding implements Binding<Timestamp, Moment> {

private static final Converter<Timestamp, Moment> INSTANCE = new Converter<Timestamp, Moment>() {
private static final MomentBinding INSTANCE = new MomentBinding();
private static final Converter<Timestamp, Moment> CONVERTER_INSTANCE = new Converter<Timestamp, Moment>() {
@Override
public Moment from(Timestamp databaseObject) {
if (databaseObject == null) {
Expand All @@ -68,10 +71,19 @@ public Class<Moment> toType() {
return Moment.class;
}
};
private static final DataType<Moment> DATA_TYPE = SQLDataType.TIMESTAMP.asConvertedDataType(INSTANCE);

public static MomentBinding instance() {
return INSTANCE;
}

@Override
public Converter<Timestamp, Moment> converter() {
return INSTANCE;
return CONVERTER_INSTANCE;
}

public static DataType<Moment> dataType() {
return DATA_TYPE;
}

@Override
Expand All @@ -83,37 +95,31 @@ public void sql(BindingSQLContext<Moment> ctx) throws SQLException {
}
}

// Registering VARCHAR types for JDBC CallableStatement OUT parameters
@Override
public void register(BindingRegisterContext<Moment> 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<Moment> 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<Moment> 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<Moment> 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<Moment> ctx) throws SQLException {
throw new SQLFeatureNotSupportedException();
}

// Getting a value from a JDBC SQLInput (useful for Oracle OBJECT types)
@Override
public void get(BindingGetSQLInputContext<Moment> ctx) throws SQLException {
throw new SQLFeatureNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@
import org.jooq.BindingSetSQLOutputContext;
import org.jooq.BindingSetStatementContext;
import org.jooq.Converter;
import org.jooq.DataType;
import org.jooq.impl.SQLDataType;

/**
*
* @author scf
*/
public class PostGisGeometryBinding implements Binding<Object, Geometry> {

private static final PostGisGeometryBinding INSTANCE = new PostGisGeometryBinding();
private static final Converter<Object, Geometry> CONVERTER_INSTANCE = new Converter<Object, Geometry>() {
@Override
public Geometry from(Object databaseObject) {
Expand All @@ -59,12 +62,21 @@ public Class<Geometry> toType() {
return Geometry.class;
}
};
private static final DataType<Geometry> DATA_TYPE = SQLDataType.VARBINARY.asConvertedDataType(INSTANCE);

public static PostGisGeometryBinding instance() {
return INSTANCE;
}

@Override
public Converter<Object, Geometry> converter() {
return CONVERTER_INSTANCE;
}

public static DataType<Geometry> dataType() {
return DATA_TYPE;
}

@Override
public void sql(BindingSQLContext<Geometry> ctx) throws SQLException {
ctx.render().sql("ST_GeomFromEWKT(?)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

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

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,8 +59,8 @@ public StaTimeIntervalWrapper(Field<Moment> start, Field<Moment> 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<Moment> getStart() {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public static JsonFieldWrapper jsonFieldFromPath(final Field mainField, final En
}

protected PropertyFields<T> propertyFieldForJsonField(final JsonFieldWrapper jsonFactory, final EntityPropertyCustomSelect epCustomSelect) {
final Field deepField = jsonFactory.materialise().getJsonExpression();
final Field<Object> deepField = jsonFactory.materialise().getJsonExpression();
PropertyFields<T> pfs = new PropertyFields<>(
epCustomSelect,
new PropertyFieldRegistry.ConverterRecordDeflt<>(
Expand Down

0 comments on commit c39895f

Please sign in to comment.