Jooq custom binding registration in Java

折月煮酒 提交于 2019-12-10 22:16:38

问题


I have a custom binding written to convert from custom type to Postgres json type. This part of the documentation mentions how to register using xml but I'm using Java. I have tried to search to find how to do that but in vain.

Any help is appreciated.


回答1:


If by "I'm using Java", you mean using programmatic code generator configuration using Java:

There's a manual section about programmatic code generator configuration here:

http://www.jooq.org/doc/latest/manual/code-generation/codegen-programmatic

Essentially, all XML elements also exist as Java types, which are generated with XJC from the code generation configuration XSD, so all XML configuration maps 1:1 to Java configuration, including that for data type bindings (via ForcedType objects).

If by "I'm using Java", you mean you don't use the code generator and want to create a binding:

The code generator doesn't do anything magic. Everything it does, you can do manually as well. You can easily call:

DataType<MyJsonType> jsonType = 
    SQLDataType.VARCHAR.asConvertedDataType(new MyJsonBinding());
Field<MyJsonType> jsonField = field(name("my_table", "my_column"), jsonType);

Of course, using the code generator instead will greatly help...



来源:https://stackoverflow.com/questions/39777764/jooq-custom-binding-registration-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!