Search code examples
javajooqjooq-codegen

How to convert a Field in jooq custom converter using other fields in the same Record?


  • Need to apply custom field conversion logic in org.jooq.Converter implementation.
  • The custom conversion is a encrypt / decrypt the field
  • The key for encryption / decryption will be available in the same org.jooq.RecordContext i.e: In the same table another column will have key.

If below is not possible what are the other ways to achieve this?

public class CustomFieldConverter implements Converter<String, String> {

    
    @Override
    public String from(String databaseObject) {

        // do MySQLDSL.aesDecrypt(databaseObject, Field('keyColumn')
        // How to access keyColumn field here?
        // 
    }

    @Override
    public String to(String userObject) {
        // do MySQLDSL.aesEncrypt(databaseObject, Field('keyColumn')
        // How to access keyColumn field here?
    }

    @Override
    public Class<String> fromType() {
        return String.class;
    }

    @Override
    public Class<String> toType() {
        return String.class;
    }
}


Solution

  • You probably misunderstood my previous answer. All you do in a Converter is:

    • 100% client based, so you cannot apply any SQL functions in there
    • 100% single column expression based, so you cannot access any other column values

    There's no way to achieve what you want to do with a Converter. My previous suggestion of using a Converter was meant to hint at doing all the encryption / decryption completely in the client, not partially in the client. This means you have to have that key available in memory to do any encryption / decryption using Java API, not using MySQL API.