package io.ebeaninternal.server.type;
import io.ebean.config.dbplatform.DbPlatformType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.sql.SQLException;
public abstract class ScalarTypeJsonNodePostgres extends ScalarTypeJsonNode {
final ObjectMapper objectMapper;
final String postgresType;
ScalarTypeJsonNodePostgres(ObjectMapper objectMapper, int jdbcType, String postgresType) {
super(objectMapper, jdbcType);
this.objectMapper = objectMapper;
this.postgresType = postgresType;
}
@Override
public void bind(DataBind bind, JsonNode value) throws SQLException {
String rawJson = (value == null) ? null : formatValue(value);
bind.setObject(PostgresHelper.asObject(postgresType, rawJson));
}
public static class JSON extends ScalarTypeJsonNodePostgres {
public JSON(ObjectMapper objectMapper) {
super(objectMapper, DbPlatformType.JSON, PostgresHelper.JSON_TYPE);
}
}
public static class JSONB extends ScalarTypeJsonNodePostgres {
public JSONB(ObjectMapper objectMapper) {
super(objectMapper, DbPlatformType.JSONB, PostgresHelper.JSONB_TYPE);
}
}
}