How can I store XML data?
I saw How can I insert an XML document in PostgreSQL in Java? but I was wondering if jOOQ offers another solution to this kind of problem.
At the moment I don't see another method as to write something like
String sql = "INSERT INTO xml_docs(id, gkuzu) VALUES (?, XMLPARSE(?))";
and execute it with jOOQ
but is there another option for more complex statements where I can also write e.g.
StringBuilder xml = new StringBuilder(); // .. this.ctx.insertInto(MY_TABLE) .set(MY_TABLE.NAME, name) // .. .set(MY_TABLE.DESCRIPTION_XML, xml.toString());
jOOQ 3.7 doesn't support XML (or JSON, etc.) types out of the box, but indeed, jOOQ helps you abstract the XML data type by implementing your custom data type binding. There's an example for JSON and PostgreSQL in the manual. You can adapt that easily for XML:
Essentially, you'll need to implement org.jooq.Binding<Object, YourXMLRepresentation>, and then configure the code generator to apply this binding either to all XML type columns, or to columns of a specific name pattern: