vertx-sql-client
vertx-sql-client copied to clipboard
Support for BLOB in vertx-sql-client-templates
Version
4.2.6
Context
DDL
CREATE TABLE "TEST"."TBL_MESSAGE" (
"ID" NUMBER(20,0) NOT NULL,
...
"ORIGIN_DATA" BLOB,
...
)
entity
@Data
@Table(name = "TBL_MESSAGE")
public class TblMessage implements Serializable {
...
@Column(name = "ORIGIN_DATA")
private byte[] originData;
...
}
I try to insert record used by SqlTemplate
JDBCPool pool = DbHelper.client();
SqlTemplate.forUpdate(pool, "INSERT INTO TBL_MESSAGE(ORIGIN_DATA) VALUES (#{originData})")
.mapFrom(TblMessage.class)
.execute(tblMessage)
.onSuccess(v -> {
log.info("onSuccess: {}", v);
})
.onFailure(e -> {
log.warn("Failure: ", e);
});
mapFrom in io.vertx.sqlclient.templates.SqlTemplate have convert object to Map ,the method cause oracle.jdbc.OracleDatabaseException: ORA-01465, because JSONObject convert byte[] to base64 String
I don't think this is the best way. value's type has changed ,from JsonObject to Map<String, Object>
package io.vertx.sqlclient.templates
...
@VertxGen
public interface SqlTemplate<I, R> {
...
default <T> SqlTemplate<T, R> mapFrom(Class<T> type) {
return mapFrom(TupleMapper.mapper(params -> {
JsonObject jsonObject = JsonObject.mapFrom(params);
Map<String, Object> map = new LinkedHashMap<>(jsonObject.size());
for (String fieldName : jsonObject.fieldNames()) {
map.put(fieldName, jsonObject.getValue(fieldName));
}
return map;
}));
}
...
}
Possible duplicate of https://github.com/vert-x3/vertx-jdbc-client/issues/275