vertx-sql-client icon indicating copy to clipboard operation
vertx-sql-client copied to clipboard

Support for BLOB in vertx-sql-client-templates

Open vicliu624 opened this issue 3 years ago • 1 comments

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;
    }));
  }

 ...

}

vicliu624 avatar Mar 25 '22 03:03 vicliu624

Possible duplicate of https://github.com/vert-x3/vertx-jdbc-client/issues/275

tsegismont avatar Mar 25 '22 13:03 tsegismont