问题
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